Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

[php] redirection and session start

  • 02-01-2003 04: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, Registered Users 2 Posts: 4,660 ✭✭✭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