SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    login script problem

    Hi,

    I have a login script........if the user provides correct login info i creat a session and redirect with the following code:

    Code PHP:
    $_SESSION['first_name'] == $first_name;
    	      	    header("location:home.php");

    This gives me a headers already sent error.....it says output started on this line:

    Code PHP:
    $_SESSION['first_name'] == $first_name;

    How do i fix this?! I need to set the session up and then i need to redirect. The only solution ive come accross is output buffering but it seems clumsy.

    Any suggestions?

  2. #2
    SitePoint Enthusiast jcarouth's Avatar
    Join Date
    Sep 2006
    Location
    College Station, TX
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i agree. output buffering is a hack, not a solution.

    you need to post more of your code, especially for this particular problem.

    any include files that have a closing ?> and possibly a newline or other whitespace after the closing ?> that will cause this error.

  3. #3
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, thanks for the reply

    No its not a whitespace issue......if it take this line out:

    PHP Code:
    $_SESSION['first_name'] == $first_name
    from the two lines above the redirect works fine....the session counts as output....so how the hell do i get around it?!?!

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,805
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    Should that be
    PHP Code:
    $_SESSION['first_name'] = $first_name
    ....
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #5
    SitePoint Evangelist AlienDev's Avatar
    Join Date
    Feb 2007
    Location
    UK
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unless the problem is what spikeZ said (in which case, wouldn't you see a nice big error...?) and you didn't just type it in wrong to SP, only other way of redirecting after output has started is through meta redirects, or JS.
    Me on StackOverflow | Blog & personal website.

    I mostly use: PHP, Java, JavaScript, Android.

  6. #6
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh dear....so sorry its been a long day....i was was a combo or spikes post and
    forgetting the session_start()....truly schoolboy errors!

    Thanks

  7. #7
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,805
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    very long day then!!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


Bookmarks

Posting Permissions

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