Jump to content

theamazingninja

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

theamazingninja's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. yes that was it! thank you! According to the header information on php.net, you have to put an absolute path when using the header function. This is good to know though. Thanks again.
  2. 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!!
  3. 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!!
  4. I have a new problem now. When the header redirects, it goes to a page called student_home.php where I have this code: <?php error_reporting(E_ALL); ini_set('display_errors', '1'); 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!"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Complete Guitar Method</title> </head> <body> Student Homepage. </body> </html> it was saying i wasn't logged in. I figured there was a problem with the sessions but wasn't sure. I added the code that p2grace suggested: error_reporting(E_ALL); ini_set('display_errors', '1'); and this is what it is displaying: Warning: session_start() [function.session-start]: open(/var/php_sessions/sess_90d40c9825203679c2f22fae21b19e4f, O_RDWR) failed: No such file or directory (2) in /hermes/bosweb/web075/b753/sl.dw/public_html/student_home.php on line 4 Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /hermes/bosweb/web075/b753/sl.dw/public_html/student_home.php:4) in /hermes/bosweb/web075/b753/sl.dw/public_html/student_home.php on line 4 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /hermes/bosweb/web075/b753/sl.dw/public_html/student_home.php:4) in /hermes/bosweb/web075/b753/sl.dw/public_html/student_home.php on line 4 You must be logged in to view this page Warning: Unknown(): open(/var/php_sessions/sess_90d40c9825203679c2f22fae21b19e4f, O_RDWR) failed: No such file or directory (2) in Unknown on line 0 Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/php_sessions) in Unknown on line 0 I really don't understand what's happening. Hopefully someone can help me out. Thanks.
  5. the ob_start(); and ob_flush(); worked. Thank you everyone for your help.
  6. Here is my code: <?php 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.mywebsite.com/new_page.php'); } 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.'; } } ?> Everything works fine with no errors, but the header won't redirect to the new page. Please help. Thank you.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.