Featured post
php - Can't hold session values -
i have written code login page , user page. when user provides correct username , password, code creates session variable rid , redirects user user page.
but facing weird problem, session variable remains in login page when code redirects user page says notice: undefined variable: _session in /var/www/avatar/test1.php on line 6
.
just check if session working tries output $_session['rid']
on both pages, displays rid on login page, on user page above error.
so have created 2 sample pages test.php
, test1.php
. creating session variable in test.php
, trying display in in test1.php
.
test.php :
<?php $result=session_start(); $_session["searock"]="searock"; echo $result; echo $_session["searock"]; ?> <html> <body> <a href="test1.php">next</a> </body> </html>
output :
1 searock next
test1.php :
<?php echo $_session["searock"]; ?>
output :
notice: undefined variable: _session in /var/www/avatar/test1.php on line 2
i don't know whether problem in code or in php enviroment variables.
heres screen shot of phpinfo.
can point me in right direction ?
thanks.
unless session.auto_start enabled, need call session_start
explicitly on every page want session available.
so call session_start
in test1.php , check whether $_session["searock"]
exists before accessing it:
<?php session_start(); if (isset($_session["searock"])) { echo $_session["searock"]; } ?>
- Get link
- X
- Other Apps
Comments
Post a Comment