RLJ Posted April 17, 2011 Share Posted April 17, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/233963-session-variable-being-set-on-my-pc-but-not-on-webhosts-server/ Share on other sites More sharing options...
spiderwell Posted April 17, 2011 Share Posted April 17, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/233963-session-variable-being-set-on-my-pc-but-not-on-webhosts-server/#findComment-1202575 Share on other sites More sharing options...
RLJ Posted April 18, 2011 Author Share Posted April 18, 2011 Yeah seems like you might be right, now all session variables are being set correctly, hopefully this will last. Quote Link to comment https://forums.phpfreaks.com/topic/233963-session-variable-being-set-on-my-pc-but-not-on-webhosts-server/#findComment-1202795 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.