views:

50

answers:

3

Hi

I am experiencing issues with session where if i put the following code on a page the counter will increment by one every time i reload the page.

session_start();  
if(isset($_SESSION['views']))
    $_SESSION['views'] = $_SESSION['views']+ 1;
else
    $_SESSION['views'] = 1; 

if i put the above code in an if statement where it only runs when you hit a button and display the number in the session the session is always empty.

Could there be a php.ini issue?

Thanks in advance

A: 

Your session could not be initiated. Check for tmp directory if server can write (many session issues are related with full disk!)

nerkn
just check the tmp directory where the sessions are saved and the folder has the correct permissions and is only 7% full
adamias
A: 

Also check php.ini to make sure session.auto_start=1 and for the code...

//debug your session   

echo"<!--".session_id()."-->";

//update the views

array_key_exists('views',$_SESSION)?$_SESSION['views']++:$_SESSION['views']=1;

FatherStorm
you'll want to remove the debugging once you ironed out the problem, but this way you can check to see if you HAVE a session but it's not the SAME session...
FatherStorm
hi if i display the session id on the page load and then display what the session id is on the post back they are both the same. I have also looped through the session variables to see what keys i have and any session that is created (attempted) in the post back still isnt saved.
adamias
I have also check the php ini settings and the session.auto_start was set to 0 so i have changed that and still experience the same issue
adamias
A: 
session_start();  

if(isset($_SESSION['views']))
    $_SESSION['views']++;
else
    $_SESSION['views'] = 1; 
luckytaxi