Jump to content

Global variables


c_pattle

Recommended Posts

I have the following code that reads and file and adds one to it before saving it again (this is being used as a hit counter).  However I at the moment it adds one every time the page is refreshed and I only want it to add one once no matter how many times they refresh the home page. 

 

I have tried to use a variable to stop this by checking if the variable has been set but it's not working.  Do I need to make it a global variable and if so how do I do that.  (I know I could make it work by using a session variable but I don't want to hassle of creating a session just for that. 

 

if (!$counter_set_index) {
$countfileindex = "counterindex.txt"; 

$handle = fopen($countfileindex, 'r+') ; 

include("includes/inc_counter.php");

$counter_set_index = 1;

} 

Link to comment
https://forums.phpfreaks.com/topic/207821-global-variables/
Share on other sites

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.