sanzeeb Posted June 1, 2007 Share Posted June 1, 2007 hi i have wrote the following script but , it works 100% ok in my WAMP, but when i have uploaded it in server then its not working properly though it dosent shows any warning or error but sesson is not working. ithe path and of the session save folder is also correct and i foxed CHMOD 777 for the folder. <?php session_save_path('./tmpx'); session_start(); /* $session_path = session_save_path(); echo $session_path; */ $visitor=0; $myFile = "count.txt"; $file = fopen($myFile, 'r') or die("can't open file"); $data = fgets($file); fclose($file); if($_SESSION[visitor]) { $visitor=$_SESSION[visitor]; // echo $visitor; } else { $myFile = "count.txt"; $file = fopen($myFile, 'w') or die("can't open file"); $visitor = $data + 1; fwrite($file,$visitor); fclose($file); $_SESSION[visitor]= $visitor; // echo $visitor; } echo $visitor; ?> how to fix this problem ? Quote Link to comment https://forums.phpfreaks.com/topic/53851-server-session-not-working-properly/ Share on other sites More sharing options...
Psycho Posted June 1, 2007 Share Posted June 1, 2007 I'm not sure what you are trying to do here. Are you trying to use session data to count the number of visitors to the site? You can't do that with session data, you would need to use cookies. How do you know sessions is not working? What is not happening that you expect to happen. Based upon what I see I would expect the following: The first time you open your browser and navigate to this page it would perform the else clause, i.e. it would open $myFile and modify the value. On every subsequent visit to the page (without closing the browser), then the if clause would take place. Try putting print_r($_SESSION) right before the if statement and eplain what you see on the first visit and subsequent visits. Quote Link to comment https://forums.phpfreaks.com/topic/53851-server-session-not-working-properly/#findComment-266242 Share on other sites More sharing options...
sanzeeb Posted June 1, 2007 Author Share Posted June 1, 2007 I'm not sure what you are trying to do here. Are you trying to use session data to count the number of visitors to the site? You can't do that with session data, you would need to use cookies. How do you know sessions is not working? What is not happening that you expect to happen. Based upon what I see I would expect the following: The first time you open your browser and navigate to this page it would perform the else clause, i.e. it would open $myFile and modify the value. On every subsequent visit to the page (without closing the browser), then the if clause would take place. Try putting print_r($_SESSION) right before the if statement and eplain what you see on the first visit and subsequent visits. yaa you are right , its a counter script . i dont understand " Are you trying to use session data to count the number of visitors to the site? You can't do that with session data, you would need to use cookies." what you tried to mean by this ? why it shouldn't work in session ? beside this i didn't mean that servers session is not working , i meant that the script is working well in my WAMP server but its not working in when i have uploaded it in real server. in browse when i press refresh,(after uploading in server) it increase the count but it shouldn't have to be that ! Quote Link to comment https://forums.phpfreaks.com/topic/53851-server-session-not-working-properly/#findComment-266427 Share on other sites More sharing options...
Psycho Posted June 1, 2007 Share Posted June 1, 2007 i dont understand " Are you trying to use session data to count the number of visitors to the site? You can't do that with session data, you would need to use cookies." what you tried to mean by this ? why it shouldn't work in session ? By using sessions you will be counting sessions - not visitors. beside this i didn't mean that servers session is not working , i meant that the script is working well in my WAMP server but its not working in when i have uploaded it in real server. in browse when i press refresh,(after uploading in server) it increase the count but it shouldn't have to be that ! Right, so you need to start the debugging process to find out why it's not working. Did you insert the code I posted above to see what the results are? I would also suggest temporarily removing the session_save_path line as well. Quote Link to comment https://forums.phpfreaks.com/topic/53851-server-session-not-working-properly/#findComment-266477 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.