Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts

    redirecting a page when wrong user and pass

    I get the error: headers already sent


    Code:
    if($count==1){
    // Register $myusername, $mypassword and redirect to file "login_success.php"
    session_register("myusername");
    session_register("mypassword");
    header("location:login_success.php");
    }
    else {
    echo "Wrong Username or Password";
    header("location:index.html");
    
    }

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Code:
    //echo "Wrong Username or Password";
    header("location:index.html");
    You can't echo/output something before header()
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts
    i swapped them around, still doesn't work

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    It never will mate, as soon as you send a header redirection it will force the page to the new location - you will never get the output from the echo. Instead, redirect them to a page that includes the error message, or use the $_SESSION (from your last post) or $_GET, to pass an error code back to the login to display the results. Something like:
    PHP Code:
    header('Location: index.php?ec=1'); 
    Then back in index.php
    PHP Code:
    <?php
    // some stuffs

    if (isset($_GET['ec']))
    {
        switch(
    $_GET['ec'])
        {
            case 
    1:
                echo 
    'Invalid username specified';
                break;
            case 
    2:
                echo 
    'Invalid password specified';
                break;
        }
    }
    // login stuff.
    Or whatever you want to do with the feedback.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

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