Smudly Posted June 11, 2010 Share Posted June 11, 2010 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? Link to comment https://forums.phpfreaks.com/topic/204452-using-a-single-variable-from-a-separate-file-without-using-import/ Share on other sites More sharing options...
JasonLewis Posted June 11, 2010 Share Posted June 11, 2010 Include the file in members.php, then echo the named variable. Link to comment https://forums.phpfreaks.com/topic/204452-using-a-single-variable-from-a-separate-file-without-using-import/#findComment-1070644 Share on other sites More sharing options...
thomashw Posted June 11, 2010 Share Posted June 11, 2010 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(); Link to comment https://forums.phpfreaks.com/topic/204452-using-a-single-variable-from-a-separate-file-without-using-import/#findComment-1070646 Share on other sites More sharing options...
TOA Posted June 11, 2010 Share Posted June 11, 2010 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 Link to comment https://forums.phpfreaks.com/topic/204452-using-a-single-variable-from-a-separate-file-without-using-import/#findComment-1070761 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.