Jump to content

Recommended Posts

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 ?

Link to comment
https://forums.phpfreaks.com/topic/53851-server-session-not-working-properly/
Share on other sites

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.

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 ! 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.