im still new to php , and i got this error .. pls help me out here , thx .
Notice: Undefined index: sid in C:\wamp\www\test\inc\template.php on line 205
so , here is my code :
<?php
}
elseif($_SESSION['sid'] != '')
{
?>
im still new to php , and i got this error .. pls help me out here , thx .
Notice: Undefined index: sid in C:\wamp\www\test\inc\template.php on line 205
so , here is my code :
<?php
}
elseif($_SESSION['sid'] != '')
{
?>
$_SESSION
is an array so you set it like so $_SESSION['sid'] = 'some sid';
if you try to use $_SESSION['sid']
without setting it then PHP throws a notice.
If you want to avoid the notice then one of these options will work:
Option 1
<?php
// check if the variable isset before using it
if(isset($_SESSION['sid']) && $_SESSION['sid'] != '')
{
// do something
}
?>
Option 2
<?php
// turn off error reporting
// NEVER DO THIS IN A DEVELOPMENT ENVIRONMENT
// error_reporting(E_ALL) should be used in development
error_reporting(0);
if($_SESSION['sid'] != '')
{
// do something
}
?>
If you want to see if a session variable is set (or any variable for that matter), use isset()
. If you just want to see if it is empty, use empty()
after using isset()
elseif(isset($_SESSION['sid']) && !empty($_SESSION['sid']))