dachshund Posted August 29, 2009 Share Posted August 29, 2009 hi, i have this code in the header of my page <?php if (isset($_SESSION['uid'])){ echo "Hello"; }else { include $_SERVER['DOCUMENT_ROOT'] . "/test/profile/login.php"; } ?> and my login.php looks like this <?php if(!$_POST['submit'] == 'login'){ echo "<div id=\"blanket\" style=\"display:none;\"></div>\n"; echo "<div id=\"popUpDiv\" style=\"display:none;\">\n"; echo "<a href=\"#\" onclick=\"popup('popUpDiv')\">\n"; echo "Close\n"; echo "</a>\n"; echo "<div id=\"loginform\">\n"; echo "<form name=\"login\" method=\"post\" action=\"#\">\n"; echo "<p>Username\n"; echo "<input name=\"username\" type=\"text\" class=\"formtext\" id=\"username\" size=\"28\">\n"; echo "</p>\n"; echo "<p>Password\n"; echo "<input name=\"password\" type=\"password\" class=\"formtext\" id=\"password\" size=\"28\">\n"; echo "</p>\n"; echo "<input type=\"submit\" name=\"submit\" class=\"loginformtext\" value=\"Submit\">\n"; echo "</form>\n"; echo "</div>\n"; echo "</div>\n"; echo "<span class=\"login_text\"><a href=\"#\" onclick=\"popup('popUpDiv')\">LOG IN</a> |\n"; }else { $user= $_POST['username']; $pass= $_POST['password']; if($user && $pass){ $sql = "SELECT * FROM `users` WHERE `username`='$user'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 1){ $epass = md5($password); $sql2 = "SELECT * FROM `users` WHERE `username` ='$user' AND `password`='$epass'"; $res2 = mysql_query($sql2) or die(mysql_error()); if(mysql_num_rows($res2) ==1){ //success $row = mysql_fetch_assoc($res2); $_SESSION['uid'] = $row['id']; echo "<span class=\"login_text\">ACCOUNT | <a href=\"\n"; include $_SERVER['DOCUMENT_ROOT']; echo "/test/profile/logout.php\">LOGOUT</a></span>\n"; }else { echo "<span class=\"login_text\">USERNAME OR PASSWORD INCORRECT | <a href=\"/phptesting\">HOME</a></span>\n"; } }else { echo "<span class=\"login_text\">USERNAME OR PASSWORD INCORRECT | <a href=\"/phptesting\">HOME</a></span>\n"; } }else { echo "<span class=\"login_text\">PLEASE SUPPLY ALL VALID FIELDS | <a href=\"/phptesting\">HOME</a></span>\n"; } } ?> it logs in fine initially, but as soon as i click a link to go to another page the session is lost. can anyone see why? thanks Link to comment https://forums.phpfreaks.com/topic/172347-solved-_sessionuid-doesnt-stay-open/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 29, 2009 Share Posted August 29, 2009 Every page the sets or references a $_SESSION variable needs a session_start statement before any content is output on the page. Link to comment https://forums.phpfreaks.com/topic/172347-solved-_sessionuid-doesnt-stay-open/#findComment-908691 Share on other sites More sharing options...
dachshund Posted August 29, 2009 Author Share Posted August 29, 2009 oh yeah forgot to say that. the header on every page has session_start() at the top. that's why i'm so confused at why it's not working. Link to comment https://forums.phpfreaks.com/topic/172347-solved-_sessionuid-doesnt-stay-open/#findComment-908696 Share on other sites More sharing options...
PFMaBiSmAd Posted August 29, 2009 Share Posted August 29, 2009 Add the following two lines of code after the first opening <?php tag on your main page to show all php detected errors - ini_set("display_errors", "1"); error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/172347-solved-_sessionuid-doesnt-stay-open/#findComment-908700 Share on other sites More sharing options...
dachshund Posted August 29, 2009 Author Share Posted August 29, 2009 when i log in it says Notice: Undefined index: id in /test/profile/login.php on line 39 which is $_SESSION['uid'] = $row['id']; Link to comment https://forums.phpfreaks.com/topic/172347-solved-_sessionuid-doesnt-stay-open/#findComment-908704 Share on other sites More sharing options...
dachshund Posted August 29, 2009 Author Share Posted August 29, 2009 and before i try to log in it says Notice: Undefined index: submit in /test/profile/login.php on line 3 which is if(!$_POST['submit'] == 'login'){ Link to comment https://forums.phpfreaks.com/topic/172347-solved-_sessionuid-doesnt-stay-open/#findComment-908713 Share on other sites More sharing options...
PFMaBiSmAd Posted August 29, 2009 Share Posted August 29, 2009 It would appear that there is no column named id in your users table. Link to comment https://forums.phpfreaks.com/topic/172347-solved-_sessionuid-doesnt-stay-open/#findComment-908715 Share on other sites More sharing options...
dachshund Posted August 29, 2009 Author Share Posted August 29, 2009 oh my god. i can't believe i was that stupid. i forgot i renamed that column userid. thank you very much for wasting your time on me. ini_set("display_errors", "1"); error_reporting(E_ALL); that's very useful as well. thanks Link to comment https://forums.phpfreaks.com/topic/172347-solved-_sessionuid-doesnt-stay-open/#findComment-908717 Share on other sites More sharing options...
PFMaBiSmAd Posted August 29, 2009 Share Posted August 29, 2009 You should actually be developing and debugging php code on a system where those two settings are set in your php.ini so that fatal parse errors would be displayed as well. It will save you a lot of time. Stop and start your web server to get any change made to php.ini to take effect and confirm the settings were changed using a phpinfo() statement. Link to comment https://forums.phpfreaks.com/topic/172347-solved-_sessionuid-doesnt-stay-open/#findComment-908721 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.