Jump to content

[SOLVED] Sessions Not working on my web host


tim101011

Recommended Posts

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

:( :( :(

 

 

Link to comment
Share on other sites

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 !

 

 

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.