Jump to content

having some strange problems with a redirect


Seitan

Recommended Posts

Hi, I'm having some strange problems with my redirect. It doesn't work. I have a page for users to login and every time they do, it doesn't redirect the user, it just shows a blank page. Here is my code. The whole page. At the bottom I will also post just the redirect code.

<?php # login.php
// This is the login page for the site. 

// Include the configuration file for error management and such.
require_once ('../****/config.inc.php');

// Set the page title and include the HTML header.
$page_title = 'Login';
$header = 'Login';
include ('../php/header.php'); 

if (isset($_POST['submitted'])) { // Check if the form has been submitted.

   require_once ('../****/mysql_connect.php');
   // Connect to the database.

   // Validate the user name address.
   if (!empty($_POST['user_name'])) {
      $u = escape_data($_POST ['user_name']);
   } else {
      echo '<p><font color="red"size="-1">
      You forgot to enter your User Name!
      </font></p>';
      $u = FALSE;
   }

   // Validate the password.
   if (!empty($_POST['password'])) {
      $p = escape_data($_POST ['password']);
   } else {
      $p = FALSE;
      echo '<p><font color="red"size="-1">
      You forgot to enter your password!
      </font></p>';
   } 
   
   if ($u && $p) { // If everything's OK.

   // Query the database.
   $query = "SELECT user_name FROM users WHERE (user_name='$u' AND password=SHA('$p')) AND active IS NULL";
   $result = mysql_query ($query) or trigger_error
    ("Query: $query\n <br />MySQL Error: " . mysql_error()); 
   
    if (@mysql_num_rows($result) == 1) {
   // A match was made.

      // Register the values & redirect.
      $row = mysql_fetch_array ($result,MYSQL_NUM);
      mysql_free_result($result); mysql_close();
      $_SESSION['user_name'] = $row[1];
      $_SESSION['user_id'] = $row[0];

      ob_end_clean(); // Delete the buffer.
      header('Location: http://www.ourvegankitchen.com');
      exit(); // Quit the script. 
      } else { //No match was made.
        echo '<p><font color="red"size="-1">Either the user name and password entered do not match those
        on file or you have not yet activated your account.</font></p>';
      }

   } else {

      echo '<p><font color="red"size="-1">Please try again.
      </font></p>';
   }
   mysql_close();
} // End of SUBMIT conditional.
?>

<p>Your browser must allow cookies in order to log in.</p>
<form action="login.php"method="post">
  
   <p><b>User Name:</b><br> <input type="text" name="user_name"
   size="20" maxlength="40" value="<?php if (isset($_POST
   ['user_name'])) echo $_POST['user_name']; ?>" /></p>
   <p><b>Password:</b> <br><input type="password" name="password"
   size="20" maxlength="20" /></p>
   <div align="center"><input type="submit" name="submit"
   value="Login" /></div>
   <input type="hidden" name="submitted" value="TRUE" />
  
</form>

<a href ="../php/forgot_password.php">Forgot Password?</a>
<?php
include ('../php/footer.php');
?>

 

and here is the redirect

 

   if ($u && $p) { // If everything's OK.

   // Query the database.
   $query = "SELECT user_name FROM users WHERE (user_name='$u' AND password=SHA('$p')) AND active IS NULL";
   $result = mysql_query ($query) or trigger_error
    ("Query: $query\n <br />MySQL Error: " . mysql_error()); 
   
    if (@mysql_num_rows($result) == 1) {
   // A match was made.

      // Register the values & redirect.
      $row = mysql_fetch_array ($result,MYSQL_NUM);
      mysql_free_result($result); mysql_close();
      $_SESSION['user_name'] = $row[1];
      $_SESSION['user_id'] = $row[0];

      ob_end_clean(); // Delete the buffer.
      header('Location: http://www.ourvegankitchen.com');
      exit(); // Quit the script. 
      } else { //No match was made.
        echo '<p><font color="red"size="-1">Either the user name and password entered do not match those
        on file or you have not yet activated your account.</font></p>';
      }

   }

ok I read the article at the top about the headers....so I broke it into 2 pages

 

the login script is like this

 

<?php # login.php
// This is the login page for the site. 

// Include the configuration file for error management and such.
require_once ('../****/config.inc.php');

// Set the page title and include the HTML header.
$page_title = 'Login';
$header = 'Login';

include ('../php/header.php'); 
?>

<p>Your browser must allow cookies in order to log in.</p>
<form action="login2.php"method="post">
  
   <p><b>User Name:</b><br> <input type="text" name="user_name"
   size="20" maxlength="40" value="<?php if (isset($_POST
   ['user_name'])) echo $_POST['user_name']; ?>" /></p>
   <p><b>Password:</b> <br><input type="password" name="password"
   size="20" maxlength="20" /></p>
   <div align="center"><input type="submit" name="submit"
   value="Login" /></div>
   <input type="hidden" name="submitted" value="TRUE" />
  
</form>

<a href ="../php/forgot_password.php">Forgot Password?</a>
<?php
include ('../php/footer.php');
?>

 

and then the the script that runs the login is like this

<?php # login.php
// This is the login page for the site. 

// Include the configuration file for error management and such.
require_once ('../****/config.inc.php');

// Set the page title and include the HTML header.
$page_title = 'Login';
$header = 'Login';


if (isset($_POST['submitted'])) { // Check if the form has been submitted.

   require_once ('../****/mysql_connect.php');
   // Connect to the database.

   // Validate the user name address.
   if (!empty($_POST['user_name'])) {
      $u = escape_data($_POST ['user_name']);
   } else {
      echo '<p><font color="red"size="-1">
      You forgot to enter your User Name!
      </font></p>';
      $u = FALSE;
   }

   // Validate the password.
   if (!empty($_POST['password'])) {
      $p = escape_data($_POST ['password']);
   } else {
      $p = FALSE;
      echo '<p><font color="red"size="-1">
      You forgot to enter your password!
      </font></p>';
   } 
   
   if ($u && $p) { // If everything's OK.

   // Query the database.
   $query = "SELECT user_name FROM users WHERE (user_name='$u' AND password=SHA('$p')) AND active IS NULL";
   $result = mysql_query ($query) or trigger_error
    ("Query: $query\n <br />MySQL Error: " . mysql_error()); 
   
    if (@mysql_num_rows($result) == 1) {
   // A match was made.

      // Register the values & redirect.
      $row = mysql_fetch_array ($result,MYSQL_NUM);
      mysql_free_result($result); mysql_close();
      $_SESSION['user_name'] = $row[1];
      $_SESSION['user_id'] = $row[0];

      ob_end_clean(); // Delete the buffer.
      header('Location: http://www.ourvegankitchen.com');
      exit(); // Quit the script. 
      } else { //No match was made.
        echo '<p><font color="red"size="-1">Either the user name and password entered do not match those
        on file or you have not yet activated your account.</font></p>';
      }

   } else {

      echo '<p><font color="red"size="-1">Please try again.
      </font></p>';
   }
   mysql_close();
} // End of SUBMIT conditional.
include ('../php/header.php'); 
?>

<?php
include ('../php/footer.php');
?>

 

so is this better? I am just learning this stuff so I need to understand the how the code is supposed to be structured? Anyways, this doesn't work for me, so can someone please help

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.