chocopi Posted May 26, 2007 Share Posted May 26, 2007 ok, so when i log in my sessions are meant to be carried across from this page: <?php if(isset($_POST["submit"])) { if ($login_check > 0) { $_SESSION['id'] = "$id"; $_SESSION['username'] = "$username"; $_SESSION['password'] = "$password"; $filename = "login_check.php"; ob_end_clean(); header("Location: ".$filename); } else { $errors++; } } ?> That goes through a page to this. So either the sessions are wrong or this isset is wrong as it redirects even when its not meant to. <?php // Start Session session_start(); require_once('page_header.php'); // Declare Variables $id = $_SESSION['id']; $username = $_SESSION['username']; $password = $_SESSION['password']; $title = 'Chocopi :: Main'; if(isset($id, $username, $password)) { $filename = "index.php"; header("Location: ".$filename); } else { echo "".$username."(#".$id.")"; } ?> So if you can point out my mistakes, many thanks ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/53051-solved-session-isset-problems/ Share on other sites More sharing options...
taith Posted May 26, 2007 Share Posted May 26, 2007 you need to session_start() at the top of your page there... starting a session on only 1 page doesnt start it on all pages... Quote Link to comment https://forums.phpfreaks.com/topic/53051-solved-session-isset-problems/#findComment-262061 Share on other sites More sharing options...
chocopi Posted May 26, 2007 Author Share Posted May 26, 2007 it is there i just didnt post it <?php ob_start(); session_start(); // Variables $username = $_POST['username']; $raw_password = $_POST['password']; $password = md5($raw_password); $login = mysql_query("SELECT id FROM Mark WHERE username='$username' && password='$password'"); $login_check = mysql_num_rows($login); $row = mysql_fetch_array($login, MYSQL_ASSOC); $id = $row['id']; if(isset($_POST["submit"])) { if ($login_check > 0) { $_SESSION['id'] = "$id"; $_SESSION['username'] = "$username"; $_SESSION['password'] = "$password"; $filename = "login_check.php"; ob_end_clean(); header("Location: ".$filename); } else { $errors++; } } ob_flush(); ?> Cheers, ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/53051-solved-session-isset-problems/#findComment-262062 Share on other sites More sharing options...
MadTechie Posted May 26, 2007 Share Posted May 26, 2007 <?php // Declare Variables $id = $_SESSION['id']; $username = $_SESSION['username']; $password = $_SESSION['password']; $title = 'Chocopi :: Main'; if(isset($id, $username, $password)) ?> OK lets look at this $id gets SET to $_SESSION['id'] thus they ARE set even if $_SESSION['id'] = null (nothing); you need to isset($_SESSION['id']) or !empty($id) or even is_null($id) Quote Link to comment https://forums.phpfreaks.com/topic/53051-solved-session-isset-problems/#findComment-262064 Share on other sites More sharing options...
chocopi Posted May 26, 2007 Author Share Posted May 26, 2007 oh ok thanks, so how would the whole line look ? Quote Link to comment https://forums.phpfreaks.com/topic/53051-solved-session-isset-problems/#findComment-262066 Share on other sites More sharing options...
MadTechie Posted May 26, 2007 Share Posted May 26, 2007 you should work that out for yourself but personally i do the following <?php if( isset($_SESSION['id']) && isset($_SESSION['username']) && isset($_SESSION['password']) ) ?> also remember session_start(); mus be used in all pages that use $_SESSION Quote Link to comment https://forums.phpfreaks.com/topic/53051-solved-session-isset-problems/#findComment-262068 Share on other sites More sharing options...
chocopi Posted May 26, 2007 Author Share Posted May 26, 2007 kool thanks, it works gravy now, thanks ! It was redirecting because i had my true and false mixed up Anyways, thanks Quote Link to comment https://forums.phpfreaks.com/topic/53051-solved-session-isset-problems/#findComment-262071 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.