SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: PHP Sessions

  1. #1
    Free your mind Toly's Avatar
    Join Date
    Sep 2001
    Location
    Panama
    Posts
    2,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Sessions

    Hello,


    I'm trying to use PHP sessions to store users name and passwords after they have submitted them on a login form but i get the following error:

    Warning: Cannot send session cookie - headers already sent by (output started at /home/username/phpincludes/db.php:23) in /home/username/phpincludes/login.php on line 8

    Warning: Cannot send session cache limiter - headers already sent (output started at /home/username/phpincludes/db.php:23) in /home/username/phpincludes/login.php on line 8

    phpincludes is the folder i use to store all my include files, db.php is an include file which only contains a function to connect to the database and login.php is the file that starts the sessions.

    Any help would be very appreciated, thanks.


    Toly
    Community Guidelines | Community FAQ

    "He that is kind is free, though he is a slave;
    he that is evil is a slave, though he be a king." - St. Augustine

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When using session_start() there can be no whitespace or html output or echo statements above the session_start() including whitespace or html before th opening <?php tag this goes for the inlcuded files also if they are included before the session_start() call is made.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Addict zoordaan's Avatar
    Join Date
    Feb 2001
    Location
    NYC/Texas
    Posts
    348
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I suspect that there's an error in the db.php script. If that script causes php to output an error message then you'll get an error message that headers have already been sent and the session info can't be set. There should be absolutely nothing before the start of a session, no whitespace, no html etc.

  4. #4
    Free your mind Toly's Avatar
    Join Date
    Sep 2001
    Location
    Panama
    Posts
    2,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks to both for your quick replies.

    I think i solved the problem. As you said i didn't leave any white spaces and also i put the session_start() before my include file db.php and everything seems to be working now.

    Thanks a lot


    Toly
    Community Guidelines | Community FAQ

    "He that is kind is free, though he is a slave;
    he that is evil is a slave, though he be a king." - St. Augustine


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
  •