this.user Posted November 2, 2009 Share Posted November 2, 2009 I have this code, that determines if the user has a session running, if not checks for a cookie and if they have cookie create a session for them if not, send them to the index page. However, it does not work. It does not send the user back to the index page when appropriate. Can someone please tell me whats wrong i have no clue. <?php session_start(); $sessionuser = $_SESSION['user']; $sessionpassword = $_SESSION['password']; $ui = ""; $sessionquery = "SELECT id FROM user WHERE username = '" . trim($sessionuser) . "' AND password = '" . trim($sessionpassword) ."'"; $query_sessionresult = mysql_query($sessionquery) or die(mysql_error()); if (mysql_num_rows($query_sessionresult) == 0) { if(isset($_COOKIE['user'])&&(isset($_COOKIE['password']))) { $cookieuser = mysql_real_escape_string($_COOKIE['user']); $cookiepassword = mysql_real_escape_string($_COOKIE['password']); $cookiequery = "SELECT id FROM user WHERE username = '$cookieuser' AND password = '$cookiepassword'"; $query_cookieresult = mysql_query($cookiequery) or die(mysql_error()); if(mysql_num_rows($query_cookieresult) == 0) { header("Location: index.php"); die(); } else { $query_cookierow = mysql_fetch_array($query_cookieresult); $ui = $query_cookierow['id']; } } else { header("Location: index.php"); die(); } } else { $query_sessionrow = mysql_fetch_array($query_sessionresult); $ui = $query_sessionrow['id']; }?> Link to comment https://forums.phpfreaks.com/topic/179937-session-code-not-working/ Share on other sites More sharing options...
this.user Posted November 2, 2009 Author Share Posted November 2, 2009 bump Link to comment https://forums.phpfreaks.com/topic/179937-session-code-not-working/#findComment-949263 Share on other sites More sharing options...
phpretard Posted November 2, 2009 Share Posted November 2, 2009 When I run into session problems I always start with the basics and make sure the correct session isset: <? echo "<pre>". print_r($_SESSION,true) ."</pre>"; echo "<pre>". print_r($_COOKIE)."</pre>"; ?> Link to comment https://forums.phpfreaks.com/topic/179937-session-code-not-working/#findComment-949269 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.