Re: php session tracking and MySQL?



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);
.



Relevant Pages

  • php session tracking and MySQL?
    ... I am a php newbie. ... webpage. ... I know session tracking should be used, but where i put the code? ... Prev by Date: ...
    (comp.lang.php)
  • Re: Multiple Cookies
    ... HugeBob wrote: ... I added the c.setPathcommand thinking that that was the issue. ... I would think that the cookie would be overwritten. ... Does your servlet container perhaps use a cookie for session tracking? ...
    (comp.lang.java.programmer)