Jump to content

Session variable being set on my PC but not on webhost's server


Recommended Posts

Hi all,


I have the following code to check whether the client has javascript enabled in their browser:



if(isset($_SESSION['gocheck'])) {$gocheck = $_SESSION['gocheck'];} else {$gocheck = 'no';}
//echo $gocheck;
if($gocheck=='no'){header ("Location: ./gocheck.php"); exit;}
//----Execution only reaches this line if gocheck.php has been run and Javascript is enabled.--------
//rest of page



$_SESSION['gocheck'] = 'yes';

<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">
<script type=\"text/javascript\" language=\"JavaScript\">

This website requires Javascript to be enabled in your browser. <br />
Please enable Javascript and try again.





So what should happen is the user is always redirected from page.php to gocheck.php, which sets the session variable $gocheck to 'yes' and directs back to page.php via Javascript. Because $gocheck is then equal to 'yes', page.php shouldn't direct back again tio gocheck.php.


This worked fine on my PC (using WAMP), but when I upload the files to the webhost, it seems to get stuck in an infinite redirect loop between page.php and gocheck.php. Also, if I echo $gocheck in page.php, it returns 'no', so it seems as if for some reason the session variable $gocheck is not being set properly by gocheck.php.


Could somebody please shed some light on this? Is there an error in my code? Is there something I need to change in php.ini on the webhost's server?




P.S. WAMP on my PC uses PHP v.5.3.0, but the webhost uses PHP v.5.2.12 - don't think this can be the problem though.

Link to comment
Share on other sites

it is probably worth checking with your host that their server is working properly, i had a very similar experience with a live site not logging in and it turned out that the session log folder didnt have write permissions so it never held its values.  or something roughly along those lines.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • 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.