$_session not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

$_session not working

Post 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
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

put..

Code: Select all

session_start();
at the top of both files and try again...
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

You have to call session_start() before you can use sessions.
Post Reply