setting default value of superglobal

Posted by Prasoon Saurav on Stack Overflow See other posts from Stack Overflow or by Prasoon Saurav
Published on 2010-05-23T08:04:19Z Indexed on 2010/05/23 8:10 UTC
Read the original article Hit count: 277

Filed under:

I have been working on a Timesheet Management website. I have my home page as index.php

//index.php
<?php
      session_start();

    if($_SESSION['logged']=='set')
    {

       $x=$_SESSION['username'];

              echo '<div align="right">';
              echo 'Welcome ' .$x.'<br/>';
              echo'<a href="logout.php" class="links">&nbsp;<b><u>Logout</u></b></a>' ;   

    }   

    else if($_SESSION['logged']='unset')
    {
             echo'<form id="searchform" method="post" action="processing.php">
                  <div>
                  <div align="right">
                  Username&nbsp;<input type="text" name="username" id="s" size="15" value="" />
                  &nbsp;Password&nbsp;<input type="password" name="pass" id="s" size="15" value="" />
                  <input type="submit" name="submit" value="submit" />
                  </div>
                  <br />
                  </div>
                  </form> ';

     }
?>

The problem I am facing is that during the first run of this script I get an error Notice: Undefined index: logged in C:\wamp\www\ps\index.php but after refreshing the page the error vanishes.

How can I correct this problem? logged is a variable which helps determine whether the user is logged in or not. When the user is logged in $_SESSION['logged'] is set, otherwise unset. I want the default value of $_SESSION['logged'] to be unset prior to the execution of the script. How can I solve this problem?

© Stack Overflow or respective owner

Related posts about php