Results 1 to 4 of 4

Thread: Login page: PHP header erorr

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    150

    Resolved Login page: PHP header erorr

    Hi Folks,

    I am having trouble with my phph login page. When I enter the correct username and password, I get the error message below.

    Code:
    Warning: Header may not contain more than a single header, new line detected. in C:\xampp\htdocs\2012\login.php on line 9
    You are being redirected to your original page request!
    (If your browser doesn't support this, click here)

    It is pointing to line 9 which I noticed starts with header and the full code for the login page is the one below. I will appreciate if someone could sport my mistake and suggest corrections please.

    Code:
     <?php
    session_start();
    $_SESSION['logged'] = 0;
    
    if (isset($_POST['submit'])) {
      if ($_POST['username'] == "nations" && 
          $_POST['password'] == "united") {
        $_SESSION['logged'] = 1;
        header("Refresh: 5; URL=" . $_POST['redirect'] . "");
        echo "You are being redirected to your original page request!<br>";
        echo "(If your browser doesn't support this, " .
             "<a href=\"" . $_POST['redirect']. "\">click here</a>)";
      } else {
    ?>
    <html>
    <head>
    <title>Working with  PHP and MySQL</title>
    </head>
    <body>
    <p>
      Invalid Username and/or Password<br><br>
      <form action="login.php" method="post">
        <input type="hidden" name="redirect"
          value="<?php echo $_POST['redirect']; ?>">
        Username: <input type="text" name="username"><br>
        Password: <input type="password" name="password"><br><br>
        <input type="submit" name="submit" value="Login">
      </form>
    </p>
    <?php
      }
    } else {
    ?>
    <html>
    <head>
    <title>Working with  PHP and MySQL</title>
    </head>
    <body>
    <p>
      You must be logged in to view this page<br><br>
    <?
    if (isset($_GET['redirect'])) {
      $redirect = $_GET['redirect'];
    } else {
      $redirect = "index.php";
    }
    ?>
      <form action="login.php" method="post">
        <input type="hidden" name="redirect" 
          value="<?php echo $_GET['redirect']; ?>">
        Username: <input type="text" name="username"><br>
        Password: <input type="password" name="password"><br><br>
        <input type="submit" name="submit" value="Login">
      </form>
    </p>
    <?php
    }
    ?>
    </body>
    </html>
    Thanks in advance.
    Last edited by menre; Apr 4th, 2012 at 02:23 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width