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']; }?> Quote Link to comment Share on other sites More sharing options...
this.user Posted November 2, 2009 Author Share Posted November 2, 2009 bump Quote Link to comment 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>"; ?> Quote Link to comment 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.