www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 30

Thread: header redirecton problem

  1. #1
    Join Date
    Feb 2008
    Posts
    78

    header redirecton problem

    i am using the following code and i keep getting


    <?
    session_start();
    include("dbblsr.php");

    mysql_select_db("cgowie_teamcanada", $conn);

    $result = mysql_query("SELECT * FROM teamcanada WHERE reqemail='$_POST[reqemail]'");
    $row = mysql_fetch_array($result);
    $pass = $row['password'];
    $rights = $row['useright'];
    $name = $row['reqfirst'];
    $email =$row['reqemail'];

    IF ($pass != md5($_POST['password'])){
    ("Incorrect password.");
    header( 'Location: loginca.php' ) ;
    }
    ELSE{
    $_SESSION['access']= $_SESSION['access']+1;
    $_SESSION['rights']= $rights;
    $_SESSION['reqfirst']= $name;
    $_SESSION['reqemail']= $email;
    header( 'Location: team_canada.php' ) ;

    }
    ?>
    keep getting an error saying something along the lines of:

    Warning: Cannot add header information - headers already sent by (output started at

    etc. etc. etc.

    Could somebody please tell me what I need to do differently?

  2. #2
    Join Date
    Jun 2003
    Location
    here
    Posts
    4,551
    that error means that you have content before your headers/sessions, possibly a space or something before quotes or some such...

    and read my sig:

  3. #3
    Join Date
    Feb 2008
    Posts
    78
    I use the same code on a different page with a headers and it worked fine the only thing i change was the db and the headers

  4. #4
    Join Date
    Feb 2008
    Posts
    78
    I use the same code and just change the table that i check and it works fine. I am new to this can some help. Do i need to have the password and userid located at a certain poition in the sql table?

  5. #5
    Join Date
    Nov 2007
    Posts
    316
    Its nothing to do with the password and userid in the table.

    The error is related to these lines:
    PHP Code:
    header'Location: loginca.php' ) ;
    //snip
    header'Location: team_canada.php' ) ; 
    There must NOT be any kind of output before these lines. There must be NO content (including whitespace) outside of your PHP tags before these lines.

    Try attaching your code files as well as the whole error. It might make it easier for us.

  6. #6
    Join Date
    Jun 2006
    Location
    Down at the bottom of the garden
    Posts
    1,239
    Add this at the very top of your code..
    PHP Code:
    ob_start(); 

  7. #7
    Join Date
    Feb 2008
    Posts
    78

    Thumbs up

    Thanks it worked. Can you tell me what that line of code does

  8. #8
    Join Date
    Nov 2007
    Posts
    316
    Normally php outputs during processing, so the starts receiving the page while the script is still running.

    The ob functions control buffering of output. With ob started php outputs everything to a buffer. Only when the php has finished processing (or if the buffer is explicitly flushed) does the user start receiving the page.

    The added code means that your header calls (which aren't buffered) are being sent to the client before they receive any output.

  9. #9
    Join Date
    Feb 2008
    Posts
    78
    With that code it does go to header location but it does not check the db and it does not execute the else statement

  10. #10
    Join Date
    Nov 2007
    Posts
    316
    With the ob started it will still execute all the code.

  11. #11
    Join Date
    Feb 2008
    Posts
    78
    That is not happening for me

  12. #12
    Join Date
    Feb 2008
    Posts
    78
    This is what the code looks like now when i execute it displays the header for the incorret password but when i input a user email and password it redisplays the same thing.
    <?
    ob_start();
    session_start();
    include("dbblsr.php");

    mysql_select_db("cgowie_teamcanada", $conn);

    $result = mysql_query("SELECT * FROM teamcanada WHERE reqemail='$_POST[reqemail]'");
    $row = mysql_fetch_array($result);
    $pass = $row['password'];
    $rights = $row['useright'];
    $name = $row['reqfirst'];
    $email =$row['reqemail'];

    IF ($pass != md5($_POST['password'])){
    ("Incorrect password.");
    header( 'Location: loginca.php' ) ;
    }
    ELSE{
    $_SESSION['access']= $_SESSION['access']+1;
    $_SESSION['rights']= $rights;
    $_SESSION['reqfirst']= $name;
    $_SESSION['reqemail']= $email;
    header( 'Location: team_canada.php' ) ;

    }
    ?>

    Then i try this notice that it has a different db and this db does not include the table i am trying to check but it still got to the incorrect header location
    <?
    ob_start();
    session_start();
    include("db.php");

    mysql_select_db("cgowie_teamcanada", $conn);

    $result = mysql_query("SELECT * FROM teamcanada WHERE reqemail='$_POST[reqemail]'");
    $row = mysql_fetch_array($result);
    $pass = $row['password'];
    $rights = $row['useright'];
    $name = $row['reqfirst'];
    $email =$row['reqemail'];

    IF ($pass != md5($_POST['password'])){
    ("Incorrect password.");
    header( 'Location: loginca.php' ) ;
    }
    ELSE{
    $_SESSION['access']= $_SESSION['access']+1;
    $_SESSION['rights']= $rights;
    $_SESSION['reqfirst']= $name;
    $_SESSION['reqemail']= $email;
    header( 'Location: team_canada.php' ) ;

    }
    ?>

  13. #13
    Join Date
    Feb 2008
    Posts
    78
    any ideas

  14. #14
    Join Date
    Jun 2003
    Location
    here
    Posts
    4,551
    you still havn't used the forums [php] and [/php] tags around your code, which means that it's far harder to spot errors, so I'm gonna wait for that, like I waited for you to do it earlier with your first post.

    http://www.webdeveloper.com/forum/sh...68&postcount=5 <-- read!

  15. #15
    Join Date
    Feb 2008
    Posts
    78
    This is all php code

    <?php
    ob_start();
    session_start();
    include("dbblsr.php");

    mysql_select_db("cgowie_teamcanada", $conn);

    $result = mysql_query("SELECT * FROM teamcanada WHERE reqemail='$_POST[reqemail]'");
    $row = mysql_fetch_array($result);
    $pass = $row['password'];
    $rights = $row['useright'];
    $name = $row['reqfirst'];
    $email =$row['reqemail'];

    IF ($pass != md5($_POST['password'])){
    ("Incorrect password.");
    header( 'Location: loginca.php' ) ;
    }
    ELSE{
    $_SESSION['access']= $_SESSION['access']+1;
    $_SESSION['rights']= $rights;
    $_SESSION['reqfirst']= $name;
    $_SESSION['reqemail']= $email;
    header( 'Location: team_canada.php' ) ;

    }
    ?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles