Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

[php] redirection and session start

Options
  • 02-01-2003 4:07pm
    #1
    Closed Accounts Posts: 1,325 ✭✭✭


    Hey ppl,

    What i need to do is to start a session and be able to redirect a user on the same php page.

    It appears that in php it requires that session_start() be the first thing on the page AND header() has to be the first thing on the page.

    <?php session_start();

    //other code goes here
    //then try to redirect
    header("Location:somepage.php");
    ?>

    Therefore if i try to do the above i get the warning message --"blah blah .....headers already sent ....blah blah"

    Is there anyway of doing both on the same page????

    Any help or ideas appreciated,
    A


Comments

  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    What's the other code b3t4? I can't check now because my development machine is offline, but header() should work /unless/ something has been output, and session_start() doesn't actually output anything, it simply uses setcookie() internally to set the session id. Can you post the complete code?

    As a workaround, you could output a meta refresh tag:
    <meta http-equiv="refresh" content="0; url=/blah">
    
    adam


  • Closed Accounts Posts: 9,314 ✭✭✭Talliesin


    I don't know about PHP, but certainly in many such HTTP scripting systems you can't send a header if you've sent anything that isn't in a header (that is, if you've sent any text).

    Make sure that this isn't the case in your code.


  • Registered Users Posts: 4,676 ✭✭✭Gavin


    i think there is also an option in php.ini that will automaticly turn on session variables..

    Gav


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Do not echo/print anything to your page before adding the redirect (which is in fact a HTTP header). Header commands (such as Location, Content-Type, etc.) can only be used before the body of your page.


Advertisement