Forum Moderators: coopster
Then I took that idea further. What if there were two counters? One would count the general number of visits like if you visited, closed your browser and came back Thursday the session counter would be set to 2. Now the page counter merely counts every page you browser regardless of how often you close the browser.
I use frames on my site (no trash talk unless you can offer an actual live example to replace my setup) and so I could just use the session counter to be set by the frameset. Next each page would have the page counter.
Here is the current code (thanks to mcibor and ironik)...
<?php
if(!isset($_COOKIE["pages"]))
{
setcookie("pages", "1", time() + 2592000, "/"); //first appearance
} else {
$cookie = (int)$_COOKIE["pages"] + 1; //increase the transformed to (int) cookie
setcookie("pages", $cookie, time()+2592000, "/"); //set the increased cookie
}?>
Now lets just assume the frameset counter is named "sessions". How do I use PHP to ...
sessions * pages
I also want to say "If this number is equal to or greater {}.
<?php
$a = 5;
$b = 4;
if($a >= $b) echo "a = $a is greater than b = $b";?>
To do the session counter is a bit trickier. I suppose you want to check just one user, not the whole lot. Then you'll need or two cookies or a cookie and a session. With two cookies: temp and session_count
<?php
if(!isset($_COOKIE["temp"])) {
setcookie("temp", "1", 0, "/"); //start of the session, time=0 means the cookie is valid until the browser window closes
if(!isset($_COOKIE["session_count")) setcookie("session_count", "1", time()+2592000, "/");//first appearance
else setcookie("session_count", (int)$_COOKIE["session_count] + 1, time()+2592000, "/");//increase number of session visits
}//no else, because it's a session cookie, not a every page visit counter
?>
Best regards
Michal Cibor
Thanks for appreciation!
If I guessed right you rock! :-D If not you still rock for helping me out ... did I read the code correctly?
Ok thats before I tried the script out... I have a couple errors here...
Parse error: parse error, unexpected ')', expecting ']' in sessions.php on line 4
Then I changed...
if(!isset($_COOKIE["session_count"))
to...
if(!isset($_COOKIE["session_count"])
and got ...
Parse error: parse error, unexpected T_STRING in sessions.php on line 4
I then added another )...
if(!isset($_COOKIE["session_count"]))
but then recieved this message...
Parse error: parse error, unexpected $ in sessions.php on line 7
That's my attempt at a little debugging. A lot of thanks for your help (and a little hope for some continued for debugging!) :-D
John
<?php
if(!isset($_COOKIE["temp"]))
{
setcookie("temp", "1", 0, "/"); //start of the session, time=0 means the cookie is valid until the browser window closes
if(!isset($_COOKIE["session_count"])) setcookie("session_count", "1", time()+2592000, "/");//first appearance
else setcookie("session_count", (int)$_COOKIE["session_count"] + 1, time()+2592000, "/");//increase number of session visits
}//no else, because it's a session cookie, not a every page visit counter
?>
And yes, you understood the code perfectly. Sorry for the mistakes
Michal Cibor