setting default value of superglobal
- by Prasoon Saurav
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"> <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 <input type="text" name="username" id="s" size="15" value="" />
Password <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?