Results 1 to 16 of 16

Thread: Sessions

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Sessions

    I want to learn some more about sessions. Currently, I know next to nothing. This is in the manual:

    PHP Code:
    <?php
    session_start
    ();

    if (!isset(
    $_SESSION['count'])) {
        
    $_SESSION['count'] = 0;
    } else {
        
    $_SESSION['count']++;
    }

    echo 
    $_SESSION['count'];
    ?>
    Which counts how many times a user has viewed a page. But I want to learn what cpradio is working with. Counting the number of users on a page. Does anyone have any info that could help me?

    What's the life of a session, also? When do they expire?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I found this:
    http://www.phpbuilder.com/snippet/do...snippet&id=180

    I don't know much about timestamps...how could I modify it so that it goes by like 8 minutes instead of 15?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    the default expiration of a session is when the user closes or leaves your site. (that is why i use both cookies and sessions)

    You can set the expiration date in the php.ini file.

    Then the rest is knowing when to delete the row, insert a new one, or update a pre-existing one depending on each user.

    -Matt
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  4. #4

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    So in that example code I found, would I modify this line:

    PHP Code:
    $nu time()-900;

    //to:

    $nu time()-540
    For 8 minutes instead of 15?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    that would be nine minutes 480 would be 8 minutes.


    That is not the expiration of the session but tells the page when to remove a particular person from the database. If they have not been active for 15 minutes it will delete their row in the database or else it will keep it. (this is the hardest to understand)

    When the person first visits your site, they are given a session and placed into a database that records the time, date, and session id (according to the snippet you found).

    Now as they browse through the site every page that has the snippet you found will update their time and date so it shows them as active. If they leave the site or close the browser or just do not do anything for 15 minutes, when the next user visits your page, it will delete the inactive users from the database.

    I hope this makes some sense. I know its confusing but once you get the idea it begins to make more sense as time passes.

    -Matt
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  6. #6

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Also, can I change this:

    PHP Code:
    if ($Session_name == "default") {
        
    session_start();
    }
    else {
        
    session_name("$Session_name");
        
    session_start("$Session_name");

    to this:

    PHP Code:
    session_start();
    $_SESSION['viewers']; 
    Or will it not work that way?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    changing it to that will work fine.
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  8. #8

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by cpradio
    that would be nine minutes 480 would be 8 minutes.


    That is not the expiration of the session but tells the page when to remove a particular person from the database. If they have not been active for 15 minutes it will delete their row in the database or else it will keep it. (this is the hardest to understand)

    When the person first visits your site, they are given a session and placed into a database that records the time, date, and session id (according to the snippet you found).

    Now as they browse through the site every page that has the snippet you found will update their time and date so it shows them as active. If they leave the site or close the browser or just do not do anything for 15 minutes, when the next user visits your page, it will delete the inactive users from the database.

    I hope this makes some sense. I know its confusing but once you get the idea it begins to make more sense as time passes.

    -Matt
    I never said I was good at math Yes, I undestand that's not the expiration date. I just don't want the count to be 15 minutes off. I really don't want it to be 8 minutes off either, but oh well.

    It is starting to make sense. Thanks for the help.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  9. #9

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by cpradio
    changing it to that will work fine.
    Is there anything else I should change to bring it up to PHP 4.2 standards?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  10. #10
    scoutt
    Guest
    ya what is the purpose of this

    session_start();
    $_SESSION['viewers'];

    I seen a couple of peole doing it and it does nothing. it doesn't have a varaiable assigned to it or anything.

  11. #11
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    beats me. I just figured that was the variable he was going to use.


    -Matt
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  12. #12
    scoutt
    Guest
    ehh it was no biggie, I was just curious.

  13. #13

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by scoutt
    ya what is the purpose of this

    session_start();
    $_SESSION['viewers'];

    I seen a couple of peole doing it and it does nothing. it doesn't have a varaiable assigned to it or anything.
    I thought it specifies the session name, as opposed to "session_name("viewers");"

    If it does nothing, could I just remove it and still have it function properly?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  14. #14
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    No, you are right on how you are using it, I think what scoutt was getting at was some people throw in that line for no apparent reason, in your case it would be vital to have it or else you would just have a normal php variable.
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  15. #15
    scoutt
    Guest
    if you took it out it would work just fine, in fact you might not notice a change even if you did, all depends on how you get the variable later in the script.

    just having

    $_SESSION["viewer"];

    does nothing, not even session name.

    but if you go

    $viewer = $_session["viewer"];

    then you could just use $viewer in the script without calling the session all the time. viewer is a variable of the session, not the session name.

  16. #16

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    oh?
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width