Results 1 to 10 of 10
  1. #1
    Join Date
    Jan 2007
    Location
    Wales
    Posts
    2,432
    Tokens
    141

    Latest Awards:

    Default [PHP] Help Please?

    Hey, basically I have got a simple login script, but if I put any html above the PHP or I include the login page on another page, it comes up with the following error and it won't log me in:

    Warning
    : Cannot modify header information - headers already sent by (output started at IREMOVEDTHIS/index.php:12) in IREMOVEDTHIS/login.php on line 28

    Warning: Cannot modify header information - headers already sent by (output started at IREMOVEDTHIS/index.php:12) in IREMOVEDTHIS/login.php on line 29

    Any idea how I can stop this? +Rep to any help

    Thanks,
    Vince.
    Free Online Games And Videos:
    http://www.vincesgames.com



  2. #2
    Join Date
    Jun 2005
    Posts
    4,795
    Tokens
    0

    Latest Awards:

    Default

    All uses of header in php must be before anything is output to the client.

  3. #3
    Join Date
    Jan 2007
    Location
    Wales
    Posts
    2,432
    Tokens
    141

    Latest Awards:

    Default

    Thanks, but the lines that are causing the error are:

    PHP Code:
    setcookie("id"$user[id],time()+(60*60*24*5), "/""");
    setcookie("pass"$user[password],time()+(60*60*24*5), "/"""); 
    I don't see how I can put this before where it is, because it happens when the user is logged in and needs to be where it is, is there any way I can change it so it doesn't cause that error?
    Free Online Games And Videos:
    http://www.vincesgames.com



  4. #4
    Join Date
    Jun 2005
    Posts
    4,795
    Tokens
    0

    Latest Awards:

    Default

    It sets cookies, which requires headers being sent. Just put whatever html you want after the PHP. I can't really help futher unless you post the whole file as I don't see why it should be a problem to add your HTML after the PHP.

  5. #5
    Join Date
    Jan 2007
    Location
    Wales
    Posts
    2,432
    Tokens
    141

    Latest Awards:

    Default

    Quote Originally Posted by Tomm View Post
    It sets cookies, which requires headers being sent. Just put whatever html you want after the PHP. I can't really help futher unless you post the whole file as I don't see why it should be a problem to add your HTML after the PHP.
    Okay thanks, I really appreciate your help In attempt to resolve this, I just put everything on the index file in PHP echo so that there's no HTML above any PHP, but now I can't get it to include files by doing <? include 'login.php'; ?> because it's all in echo ""; arghhh, is there any way i can get it to include a file when it's inside an echo :S
    Free Online Games And Videos:
    http://www.vincesgames.com



  6. #6
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    Quote Originally Posted by ThisNameWillDo! View Post
    Okay thanks, I really appreciate your help In attempt to resolve this, I just put everything on the index file in PHP echo so that there's no HTML above any PHP, but now I can't get it to include files by doing <? include 'login.php'; ?> because it's all in echo ""; arghhh, is there any way i can get it to include a file when it's inside an echo :S
    Why can't you just end the echo, include the file and then re-start it?..

  7. #7
    Join Date
    Jan 2007
    Location
    Wales
    Posts
    2,432
    Tokens
    141

    Latest Awards:

    Default

    Agh thanks but it still comes up with that damn headers error, is there no way around this? :S
    Free Online Games And Videos:
    http://www.vincesgames.com



  8. #8
    Join Date
    Jun 2005
    Posts
    4,795
    Tokens
    0

    Latest Awards:

    Default

    As I've said before, without the full code it is going to be difficult to help you.

  9. #9
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    Quote Originally Posted by ThisNameWillDo! View Post
    Agh thanks but it still comes up with that damn headers error, is there no way around this? :S
    Well if you listen to what people have said, you would understand that you cant have any function placed after any data is sent to the browser (for example: HTML)

    So setcookie, header, functions arent going to work and are going to throw a error (or a paddy)

    So inorder to by pass this, any data you wish to send needs to be after the function is initiated.

    Code #1
    PHP Code:
    <?php
    setcookie
    ("id"$user[id],time()+(60*60*24*5), "/""");
    setcookie("pass"$user[password],time()+(60*60*24*5), "/""");

    echo 
    'Cookies set';

    ?>
    Code #2
    PHP Code:
    <?php
    echo 'Setting cookies';

    setcookie("id"$user[id],time()+(60*60*24*5), "/""");
    setcookie("pass"$user[password],time()+(60*60*24*5), "/""");  

    ?>
    Code #3
    PHP Code:
    <?php
    include 'loads_of_html.html';

    setcookie("id"$user[id],time()+(60*60*24*5), "/""");
    setcookie("pass"$user[password],time()+(60*60*24*5), "/""");  

    echo 
    'Cookies set';
    ?>
    Just so we're on the right lines, which ones do you think will work? (Without testing it)
    Hi, names James. I am a web developer.

  10. #10
    Join Date
    Jan 2007
    Location
    Wales
    Posts
    2,432
    Tokens
    141

    Latest Awards:

    Default

    I've sorted the problem now, thank you all for your help! I'll +rep you all if I can.
    Free Online Games And Videos:
    http://www.vincesgames.com



Posting Permissions

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