Page 1 of 1

$_session not working

Posted: Thu Aug 09, 2007 1:41 am
by m2babaey
Hi
I coded a page salam.php this way

Code: Select all

<?php
echo "salam";
$t="taj";
$_SESSION['zesht']=$t;

?>
<br>
<?php
echo "$t";
?>
<br>
<a href="hamed.php">hamed</a>
and output

salam
taj
hamed (link to hamed.php)

then I coded hamed.php this way

Code: Select all

<?php
$r = $_SESSION['zesht'];
echo $r;
?>
but when I click on the hamed link in the first page to go to hamed.php I get a notice. Why the session variable is not working?
Notice: Undefined variable: _SESSION in g:\programs new\easyphp\www\mahmud\hamed.php on line 4
thanks

Posted: Thu Aug 09, 2007 1:45 am
by iknownothing
put..

Code: Select all

session_start();
at the top of both files and try again...

Posted: Thu Aug 09, 2007 1:46 am
by Benjamin
You have to call session_start() before you can use sessions.