Jump to content

using a single variable from a separate file without using import


Smudly

Recommended Posts

I have created a file called onlineusers.php that figures out how many users there currently are online. At the end of the script is a variable that captures the final number. I want to be able to use ONLY this variable in a separate file called members.php

 

How do I go about doing something like this?

 

 

Create a function using that onlineusers.php file (I usually create a file called functions.php that contains all my functions), then include the functions.php file in your members.php file using:

include( functions.php );

 

To create the function, do something like this:

 

function onlineUsers()
{
// your code to calculate the online users

return $numUsers;
}

 

Then in your members.php page:

 

$numUsers = onlineUsers();

I have created a file called onlineusers.php that figures out how many users there currently are online. At the end of the script is a variable that captures the final number. I want to be able to use ONLY this variable in a separate file called members.php

 

How do I go about doing something like this?

 

Use sessions

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.