Jump to content

[SOLVED] Can't get $_SESSION working


ana9

Recommended Posts

I have the following on a page: (I have session_start(); on all pages)
<?php
session_start();   
if (isset($_SESSION['auth'])=="yes")
{
  echo "<p>&nbsp;</p>
<p>&nbsp;</p>
<p align='center'><font face='verdana'>You are registered.</font></p>
";
}
etc..... ?>
so that when a user registers on another page if they hit the back button they cannot register a second time.

The person is redirected to a second page where their info is inserted into the mssql database then I call:
  $_SESSION['auth']="yes";   
to set the variable

When I run this setup on my local machine it works perfectly, however when I put it up on the server it does not work.  I am running sqlserver2005, windows server 2003, IIS6, php5.
Link to comment
Share on other sites

I had that code originally and I would get an error the first time the page was loaded because there was no value for the variable.  By putting in the ISSET it eliminated the error and everything was working fine until I put it on the server.
Link to comment
Share on other sites

but isset does exactly that - it tells you if a var is set (ie, holds a value). [url=http://www.php.net/isset]isset[/url] returns either true or false. so what your check actually equates to is:
if TRUE/FALSE == 'yes'
which will always fail.

using both a check of being set as well as a check of its value should work:

[code]
<?php
if (isset($_SESSION['auth']) && $_SESSION['auth'] == "yes")
?>
[/code]

hope that helps
Cheers
Mark
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.