SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: Session Problem

  1. #1
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    I am testing out some sessions on my home comp (Win98 with PHP4, MySQL, and Apache) I put in the following code:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    
    <html>
    <head><title>New User</title></head>
    <body>
    <?php
    session_register ("count");
    $count++;
    ?>
    
    Hello visitor, you have seen this page <? echo $count; ?> times.<p>
    
    <php?
    # the <?=SID?> is necessary to preserve the session id
    # in the case that the user has disabled cookies
    ?>
    
    To continue, <A HREF="nextpage.php?<?=SID?>">click here</A>
         
    
    </body>
    </html>
    And I get this error:
    Warning: Cannot send session cookie - headers already sent by (output started at c:\phpdev\www\work\session.php:6) in
    c:\phpdev\www\work\session.php on line 7

    Warning: Cannot send session cache limiter - headers already sent by (output started at c:\phpdev\www\work\session.php:6)
    in c:\phpdev\www\work\session.php on line 7

    Warning: open(/tmp/sess_4723d19e4c4f908f32832f38655a32e3, O_RDWR) failed: m (2) in
    c:\phpdev\www\work\session.php on line 7
    Hello visitor, you have seen this page 1 times.

    To continue, click here
    Warning: open(/tmp/sess_4723d19e4c4f908f32832f38655a32e3, O_RDWR) failed: m (2) in Unknown on line 0

    Warning: Failed to write session data. Please check that the current setting of session.save_path is correct (/tmp) in Unknown
    on line 0

    I went into the php.ini file and changed the save.path to (sessions)
    Any suggestions??
    Thanks,

  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)
    A couple of things: First you need to use
    session_start();
    to initiate the session Also in the to continue line it should read
    To continue, <A HREF="nextpage.php?SID=<? print $SID; ?>">click here</A>

    Oh yeah and on the following line
    <php?
    # the <?=SID?> is necessary to preserve the session id
    # in the case that the user has disabled cookies
    ?>
    should be
    <?php
    # the <?=SID?> is necessary to preserve the session id
    # in the case that the user has disabled cookies
    ?>

    <html>
    <head><title>New User</title></head>
    <body>
    <?php
    session_register ("count");
    $count++;
    ?>

    Hello visitor, you have seen this page <? echo $count; ?> times.<p>

    <php?
    # the <?=SID?> is necessary to preserve the session id
    # in the case that the user has disabled cookies
    ?>

    To continue, <A HREF="nextpage.php?<?=SID?>">click here</A>


    </body>
    </html>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    Ok did all of that.... But I still get this error
    "Warning: open(/tmp/sess_269df0eddef0f856fef50c436ef577de, O_RDWR) failed: m (2) in c:\phpdev\www\work\session.php on line 2
    Hello visitor, you have seen this page 1 times.
    is necessary to preserve the session id # in the case that the user has disabled cookies ?> To continue, click here
    Warning: open(/tmp/sess_269df0eddef0f856fef50c436ef577de, O_RDWR) failed: m (2) in Unknown on line 0

    Warning: Failed to write session data. Please check that the current setting of session.save_path is correct (/tmp) in Unknown on line 0"

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sounds like a problem in your php.ini file. I have never had much luck with PHP4 built-in session management and normally resort to using the PHPLIB for session management. You should have a look at it.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    You can use the PHPLib with PHP4?
    From this site: http://phplib.netuse.de/
    ?

  6. #6
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The problem is definitely in your php.ini file. You need to set a directory to contain your temporary session files. The setting is clearly marked in php.ini, and is set to "/tmp" by default (which I assume doesn't work on your computer). You should probably set it to something like "C:\WINDOWS\TEMP".
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference


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
  •