|
-
May 30th, 2002, 05:16 PM
#1
Thread Starter
Stuck in the 80s
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?
-
May 30th, 2002, 05:51 PM
#2
Thread Starter
Stuck in the 80s
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?
-
May 30th, 2002, 06:01 PM
#3
Fanatic Member
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
-
May 30th, 2002, 06:02 PM
#4
Thread Starter
Stuck in the 80s
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?
-
May 30th, 2002, 06:07 PM
#5
Fanatic Member
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
-
May 30th, 2002, 06:07 PM
#6
Thread Starter
Stuck in the 80s
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?
-
May 30th, 2002, 06:09 PM
#7
Fanatic Member
changing it to that will work fine.
-
May 30th, 2002, 06:10 PM
#8
Thread Starter
Stuck in the 80s
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.
-
May 30th, 2002, 06:13 PM
#9
Thread Starter
Stuck in the 80s
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?
-
May 31st, 2002, 07:48 AM
#10
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.
-
May 31st, 2002, 07:51 AM
#11
Fanatic Member
beats me. I just figured that was the variable he was going to use.

-Matt
-
May 31st, 2002, 08:59 AM
#12
ehh it was no biggie, I was just curious.
-
May 31st, 2002, 10:35 AM
#13
Thread Starter
Stuck in the 80s
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?
-
May 31st, 2002, 10:36 AM
#14
Fanatic Member
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.
-
May 31st, 2002, 10:41 AM
#15
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.
-
May 31st, 2002, 10:43 AM
#16
Thread Starter
Stuck in the 80s
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|