tim101011 Posted October 20, 2007 Share Posted October 20, 2007 Hi, I wrote a website on my local PC that used sessions. The sessions worked perfectly. Then I uploaded the website onto a VPS linux server. The sessions stopped working: They work on an individual page, but if I try and retreive a value of a session that was set on another page, the value is returned as empty. So, I checked out the location where the sessions are being stored on my server. There were session files in there with test values I had created on my site so the sessions are definitely being stored, it seems there is just some problem picking them up on other pages.. This is the session section of my phpinfo file: www.qcitesting.com/phpinfo.png The version of PHP I am using is 5.1.2 This has been a problem for a few weeks, and has really ground me down :( Any help would be hugely appreciated, Thanks, Tim Quote Link to comment https://forums.phpfreaks.com/topic/74064-solved-sessions-not-working-on-my-web-host/ Share on other sites More sharing options...
Orio Posted October 20, 2007 Share Posted October 20, 2007 First thing to check- have you used session_start() at the start of every page? You can't access the values you saved in a previous page without using session_start() on every page. I am asking that because maybe on your PC you had session.auto_start set to true... Now, if that's not the problem, I don't think it's nothing wrong with your scripts/server. Have you doubled checked your side? What I mean is- Have you checked that your internet options are not blocking cookies or anything like that? Because it seems that your settings are fine, so as far as I can see the problem is not server side. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/74064-solved-sessions-not-working-on-my-web-host/#findComment-373900 Share on other sites More sharing options...
tim101011 Posted October 20, 2007 Author Share Posted October 20, 2007 All the browsers I have tried allow cookies - I am almost certain it is nothing to do with this The sessions in my site worked perfectly on my local build - so my code should be fine - although the site was developed at home on my windows machine which was running PHP 5.2.3 I think - the web server is using linux/apache and the its PHP version 5.1.2 :( Quote Link to comment https://forums.phpfreaks.com/topic/74064-solved-sessions-not-working-on-my-web-host/#findComment-373901 Share on other sites More sharing options...
Orio Posted October 20, 2007 Share Posted October 20, 2007 As I asked in the beginning- have you made sure that all of your scripts have session_start() in them somewhere? Please double check that. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/74064-solved-sessions-not-working-on-my-web-host/#findComment-373904 Share on other sites More sharing options...
tim101011 Posted October 20, 2007 Author Share Posted October 20, 2007 Here are two files on my server: sessiontest.php : <?php session_start(); $_SESSION['$name']= "hello"; header("location:sessiontest2.php"); ?> sessiontest2.php: <?php session_start(); echo $_SESSION['$name']; ?> The actual URLs for them are: https://212.241.216.160:8443/sitepreview/http/propertyeagle.co.uk/sessiontest.php https://212.241.216.160:8443/sitepreview/http/propertyeagle.co.uk/sessiontest.php When you go to sessiontest.php it should set the value of the session variable to "hello" and pass you on to sessiontest2.php which should display this variable, as you can see, it isn't ! Quote Link to comment https://forums.phpfreaks.com/topic/74064-solved-sessions-not-working-on-my-web-host/#findComment-373906 Share on other sites More sharing options...
Orio Posted October 20, 2007 Share Posted October 20, 2007 Why are you using a variable that you haven't defined? Remove the dollar sign before "name" in both of the scripts you should have no problems. Because you have used a variable that you haven't defined ($name), php replaces it with an empty string, and as far as I know keys in arrays can't be empty strings. So either define the variable $name before using it, or remove the dollar sign from it to create an array key that is called "name". Orio. Quote Link to comment https://forums.phpfreaks.com/topic/74064-solved-sessions-not-working-on-my-web-host/#findComment-373908 Share on other sites More sharing options...
tim101011 Posted October 20, 2007 Author Share Posted October 20, 2007 Hi, Sorry, those two test scripts were just something I put together today to prove to myself that the problem is defintely with the sessions. I have taken out the $ signs, but still no luck: please follow the links and you will see it still isn't working. Thanks for your help so far, I feel I am getting closer and closer to the solution. Sorry about my link above to sessiontest2.php, i missed out the "2" at the end Quote Link to comment https://forums.phpfreaks.com/topic/74064-solved-sessions-not-working-on-my-web-host/#findComment-373936 Share on other sites More sharing options...
Orio Posted October 20, 2007 Share Posted October 20, 2007 Ok, let me get this straight- currently, your codes look like this? sessiontest.php : <?php session_start(); $_SESSION['name']= "hello"; header("location: sessiontest2.php"); ?> sessiontest2.php: <?php session_start(); echo $_SESSION['name']; ?> I've checked the pages, and I do get the session cookie... Make sure your scripts look like this. This problem is pretty weird since I've seen that your configuration is fine... Orio. Quote Link to comment https://forums.phpfreaks.com/topic/74064-solved-sessions-not-working-on-my-web-host/#findComment-373943 Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 It probably has something to do with the settings in the php.ini file. Review them and paste all configuration related settings here. Quote Link to comment https://forums.phpfreaks.com/topic/74064-solved-sessions-not-working-on-my-web-host/#findComment-373946 Share on other sites More sharing options...
tim101011 Posted October 20, 2007 Author Share Posted October 20, 2007 Sorry, yes, thats how the files look now. Quote Link to comment https://forums.phpfreaks.com/topic/74064-solved-sessions-not-working-on-my-web-host/#findComment-373953 Share on other sites More sharing options...
tim101011 Posted October 20, 2007 Author Share Posted October 20, 2007 This is probably an incredibly stupid thing to do, but follow this link for my phpinfo file : ryjrtjrtj Quote Link to comment https://forums.phpfreaks.com/topic/74064-solved-sessions-not-working-on-my-web-host/#findComment-373958 Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 Your settings look fine. http://www.google.com/search?hl=en&q=php+sessions+stopped+working Check the top 3 mostly, read them carefully and try to do as they say. Quote Link to comment https://forums.phpfreaks.com/topic/74064-solved-sessions-not-working-on-my-web-host/#findComment-373960 Share on other sites More sharing options...
tim101011 Posted October 20, 2007 Author Share Posted October 20, 2007 Guess its time to phone the helpdesk for my web host Very expensive and extremely annoying. If they can't help then its time to switch my web host :( :( By the way, my web host is www.webfusion.co.uk I have seen a lot of bad press about them on google. Not sure if its all legitimate but it still unnerved me Quote Link to comment https://forums.phpfreaks.com/topic/74064-solved-sessions-not-working-on-my-web-host/#findComment-373967 Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 http://www.google.com/search?hl=en&q=webfusion+complaints They don't seem to have a great love of some of there clients. Quote Link to comment https://forums.phpfreaks.com/topic/74064-solved-sessions-not-working-on-my-web-host/#findComment-373969 Share on other sites More sharing options...
wildteen88 Posted October 20, 2007 Share Posted October 20, 2007 Your sessions are working, but the problem seems to be PHP is not retrieving the session id set within your cookie. Try the following. Got the following link: https://212.241.216.160:8443/sitepreview/http/propertyeagle.co.uk/sessiontest.php Now go to where you browser stores your cookies, look for the cookie set by your site (212.241.216.160). Copy the PHPSESSID from the cookie. Now go back to sessiontest.php and append the following to the url: ?PHPSESSID=your_phpsessid_here eg: https://212.241.216.160:8443/sitepreview/http/propertyeagle.co.uk/sessiontest.php?PHPSESSID=5599baf6ce540a04ff18fa14745a61f9 Once redirected to sessiontest2.php append the PHPSESSID again, eg: https://212.241.216.160:8443/sitepreview/http/propertyeagle.co.uk/sessiontest2.php?PHPSESSID=5599baf6ce540a04ff18fa14745a61f9 Hello will now be displayed. This problem may due to the fact your using a secure http connection. Quote Link to comment https://forums.phpfreaks.com/topic/74064-solved-sessions-not-working-on-my-web-host/#findComment-374059 Share on other sites More sharing options...
tim101011 Posted October 21, 2007 Author Share Posted October 21, 2007 Wow, looks like you are right. Finally it seems I might be on the right path towards fixing this. I phoned the helpdesk lastnight and they said they couldn't help. I told them they were my last bastion of hope and that since they couldn't, I would have to cancel my account tommorow. So looks like I might not have to do this :) Ok, so my next question is, do you think that PHP is not retreiving the session ID withing the cookie due to an issue with the the client machines I have tried it on or the server? I am 90% sure you mean the server. In which case, how do I turn off/bypass the secure http connection? My first guess that it is related to the "site preview" link I am following from my servers plesk control panel, or becuase I put my files in apaches http folder. I could be completely wrong. Any ideas? Thanks for your help, I really appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/74064-solved-sessions-not-working-on-my-web-host/#findComment-374736 Share on other sites More sharing options...
tim101011 Posted October 21, 2007 Author Share Posted October 21, 2007 Ok, is "duh" spelt with a capital D or a lowercase d?! I just tried using the IP address on its own: http://212.241.216.160/sessiontest.php and that works! 3 weeks I have spent stressing over that. :):):):):):):):) Thankyou! Quote Link to comment https://forums.phpfreaks.com/topic/74064-solved-sessions-not-working-on-my-web-host/#findComment-374745 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.