Jump to content

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


RLJ

Recommended Posts

Hi all,

 

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

 

page.php:

<?php
session_start(); 
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.--------
unset($_SESSION['gocheck']);
//rest of page
?>

 

gocheck.php:

<?php
session_start(); 
$_SESSION['gocheck'] = 'yes';

echo"
<!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\">
<head>
<script type=\"text/javascript\" language=\"JavaScript\">
window.location.replace('page.php');
</script>
</head>

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

</html>

";

?>

 

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?

 

Thanks!

 

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