Jump to content

Error in redirection


Machined

Recommended Posts

Hey, I've had this site functioning fully before, but now i'm redesigning it and i get an error after i login, and the login page is redirecting to a page saying that you've successfully logged in, this is the error:

 

http://localhost\/loggedin.php

 

Notice the random slash and how it annoys those who gaze upon it? lol

 

Anyway any help would be greatly appreciated i can post code if need be, but i'm hoping its just a quick fix.

 

I have check the code for out of place slashes but i may have missed something.

Link to comment
Share on other sites

Login.php - Login Page

 

<?php # login.php
if (isset($_POST['submit'])) {
  require_once ('login_connect.php');
  function escape_data ($data) {
    global $dbc;
    if (ini_get('magic_quotes_gpc')) {
      $data = stripslashes($data);
    }
    return mysql_real_escape_string($data, $dbc);
  }
  $message = NULL;
  if (empty($_POST['username'])) {
    $u = FALSE;
    $message .= '<p>You forgot to enter your username!</p>';
  } else {
    $u = escape_data($_POST['username']);
  }
  if (empty($_POST['password'])) {
    $p = FALSE;
    $message .= '<p>You forgot to enter your password!</p>';
  } else {
    $p = escape_data($_POST['password']);
  }
  if ($u && $p) { // If everything's OK.
    $query = "SELECT username
              FROM users
              WHERE username='$u'
              AND password='$p'";
    $result = @mysql_query ($query);
    $row = mysql_fetch_array ($result, MYSQL_NUM);
    if ($row) {
      // Start the session, register the values & redirect.
      session_name ('YourVisitID');
      session_start();
      $_SESSION['password'] = $p;
      $_SESSION['user_id'] = $u;
      header ("Location:  http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/loggedin.php");
      exit();
    } else {
      $message = '<p>The username and password entered do not match those on file.</p>';
    }
    mysql_close();
  } else {
    $message .= '<p>Please try again.</p>';
  }
};
$page_title = 'Login';
include ('templates/header.inc');
if (isset($message)) {
  echo '<font color="red">', $message, '</font>';
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  <fieldset><legend>Enter your information in the form below:</legend>
    <p><b>Username:</b> <input type="text" name="username" size="20" maxlength="20" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" /></p>
    <p><b>Password:</b> <input type="password" name="password" size="20" maxlength="20" /></p>
    <div align="center"><input type="submit" name="submit" value="Login" /></div>
  </fieldset>
</form><!-- End of Form -->
<small><center>*please note usernames and passwords are case sensitive*</center></small>
<?php
include ('templates/footer.inc');
?>

 

Loggedin.php - Displayed when successfully logged in

 

<?php #loggedin.php

session_name ('YourVisitID');
session_start(); // Start the session.

//If no session is present, redirect the user.
if (!isset($_SESSION['user_id'])) {
  header ("Location:  http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/index.php");
  exit(); // Quit the script.
}

// Set the page title and include the HTML header.
$page_title = 'Logged In!';
include ('templates/header.inc');

// Print a customized message.
echo "<p>You are now logged in, {$_SESSION['user_id']}!</p>";

include ('templates/footer.inc'); // Include the HTML footer.
?>

Link to comment
Share on other sites

It's this line:

 

      header ("Location:  http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/loggedin.php");

 

The dirname function is adding the extranous slash on the end, why not just use this?

 

      header ("Location: ./loggedin.php");

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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