Guest jgp4 Posted July 1, 2006 Share Posted July 1, 2006 I really need some help. I've just starting implementing sessions on a CMS i'm working on, but they're not working on my testing server (winXPpro, apache 2, php 4.4). Every time the page calls session_start() it creates a brand new session and cookie. the script works fine on my server at http://jgp4.co.uk/sessions.php .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. Quote Link to comment https://forums.phpfreaks.com/topic/13411-php-sessions-acting-really-odd/ Share on other sites More sharing options...
toplay Posted July 1, 2006 Share Posted July 1, 2006 It's best to post the exact code so members on this forum can help you better.Check that the session save path is set correctly in the php.ini file.See our session troubleshooting guide:http://www.phpfreaks.com/forums/index.php/topic,31047.msg157705.html#msg157705 Quote Link to comment https://forums.phpfreaks.com/topic/13411-php-sessions-acting-really-odd/#findComment-51791 Share on other sites More sharing options...
Guest jgp4 Posted July 2, 2006 Share Posted July 2, 2006 Sorry about that, here's the code:<?phpsession_start();if(!isset($_SESSION['count'])) { $_SESSION['count'] = 0;}else { $_SESSION['count']++;}echo $_SESSION['count'];?>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. Quote Link to comment https://forums.phpfreaks.com/topic/13411-php-sessions-acting-really-odd/#findComment-51887 Share on other sites More sharing options...
Guest jgp4 Posted July 2, 2006 Share Posted July 2, 2006 EDIT: sorry I meant 'PHP [b]can't[/b] see that there's a session'sorry if it caused any confusion Quote Link to comment https://forums.phpfreaks.com/topic/13411-php-sessions-acting-really-odd/#findComment-51892 Share on other sites More sharing options...
redarrow Posted July 2, 2006 Share Posted July 2, 2006 i tried your code works fine and you link also works ok .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 browserbut if you go away from the page the session resets and counts agin from 0 okunrealatedif you wanted to add a hit counter to the members table then just use$hits+1;insert value ('hits', where id=$id");then the data base will insert hits for the member and add one each time ok. Quote Link to comment https://forums.phpfreaks.com/topic/13411-php-sessions-acting-really-odd/#findComment-51894 Share on other sites More sharing options...
Guest jgp4 Posted July 2, 2006 Share Posted July 2, 2006 I don't have access to the server phpini but i ran a phpinfo() and everything is set up the same except for the dir where the sessions are saved as its a linux server. The sessions folder is available to all users etc. with full permissions. Could this just be a bug with running it on windows? if you want to have a look the info is at http://jgp4.co.uk/phpinfo.php Quote Link to comment https://forums.phpfreaks.com/topic/13411-php-sessions-acting-really-odd/#findComment-51955 Share on other sites More sharing options...
Orio Posted July 2, 2006 Share Posted July 2, 2006 If I press refresh on that page you gave it does go up by 1... What's the problem then?Orio. Quote Link to comment https://forums.phpfreaks.com/topic/13411-php-sessions-acting-really-odd/#findComment-51956 Share on other sites More sharing options...
toplay Posted July 2, 2006 Share Posted July 2, 2006 jgp4, have you gone through the session troubleshooting guide?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. Quote Link to comment https://forums.phpfreaks.com/topic/13411-php-sessions-acting-really-odd/#findComment-51985 Share on other sites More sharing options...
Guest jgp4 Posted July 3, 2006 Share Posted July 3, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/13411-php-sessions-acting-really-odd/#findComment-52375 Share on other sites More sharing options...
toplay Posted July 3, 2006 Share Posted July 3, 2006 [quote author=jgp4 link=topic=99134.msg390894#msg390894 date=1151910410]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?[/quote]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.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. Quote Link to comment https://forums.phpfreaks.com/topic/13411-php-sessions-acting-really-odd/#findComment-52463 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.