Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: PHP Beginner Help

  1. #1
    Join Date
    Feb 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PHP Beginner Help

    I am designing a website where I would like values and an image in a form to be transfered from one page to another. I have a very, very loose understanding of how to accomplish this. Can someone help me to polish this process. Thank You.

  2. #2
    Join Date
    Mar 2006
    Location
    UK, warwickshire
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i think this will help you but im new to PHP as well so it might not

    page 1:
    Code:
    <?
    session_start(); 
    $ok = "hello";
    $_SESSION['hello'] = $ok; 
    ?>
    page 2:
    Code:
    <?
    session_start(); 
    echo $_SESSION['hello']; 
    ?>

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    On the second page, you use the function session_start() again. Do you want to restart it? Or is this just for each page to know about the session....?
    Like.... does that mean start a new session or just start it for that particular page.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    No, you need to call session_start() on every page on which you want the session to continue. Because it modifies the headers, you must call it before you output any HTML.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Thanks, Twey.

    Andrelus, not trying to deroute your thread; seems like you've got it started, and I'd think it better to keep discussing this here than start a new one.


    So... sessions last for how long? Do they end when:
    1. the user closes the window?
    2. the time expires?
    3. refresh is hit?
    I'm guessing... probably some are right, others not. More?

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Sessions always expire when their expiry date is hit. As well as that, they can be lost when the user navigates to a page without session_start() called on it (if not using cookies) or when the cookie is deleted.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    cookies and session_start() aren't at all interchangable, though, right? I mean, you could use them together, but you can't just assume the cookie will hold the session or the session vars will hold the data of the cookie, right?

    And... the expiry date.... how does one control this?

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    cookies and session_start() aren't at all interchangable, though, right? I mean, you could use them together, but you can't just assume the cookie will hold the session or the session vars will hold the data of the cookie, right?
    Yes, you could. Making sure that session_start() is called on every page, there should be no reason why every instance of $_COOKIE couldn't simply be swapped for a $_SESSION.
    And... the expiry date.... how does one control this?
    From the manual:
    session.gc_maxlifetime integer

    session.gc_maxlifetime specifies the number of seconds after which data will be seen as 'garbage' and cleaned up.

    Note: If different scripts have different values of session.gc_maxlifetime but share the same place for storing the session data then the script with the minimum value will be cleaning the data. In this case, use this directive together with session.save_path.

    Note: If you are using the default file-based session handler, your filesystem must keep track of access times (atime). Windows FAT does not so you will have to come up with another way to handle garbage collecting your session if you are stuck with a FAT filesystem or any other filesystem where atime tracking is not available. Since PHP 4.2.3 it has used mtime (modified date) instead of atime. So, you won't have problems with filesystems where atime tracking is not available.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The session is automatically stored in the cookie? Does it not work if the cookies are disabled for a certain user?


    And what's the default for sessions, if not set by the php?

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    The session is automatically stored in the cookie?
    The session identifier (SID) is stored in the cookie. All other data is stored server-side.
    Does it not work if the cookies are disabled for a certain user?
    If cookies are not available, it will use GET variables to pass the SID between pages. You can do this manually, or you can set session.use_trans_sid to transparently pass the SID between pages (for example, it will replace all occurrences of <a href="home.php"> with <a href="home.php?PHPSESSID=<?=$SID?>"> and add <input type="hidden" name="PHPSESSID" value="<?=$SID?>"> to all forms).
    And what's the default for sessions, if not set by the php?
    1440.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •