session_start() and header()

Discussion in 'PHP' started by kuttappan, May 25, 2010.

  1. #1
    Hi!
    Before, I had this problem with session_start() - Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Users\Administrador\Documents\xampp\htdocs\login.php:1) in C:\Users\Administrador\Documents\xampp\htdocs\login.php on line 3

    I've been surfing a bunch of php forums and they all say that i can't have any blank spaces before <?php tag. I've corrected it and now... nothing happens! It doesn't send the error message, but nothing happens!

    The purpose is that, after a correct login, it opens a new window with the current user's name. but the new page doesn't open.
    If I create a regular html link (with <a>), i manage to open the new page, but the session user name is not sent.

    Can anyone help me, please??!

     
    kuttappan, May 25, 2010 IP
  2. rbu

    rbu Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    So it never gets to the header()?

    Try, if(!empty($_SESSION['nome']))

    Are you sure, $user is being filled so that $_SESSION['nome'] is getting the value?

    Echo all of the values to make sure they are filled.
     
    rbu, May 25, 2010 IP
  3. TrySparta

    TrySparta Well-Known Member

    Messages:
    279
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    170
    #3
    At the end of the script, insert:

    ob_flush ( );

    And the error will magically go away. Hopefully. =)
     
    TrySparta, May 25, 2010 IP
  4. Travis

    Travis Peon

    Messages:
    539
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Travis, May 25, 2010 IP
  5. chtdatweb

    chtdatweb Well-Known Member

    Messages:
    1,473
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    160
    #5
    Hi,

    I'm not a php expert but im sure i experienced the exact same problem. Have you tried putting session_start(); first followed by ob_start();

    i.e.:

    
    <?php
    session_start();
    ob_start();
    
    Code (markup):
     
    chtdatweb, May 26, 2010 IP
  6. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #6
    maybe some extrace ascii chars before <?php
     
    gapz101, May 26, 2010 IP
  7. muhabbatain

    muhabbatain Active Member

    Messages:
    195
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #7
    Sometimes it happens when /tmp folder is full if you see this error on all of your php based sites. Thats what I have experienced
     
    muhabbatain, May 26, 2010 IP
  8. Doxeay

    Doxeay Greenhorn

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #8
    Ah my favourite error (partially) :D

    Well straight to the point!
    Just as chtdatweb said,

    
    <?php
    session_start();
    ob_start();
    
    Code (markup):
    should do the trick! (At least it works for me)
     
    Doxeay, May 26, 2010 IP
  9. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #9
    ^^ it really doesn't solve it, how about all files having errors like that? you should check error like this: [​IMG]

    Uploaded with ImageShack.us
     
    gapz101, May 26, 2010 IP
  10. chtdatweb

    chtdatweb Well-Known Member

    Messages:
    1,473
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    160
    #10
    wow that looks like the old EDIT you used to get with DOS. Anyhow, what editor are you using to save your php file?
     
    chtdatweb, May 27, 2010 IP