theamazingninja Posted July 5, 2008 Share Posted July 5, 2008 I am working on a login script. Here is the login page's code: <?php ob_start(); session_start(); require_once('db.php'); include('functions.php'); if(isset($_POST['Login'])) { if($_POST['username']!='' && $_POST['password']!='') { $query = mysql_query('SELECT ID, Username, Active FROM users WHERE Username = "'.mysql_real_escape_string($_POST['username']).'" AND Password = "'.mysql_real_escape_string(md5($_POST['password'])).'"'); if(mysql_num_rows($query) == 1) { $row = mysql_fetch_assoc($query); if($row['Active'] == 1) { $_SESSION['user_id'] = $row['ID']; $_SESSION['logged_in'] = TRUE; header('Location: http://www.mysite.com/new_page.php'); die(); } else{ $error = 'Your membership was not activated. Please open the email that we sent and click on the activation link.'; } } else { $error = '<font color="#FF0000" size=4>Wrong username or password.</font>'; } } else{ $error = 'Please enter both your username and password to access your account.'; } } ob_flush(); ?> Then if the username and password are correct, the user gets redirected via the header function to the new page. Then on the new page, I have this script: <?php ob_start(); session_start(); if (!isset($_SESSION['user_id'])) { echo "You must be logged in to view this page"; die(); } else { echo "Hello, you're logged in!"; } ob_flush(); ?> And for some reason, when I login using a valid username and password, it says "You must be logged in to view this page." I have tried everything I can think of. Please help!! Link to comment https://forums.phpfreaks.com/topic/113339-sessions-dont-work/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.