c_pattle Posted July 15, 2010 Share Posted July 15, 2010 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 More sharing options...
Adam Posted July 15, 2010 Share Posted July 15, 2010 Whether it's a local variable or global variable.. on the next request it won't exist anymore. Without using a database to track user IPs, really your best bet is to set a session variable and/or cookie. Link to comment https://forums.phpfreaks.com/topic/207821-global-variables/#findComment-1086367 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.