session problem, help appreciated with green!

Discussion in 'PHP' started by klown, Feb 3, 2007.

  1. #1
    I recently downgraded (or upgraded depending on how you look at it) a server from a 50$ a month to a cheap hosting plan (50$ per year) to save money. Anyhow I basically copied and pasted the site over and I seem to have a problem with my session usage which I use in the join section.

    You don't need to say anything about people being able to read my form data, I could care less..

    Anyhow when i first start the session I'm presented with this..

    Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/oregonvd/public_html/html/buy.php:6) in /home/oregonvd/public_html/html/buy.php on line 45
    
    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/oregonvd/public_html/html/buy.php:6) in /home/oregonvd/public_html/html/buy.php on line 45
    PHP:
    the code on my site basically just gets variables from the previous page and places it into session variables (code below). I'm using the session variables because there are multiple confirm pages that I didn't want to post data to every time.

    Here is the code that elicits the warning above

    	session_start();
    	$_SESSION['Sessionname']=$name;
    
    PHP:
     
    klown, Feb 3, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    You can't send any output to the browser before starting the session. No white spaces before the opening <?php tag, and no HTML either. The session_start() has to go on top of everything.
     
    nico_swd, Feb 3, 2007 IP
    klown likes this.
  3. klown

    klown Peon

    Messages:
    2,093
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Works great! amazing what a change in line order can do to code..
     
    klown, Feb 3, 2007 IP