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 7 of 7
  1. #1
    New Coder
    Join Date
    Jan 2010
    Location
    In a dump
    Posts
    64
    Thanks
    9
    Thanked 2 Times in 2 Posts

    cannot modify header information

    I am trying to make a form to allow a user to sign into the webpage however I wanted to make the php check if the user had filled out all the details on the form and if not then display a message and then go back to the login page. I have put the header alteration in but it states that the header information has already been changed.

    I think I know what is wrong as I am requesting information from the previous page before I can call the change of page but I dont know how I would do it any other way.

    Any help would be greatly appreciated.

    Code:

    [code]
    <?php
    if(!empty($_REQUEST['email'])){$email = $_REQUEST['email'];}
    else{$email = NULL; echo "<p><b>You have forgot to enter your email address. Please sign in again.</b>";};

    if(!empty($_REQUEST['password'])){$password = $_REQUEST['password'];}
    else{$password = NULL; echo "<p><b>You have forgot to enter your password. Please sign in again.</b>";};

    $_REQUEST['signin'];

    if($password && $email){
    $dbcheck = mysql_query("select * from users where username = '$email'") or die(mysql_error());
    }
    else
    {
    sleep(5);
    header('location: login.html');
    };
    ?>
    [code]

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    See http://php.net/header
    Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.
    Do you have anything echoed or any html tags before that php code?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    InterbredMonkey (01-07-2010)

  • #3
    New Coder
    Join Date
    Jan 2010
    Location
    In a dump
    Posts
    64
    Thanks
    9
    Thanked 2 Times in 2 Posts
    yeah I have HTML above it. I have taken it out and still the same. There is also an echo above the header statment.

    The only issue is that before I wanted to re-direct the page I wanted to display a message to let the user know and this will not work.

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    There is also an echo above the header statment.
    Instead of echoing the error there, save it to a variable, say
    PHP Code:
    $error="You have forgot to enter your email address. Please sign in again"
    or
    PHP Code:
    $error="You have forgotten to enter your password. Please sign in again"
    and then change your header like
    PHP Code:
    if(!isset($error)){
    $dbcheck mysql_query("select * from users where username = '$email'") or die(mysql_error());
    header('location: success.html');
    }
    else
    {
    //echo error here

    }; 
    ie, post your form to the same page and echo the error, if any. Otherwise do the action and redirect to a new page.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Better still, create a session variable and sacve the error message to that, then check for that session variable being set on your login page, and display it if it exists. Also with headers sent errors, check the error to see what line and file it says the output started. The line it started is where you need to find what is causing the output, and stop it. You should avoid echoing anything if possible if you have headers being sent

  • #6
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Also, one other method if you want to show your error message for say 5 seconds then move to the login page is to use the meta refresh method
    Code:
    <meta http-equiv="refresh" content="5;url=http://www.yoursite.com/login.php">
    5 is the number of seconds to wait before redirection

  • Users who have thanked JAY6390 for this post:

    InterbredMonkey (01-07-2010)

  • #7
    New Coder
    Join Date
    Jan 2010
    Location
    In a dump
    Posts
    64
    Thanks
    9
    Thanked 2 Times in 2 Posts
    YATTA!!!

    Thank you very very much everyone who has posted.


  •  

    Posting Permissions

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