For Programmers: Free Programming Magazines  


Home > Archive > PHP Programming > May 2004 > Counter without sessions or cookies









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Counter without sessions or cookies
James

2004-05-18, 4:30 am

I have been asked to find out how a basic webpage counter can be created
without sessions or cookies. I am thinking maybe with the use of Javascript
in some way.

Does anyone know the answer or have any ideas?

Here is what I mean by a simple counter (it is two counters, one with a
session and another with a cookie):

<?php
$count++;
setCookie("count", $count);

session_start();
session_register("session_count");

if ($choice) {
$session_count = "";
}
else {
$session_count++;
}
?>

<html><head><title>welcome.php</title></head><body>
Hello visitor, you have visited this page <?php echo $count ?> (cookie)
times.
<p>To continue, <a href="welcome.php">click here</a> <br>

Hello visitor, you have visited this page <?php echo $session_count ?>
(session) times.
<p>To continue, <a href="welcome.php">click here</a> <br>

<form method="post" action="welcome.php?<?=SID?>">
<input type="submit" name="clear" value="Clear the session">
</form>

</body></html>


Tim Van Wassenhove

2004-05-18, 5:30 am

In article <c8ceg8$ggt$1@hercules.btinternet.com>, James wrote:
> I have been asked to find out how a basic webpage counter can be created
> without sessions or cookies.


HTTP is stateless. So it's impossible to find out about a client's
history. That is exactly why cookies/session's are being used.



--
Tim Van Wassenhove <http://home.mysth.be/~timvw/contact.php>
Lars Plessmann

2004-05-18, 3:35 pm

Tim Van Wassenhove wrote:
> In article <c8ceg8$ggt$1@hercules.btinternet.com>, James wrote:
>
>
>
> HTTP is stateless. So it's impossible to find out about a client's
> history. That is exactly why cookies/session's are being used.
>
>
>


save it to a file if you need a common counter!?
if you need a individual counter for each user, you nmeed sessions
(POST/GET) oder cookies.
Chung Leong

2004-05-18, 7:30 pm

"James" <nospamheredude@yahoo.com> wrote in message
news:c8ceg8$ggt$1@hercules.btinternet.com...
> I have been asked to find out how a basic webpage counter can be created
> without sessions or cookies. I am thinking maybe with the use of

Javascript
> in some way.


The only way you can do this without using cookies is through frame.
Basically you'd have a frameset with one frame. When the user goes from page
to page, only the frame is changed. The page with the frame set stay the
same. Using Javascript, you can get/set variables in the frameset document.


R. Rajesh Jeba Anbiah

2004-05-21, 1:30 am

"James" <nospamheredude@yahoo.com> wrote in message news:<c8ceg8$ggt$1@hercules.btinternet.com>...
> I have been asked to find out how a basic webpage counter can be created
> without sessions or cookies. I am thinking maybe with the use of Javascript
> in some way.
>
> Does anyone know the answer or have any ideas?
>
> Here is what I mean by a simple counter (it is two counters, one with a
> session and another with a cookie):
>
> <?php
> $count++;
> setCookie("count", $count);
>
> session_start();
> session_register("session_count");
>
> if ($choice) {
> $session_count = "";
> }
> else {
> $session_count++;
> }
> ?>


<snip>

Use of session_register() is discouraged
<http://in2.php.net/session_register>

With the default settings for sessions, session will be (usually)
non-persistent--which means session will soon get expired, and hence
your counter will get restart from 0 often. So, IMHO, the preferred
way is to use cookies.

Also, if your site is heavy traffic as Google or Yahoo!, cookies
are preferred than sessions as it will consumes system resources.

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com