Re: php session tracking and MySQL?
- From: Steven Stern <sdsternNOSPAMHERE@xxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 30 May 2005 17:00:06 GMT
On 30 May 2005 09:34:29 -0700 (more or less), marslee@xxxxxxxxxxx wrote:
>I am a php newbie. I would like to count how many times a user visit a
>webpage.
>I know session tracking should be used, but where i put the code? Is it
>inside the html that the user visit?
>
>session_start();
> if (!IsSet($page_number))
> $page_number = 1;
> print("You have now visited $page_number");
> print(" of pages <br />");
> $page_number++;
> $session_register("page_number");
>
>Also, i want to record the number of time a user visit a page and store
>it in MySQL. I know how to do it using "form action and submit" way,
>but
>have no clue of doing it with session tracking .
You can't do what you want with session cookes. You'll need to create a
permanent (or at least long duration) cookie for a visitor.
Something like:
// look for an existing cookie for this site
if (isset($_COOKIE['$thispage'])) { // if found, increment the count in
the database
update_db($user_code,$thispage);
}
// set a cookie (or extend the life of the current one
setcookie($aUniqueID,$thispage,time()+60*60*24*30);
.
- References:
- php session tracking and MySQL?
- From: marslee
- php session tracking and MySQL?
- Prev by Date: Re: index page query from PHP newbie
- Next by Date: Detecting PDF files in a folder and sorting them by date
- Previous by thread: php session tracking and MySQL?
- Next by thread: Where can I find Free Web Hosting that supports PHP/MySql?
- Index(es):
Relevant Pages
|