PHP sessions acting really odd!
Posted 01 July 2006 - 09:15 PM
The script is just the basic one from PHP.net about counting the number of times a page has been loaded by the client.
Any help would be really appreciated.
Posted 02 July 2006 - 06:13 AM
$_SESSION['count'] = 0;
The session save path is set to "C:\php\sessions" and seems to be working, every time I refresh the page it create a new file in that dir and the value for the localhost cookie PHPSESSID changes to the values of the new file.
It seems like php can see that there's a session and so creates a new one, can anyone think why?
Thanks in advance.
Posted 02 July 2006 - 06:24 AM
sorry if it caused any confusion
Posted 02 July 2006 - 06:34 AM
look at the sever php.ini to match the testing php.ini ok
the code you provided only counts up from 0 to whatever when refresing the browser
but if you go away from the page the session resets and counts agin from 0 ok
if you wanted to add a hit counter to the members table then just use
insert value ('hits', where id=$id");
then the data base will insert hits for the member and add one each time ok.
((EMAIL CODE THAT WORKS))
((PAYPAL INTEGRATION THAT WORKS))
Posted 02 July 2006 - 11:06 AM
Posted 02 July 2006 - 11:10 AM
(Gone until 20 to November)
Posted 02 July 2006 - 01:54 PM
It sounds like the browser you're using isn't saving the php session cookie. It could also be network security software you have installed. All this is specified in the troubleshooting guide.
Try the session script in about the 10th bullet and report back what you get. If the session ID is shown in the URL, then session cookies are not being saved on your Windows system.
Posted 03 July 2006 - 07:06 AM
Posted 03 July 2006 - 03:07 PM
The SID constant doesn't get populated by PHP unless it can't write a session cookie. A PHP session cookie holds the session ID (usually 32 characters long). The files created in your session path is what actually holds the data you wish to save per session. The server side session filename is in the form of sess_xxx, where "xxx" is the session ID.
I've tried the script in the troubleshooting guide and it works, but displays the sessid in the url, i'll keep reading the guide but i think i've tried avrything there. If it's not setting cookies then what are the files which keep getting created in my session.save_path?
The cookie has the session ID so PHP knows which session this is and can get at any existing session file data located in your session save path. If the session cookies is not there, or the session ID is not provided in the URL, then PHP will think it's a new session. And that's why you keep getting a new session ID each page refresh.
When session.trans_sid is on, PHP automatically adds the session name and ID to each URL when a session cookie couldn't be created (so the session is not lost). However, PHP doesn't do it on redirects like using header with location. That's why my example code uses the SID constant.
You have to see why cookies aren't being created (common reasons are outlined in the troubleshooting guide). Also, try different browsers.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users