SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    Knowledge is key 2 progression Tryst's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cookie and Session Headers

    At the moment my script is throwing a 'Headers Already Sent..." message when I attempt to set a cookie, but before this I start a session.

    Is it this that throws the error message? Or is it possible to start a session, and then later on to set a cookie?

    Thanks

    Tryst

  2. #2
    SitePoint Enthusiast mullen's Avatar
    Join Date
    Jul 2004
    Location
    Durham, UK
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem is probably due to you having output something to the screen before trying to set the cookie. Check you haven't ECHOed anything prior to setting the cookie. Also, double check to ensure there are no blank lines before your opening <?php tag (as this is output to the browser too).

  3. #3
    Knowledge is key 2 progression Tryst's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But can you send a session header, and then later on in the script send a cookie header?

    Thanks

    Tryst

  4. #4
    Knowledge is key 2 progression Tryst's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So does the blank line in the following piece of code constitute as being as 'output'?

    PHP Code:
    <?php
    session_start
    ();
    /* load in main configuration file for application */
    require_once('..\application.php');
    require_once(
    'user.php');

    /* Checks to see whether the HTML <form> has been posted */
    if(isset($_POST['login_submit'])) {
    $user = new member_class();
    $user->check_login($_POST['username'], $_POST['password'], $_POST['remember']);
    }
    // End POST
    In the above code, the 'check_login() function is called from the user.php file, where the cookie is called.

    Thanks

    Tryst

  5. #5
    <? james('rules'); ?>
    Join Date
    Jun 2004
    Location
    Wales, UK
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, a space, text, anything remotely outtpued is counted as "output":
    PHP Code:
     <?php

    session_start
    ();

    ?>
    This would send the error because of the space before the <?php etc..

    Regards,

    James


    EDIT - Sorry didnt read your question properly, no that space wouldn't cause the error because it isnt actually output.
    If knowledge is power - Why isn't our army librarians?!
    Statistics show that 63% of all statistics are fake.
    When i was little i broke my neck, and i havent looked back since .
    I completed the internet in 1 week. The end boss was pretty easy though .

  6. #6
    <? james('rules'); ?>
    Join Date
    Jun 2004
    Location
    Wales, UK
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Check that your require'd files dont have output as that would cause an error aswell..
    Off Topic:


    Where in wales do you live btw?
    If knowledge is power - Why isn't our army librarians?!
    Statistics show that 63% of all statistics are fake.
    When i was little i broke my neck, and i havent looked back since .
    I completed the internet in 1 week. The end boss was pretty easy though .

  7. #7
    Knowledge is key 2 progression Tryst's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So my blank line within my <PHP> tags is ok? But any ouput before the <PHP> tag would be the possible cause for this error?

    Tryst

  8. #8
    <? james('rules'); ?>
    Join Date
    Jun 2004
    Location
    Wales, UK
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, output in your application.php or user.php, or a simple space before a start of line of code would cause the error but the line in your code wouldn't.

    Regards,

    James
    If knowledge is power - Why isn't our army librarians?!
    Statistics show that 63% of all statistics are fake.
    When i was little i broke my neck, and i havent looked back since .
    I completed the internet in 1 week. The end boss was pretty easy though .

  9. #9
    Knowledge is key 2 progression Tryst's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I found the error - you were right, I was output from with in my required/included files.

    Off topic

    1337-Dev - I live in Cardiff, well, near Cardiff in a place called Pontypridd. Why are you from the 'Valleys'?
    Thanks

    Tryst

  10. #10
    <? james('rules'); ?>
    Join Date
    Jun 2004
    Location
    Wales, UK
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad to have helped .

    Im from llantrisant which is about 5 - 10 miles away from ponty awesome.
    If knowledge is power - Why isn't our army librarians?!
    Statistics show that 63% of all statistics are fake.
    When i was little i broke my neck, and i havent looked back since .
    I completed the internet in 1 week. The end boss was pretty easy though .

  11. #11
    SitePoint Enthusiast mullen's Avatar
    Join Date
    Jul 2004
    Location
    Durham, UK
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's correct... within PHP tags, you can have as many blank lines as you like, but a single space or carriage return before the opening tag will prevent you from being able to send any headers (including setting cookies).

    Edit: Hmmm, posts crossed

  12. #12
    <? james('rules'); ?>
    Join Date
    Jun 2004
    Location
    Wales, UK
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mullen
    Edit: Hmmm, posts crossed
    I hate it when that happens, make things so confusing..but yeh i suggested the includes etc and its all sorted .
    If knowledge is power - Why isn't our army librarians?!
    Statistics show that 63% of all statistics are fake.
    When i was little i broke my neck, and i havent looked back since .
    I completed the internet in 1 week. The end boss was pretty easy though .

  13. #13
    Knowledge is key 2 progression Tryst's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Haha - evening better, I am from Church Village/Tonteg Which is even closer!

    My sister lives in Beddua (is that how you spell it?) :-s

    Tryst

  14. #14
    <? james('rules'); ?>
    Join Date
    Jun 2004
    Location
    Wales, UK
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Beddau, awesome whats her name? i know basically everyone in beddau

    Interesting info for you - my nan is from church village, lol..
    If knowledge is power - Why isn't our army librarians?!
    Statistics show that 63% of all statistics are fake.
    When i was little i broke my neck, and i havent looked back since .
    I completed the internet in 1 week. The end boss was pretty easy though .

  15. #15
    Knowledge is key 2 progression Tryst's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Her name is Heulwen.

    She never went to Bryn school, she, well we, went to Cardinal Newman school in Trefforest.

    So are you a student, or do you work with PHP?

    Tryst


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
  •