SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Location
    Seattle, WA
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm trying to use PHP4 "sessions' on my site, and I'm running into sessions header problems.

    I have a series of customer registration pages that are linked sequentially:
    1. register1.php -- simple page, no form, linked to register2.php
    2. register2.php -- contains form, sends results to register3.php (action="register3.php")
    3. register3.php -- stores results from register2.php and contains another form, sends results to register4.php (action="register4.php")
    4. register4.php -- stores results from register3.php and thanks customer for registering

    When I include a "session_start()" statement on register1.php page, I get a SID on each of the subsequent pages. (I don't have any sessions variables to register until the register3.php page.) However, if I place a "session_start()" statement on any of the other pages, register2,3 or 4, I get an error message. For example, if I place a "session_start()" statement on the register2 page, I get the following error message:

    "Warning: Cannot send session cache limiter - headers already sent (output started at ... / register2.php:7) in ... / register 2.php on line ..."

    If I remove all "session_start()" statements except the one on the register1.php page, I get no error messages. But when I try to add "session_register" statements on the register3.php page, I again get the same error message as above -- except the error message reference is to register3.php.

    I suppose I could put all of my registration process on one long page, rather than breaking it into several steps. But I'd rather not.

    Am I doing something incorrectly with "sessions" or is there a way to work around my problem?

    SeattleDan

  2. #2
    SitePoint Wizard johnn's Avatar
    Join Date
    Mar 2001
    Location
    Southern California, USA
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You must have

    <?php
    session_start();

    At the very begining of the script, not even a single white space before it.

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To further johnn you can have php code above the session_start() just not output.


    PHP Code:
    //This is okay
    ========Top of file===========
    <?
    $var1 
    "something";
    mysql_query("...something... from .....");
    session_start();

    //So is this
    ========Top of file===========
    <?
    session_start();

    //This isn't okay
    ========Top of file===========
    <
    html>
    <
    head>
    </
    head>
    <
    body>
    <?
    session_start();

    //neither is this
    ========Top of file===========
    <?
    $var1 "something";
    print 
    $var1;
    session_start();
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Location
    Seattle, WA
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I appreciate your comments, johnn & freddy, but that's not what's causing the problem. I had placed my session_start() statement before *anything else* and was receiving the error message mentioned.

    Any other ideas on what's going on here?

    SeattleDan

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First make sure to check any included files for whitespace. Normally the only way that error appears is because of output already being sent to the browser. If you are sure about the whitespace then post your code here and we can try to figure it out.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Location
    Seattle, WA
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Freddy,

    I'm not exactly sure of what you mean by "check any included files for whitespace." What should I be looking for?

    SeattleDan

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It would only effect your situation if you use
    include("somefile");

    above your session_start();

    And somefile has some whitespace before the initial <? or you have print or echo in your include file. Can you post the code?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  8. #8
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Location
    Seattle, WA
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Freddy,

    I've been putting the session_start(); statement at the very beginning of my files. So I don't think that's the problem.

    It seems to me that the sequential linking of my pages is what's causing the problem somehow.

    Posting my very lengthy code would take up a huge amount of space here, so I'll have to go back and sanitize my code before posting it. Before I do that, do you (or anyone else) have any other ideas on what's wrong here?

    SeattleDan

  9. #9
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well you can send the code to me via email and I can take a look at it freddy@bereminded.com, otherwise I shall wait till you post it here, I highly doubt the reason is from the sequential linking of your pages, I am beginning to think its probably some stupid little error you have in there, but we can't be sure till we the code.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


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
  •