bhavin12300 Posted July 9, 2007 Share Posted July 9, 2007 HI I AM LITTLE NEW TO PHP I AM HAVING SOME PROBLEM REGARDING THE SESSION IN PHP. HERE IS MY PROBLEM. AS LIKE ALL WEBSITE MY AIM IS TO ASK FOR ID AND PASSWORD FROM USER AND AFTER CHECKING THE ID AND PASSWORD I CREATE ONE SESSION AND STORE USER ID IN ONE VARIABLE TO REFER TO OTHER PAGE. AND I AM REDIRECTING TO HOME PAGE AFTER SETTING SESSION AND AT THAT HOME PAGE I AM UNABLE TO RETRIEVE THAT SESSION VARIABLE DATA. MEANS MY SESSION IS NOT PERSISTENCE. CAN ANYONE HELP ME WAITING FOR REPLY. IF CODE REQUIRE ASK ME I AM DOING THIS ON SERVER LOT LOCAL SERVER Quote Link to comment https://forums.phpfreaks.com/topic/59058-solved-session-help/ Share on other sites More sharing options...
tapos Posted July 9, 2007 Share Posted July 9, 2007 can i see ur code? You must start session to retrive the variables. -- Tapos Pal Quote Link to comment https://forums.phpfreaks.com/topic/59058-solved-session-help/#findComment-293177 Share on other sites More sharing options...
bhavin12300 Posted July 9, 2007 Author Share Posted July 9, 2007 yes you can c code.i did start my session first code is where i am setting my session. and second is where i am retrieving. 1) <?php $mydb=mysql_connect('mysql3.freehostia.com:3306','bhapit_database','canuseeme2'); if(mysql_select_db('bhapit_database',$mydb)) { } else { echo("databse not connected"); } $userid = $_POST['userid']; $password = $_POST['password']; $submit="select * from user where userid like '$userid' and password like '$password'"; $result=mysql_query($submit); $num=1; while($row=mysql_fetch_array($result)) { session_start(); $SESSION['username'] =$userid; mysql_close($mydb); header("Location: index.php"); } ?> <html> <head> </head> <body> <table > <tr><td > <?php include("header.php"); ?></td></tr> <tr><td > <?php include("nevigator.php"); ?></td></tr> <tr> <td>Registration Done Sucessfully.<br>Login Here<?php include("login_user.php"); ?> </td> </tr> <tr><td> <?php include("footer.php"); ?></td></tr> <table> </body> </html> here is the code for session retrival <?php session_start(); $MYNAME=$_SESSION['USERNAME']; //retrieve data echo $MYNAME; ?> <html> <head> </head> <body> <table > <tr><td > <?php include("header.php"); ?></td></tr> <?php if($MYNAME=="") { } else { echo("<font size=3><b>WELCOME!!"); echo $MYNAME; echo(" <a href=>Sign Out</a></b></font>"); } ?> <tr><td > <?php include("nevigator.php"); ?></td></tr> <tr> <td> <?php include("center.php"); ?> </td> </tr> <tr><td> <?php include("footer.php"); ?></td></tr> <table> </body> </html> ANY INFORMATION? Quote Link to comment https://forums.phpfreaks.com/topic/59058-solved-session-help/#findComment-293179 Share on other sites More sharing options...
tapos Posted July 9, 2007 Share Posted July 9, 2007 I think here is the problem: $SESSION['username'] =$userid; $MYNAME=$_SESSION['USERNAME']; This should be $MYNAME = $_SESSION['username']; -- Tapos Pal Quote Link to comment https://forums.phpfreaks.com/topic/59058-solved-session-help/#findComment-293184 Share on other sites More sharing options...
bhavin12300 Posted July 9, 2007 Author Share Posted July 9, 2007 no sir its still same i am not getting answer here is the update code <?php session_start(); $MYNAME=$_SESSION['username']; //retrieve data echo $MYNAME; ?> <html> <head> </head> <body> <table > <tr><td > <?php include("header.php"); ?></td></tr> <?php if($MYNAME=="") { } else { echo("<font size=3><b>WELCOME!!"); echo $MYNAME; echo(" <a href=>Sign Out</a></b></font>"); } ?> <tr><td > <?php include("nevigator.php"); ?></td></tr> <tr> <td> <?php include("center.php"); ?> </td> </tr> <tr><td> <?php include("counter_footer.php"); ?></td></tr> <table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/59058-solved-session-help/#findComment-293201 Share on other sites More sharing options...
sushant_d84 Posted July 9, 2007 Share Posted July 9, 2007 CONFIRM ONE THING is the statement session_start() is present at the top of all your pages? confirm this once Quote Link to comment https://forums.phpfreaks.com/topic/59058-solved-session-help/#findComment-293203 Share on other sites More sharing options...
tapos Posted July 9, 2007 Share Posted July 9, 2007 $SESSION['username'] =$userid; Here is the problem: $_SESSION['username'] = $userid; -- Tapos Pal Quote Link to comment https://forums.phpfreaks.com/topic/59058-solved-session-help/#findComment-293204 Share on other sites More sharing options...
tapos Posted July 9, 2007 Share Posted July 9, 2007 $SESSION['username'] =$userid; Here is the problem: $_SESSION['username'] = $userid; -- Tapos Pal Quote Link to comment https://forums.phpfreaks.com/topic/59058-solved-session-help/#findComment-293205 Share on other sites More sharing options...
bhavin12300 Posted July 9, 2007 Author Share Posted July 9, 2007 wowwwwwwwwwwwww thasnk you so much sir i will be back if i got another proble thasnk you once again Quote Link to comment https://forums.phpfreaks.com/topic/59058-solved-session-help/#findComment-293244 Share on other sites More sharing options...
bhavin12300 Posted July 9, 2007 Author Share Posted July 9, 2007 yes you can c code.i did start my session first code is where i am setting my session. and second is where i am retrieving. 1) <?php $mydb=mysql_connect('mysql3.freehostia.com:3306','bhapit_database',' '); if(mysql_select_db('bhapit_database',$mydb)) { } else { echo("databse not connected"); } $userid = $_POST['userid']; $password = $_POST['password']; $submit="select * from user where userid like '$userid' and password like '$password'"; $result=mysql_query($submit); $num=1; while($row=mysql_fetch_array($result)) { session_start(); $SESSION['username'] =$userid; mysql_close($mydb); header("Location: index.php"); } ?> <html> <head> </head> <body> <table > <tr><td > <?php include("header.php"); ?></td></tr> <tr><td > <?php include("nevigator.php"); ?></td></tr> <tr> <td>Registration Done Sucessfully.<br>Login Here<?php include("login_user.php"); ?> </td> </tr> <tr><td> <?php include("footer.php"); ?></td></tr> <table> </body> </html> here is the code for session retrival <?php session_start(); $MYNAME=$_SESSION['USERNAME']; //retrieve data echo $MYNAME; ?> <html> <head> </head> <body> <table > <tr><td > <?php include("header.php"); ?></td></tr> <?php if($MYNAME=="") { } else { echo("<font size=3><b>WELCOME!!"); echo $MYNAME; echo(" <a href=>Sign Out</a></b></font>"); } ?> <tr><td > <?php include("nevigator.php"); ?></td></tr> <tr> <td> <?php include("center.php"); ?> </td> </tr> <tr><td> <?php include("footer.php"); ?></td></tr> <table> </body> </html> ANY INFORMATION? Quote Link to comment https://forums.phpfreaks.com/topic/59058-solved-session-help/#findComment-293246 Share on other sites More sharing options...
bhavin12300 Posted July 9, 2007 Author Share Posted July 9, 2007 yes you can c code.i did start my session first code is where i am setting my session. and second is where i am retrieving. 1) <?php $mydb=mysql_connect('mysql3.freehostia.com:3306','bhapit_database',' '); if(mysql_select_db('bhapit_database',$mydb)) { } else { echo("databse not connected"); } $userid = $_POST['userid']; $password = $_POST['password']; $submit="select * from user where userid like '$userid' and password like '$password'"; $result=mysql_query($submit); $num=1; while($row=mysql_fetch_array($result)) { session_start(); $SESSION['username'] =$userid; mysql_close($mydb); header("Location: index.php"); } ?> <html> <head> </head> <body> <table > <tr><td > <?php include("header.php"); ?></td></tr> <tr><td > <?php include("nevigator.php"); ?></td></tr> <tr> <td>Registration Done Sucessfully.<br>Login Here<?php include("login_user.php"); ?> </td> </tr> <tr><td> <?php include("footer.php"); ?></td></tr> <table> </body> </html> here is the code for session retrival <?php session_start(); $MYNAME=$_SESSION['USERNAME']; //retrieve data echo $MYNAME; ?> <html> <head> </head> <body> <table > <tr><td > <?php include("header.php"); ?></td></tr> <?php if($MYNAME=="") { } else { echo("<font size=3><b>WELCOME!!"); echo $MYNAME; echo(" <a href=>Sign Out</a></b></font>"); } ?> <tr><td > <?php include("nevigator.php"); ?></td></tr> <tr> <td> <?php include("center.php"); ?> </td> </tr> <tr><td> <?php include("footer.php"); ?></td></tr> <table> </body> </html> ANY INFORMATION? Quote Link to comment https://forums.phpfreaks.com/topic/59058-solved-session-help/#findComment-293247 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.