phpretard Posted April 16, 2008 Share Posted April 16, 2008 When I change pages it seems that the session is destroyed. Here is the code: <?php session_start(); $link=mysql_connect("secret","secret","secret"); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db=mysql_select_db("secret"); if(!$db) { die("Unable to select database"); } if(!get_magic_quotes_gpc()) { $login=mysql_real_escape_string($_POST['login']); }else { $login=$_POST['login']; } $qry="SELECT * FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'"; $result=mysql_query($qry); while($row = mysql_fetch_array($result)) { $member_id=$row['member_id']; $firstname=$row['firstname']; $lastname=$row['lastname']; } if($result) { if(mysql_num_rows($result)>0) { session_regenerate_id(); $member=mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID']=$member_id; $_SESSION['SESS_MEMBER_FNAME']=$firstname; $_SESSION['SESS_MEMBER_LNAME']=$lastname; header("location: member-index.php"); }else header("location: login-failed.php"); } }else { die("Query failed"); } ?> Can you tell why by this code? The session might not be ending but it seems to... Each time I go to a new page the form shows up again instead of member index. <? if (!isset($_SESSION['SESS_MEMBER_ID'])){ echo" <a name='login_top'></a> <form style='padding-left:10px;' id='loginForm' name='loginForm' method='post' action='#login_top'> $log_error <b>Login</b><br> <input name='login' type='text' id='login' /><br> <b>Password</b><br> <input name='password' type='password' id='password' /><br> <input style='margin-top:5px; height:23px; width:75px; font-size:10px;' type='submit' name='Login' value='Login' /> </form> "; } elseif (isset($_SESSION['SESS_MEMBER_ID'])){ include 'Login/member-index.php'; } ?> Can anyone help with this? If the session is not ending what is the best way to pass session variables from page to page? Link to comment https://forums.phpfreaks.com/topic/101371-solved-session-close/ Share on other sites More sharing options...
micah1701 Posted April 16, 2008 Share Posted April 16, 2008 do you have session_start(); at the top of every page or just the first page? it needs to be on every page so that php knows to continue the current session. Link to comment https://forums.phpfreaks.com/topic/101371-solved-session-close/#findComment-518502 Share on other sites More sharing options...
jonsjava Posted April 16, 2008 Share Posted April 16, 2008 change <?php if (!isset($_SESSION['SESS_MEMBER_ID'])){ echo" <a name='login_top'></a> <form style='padding-left:10px;' id='loginForm' name='loginForm' method='post' action='#login_top'> $log_error <b>Login</b><br> <input name='login' type='text' id='login' /><br> <b>Password</b><br> <input name='password' type='password' id='password' /><br> <input style='margin-top:5px; height:23px; width:75px; font-size:10px;' type='submit' name='Login' value='Login' /> </form> "; } elseif (isset($_SESSION['SESS_MEMBER_ID'])){ include 'Login/member-index.php'; } ?> to <?php session_start(); if (!isset($_SESSION['SESS_MEMBER_ID'])){ echo" <a name='login_top'></a> <form style='padding-left:10px;' id='loginForm' name='loginForm' method='post' action='#login_top'> $log_error <b>Login</b><br> <input name='login' type='text' id='login' /><br> <b>Password</b><br> <input name='password' type='password' id='password' /><br> <input style='margin-top:5px; height:23px; width:75px; font-size:10px;' type='submit' name='Login' value='Login' /> </form> "; } elseif (isset($_SESSION['SESS_MEMBER_ID'])){ include 'Login/member-index.php'; } ?> Link to comment https://forums.phpfreaks.com/topic/101371-solved-session-close/#findComment-518503 Share on other sites More sharing options...
phpretard Posted April 16, 2008 Author Share Posted April 16, 2008 I do now...and it works great! Thank you Link to comment https://forums.phpfreaks.com/topic/101371-solved-session-close/#findComment-518510 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.