Jump to content

Archived

This topic is now archived and is closed to further replies.

doforumda

Help with SESSION variable

Recommended Posts

Hi

 

I am using very simple code. Here it is

 

<?php
session_start();
$user = "guest";
$uid = "1";
echo $_SESSION['user']."<br />";
echo $_SESSION['uid'];
?>

it displays this error

Notice: Undefined index: user in C:\wamp\www\DealDash\index.php on line 5
Notice: Undefined index: uid in C:\wamp\www\DealDash\index.php on line 6

 

how can I solve this problem? Help please

Share this post


Link to post
Share on other sites
<?php
session_start();
$_SESSION['user'] = "guest";
$_SESSION['uid'] = "1";

echo $_SESSION['user']."<br />";
echo $_SESSION['uid'];
?>

Share this post


Link to post
Share on other sites

It's giving you an error for anytime you use a variable that hasn't been inialized yet. To stop that, just post this BEFORE the error (I.E. the variables are used)

 

<?php error_reporting(E_ALL ^ E_NOTICE); ?>

Share this post


Link to post
Share on other sites

To stop the warning, fix the condition that is causing the warning in the first place.

Share this post


Link to post
Share on other sites

×

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.