By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,408 Members | 1,595 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,408 IT Pros & Developers. It's quick & easy.

php session tracking and MySQL?

P: n/a
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 .

Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On 30 May 2005 09:34:29 -0700 (more or less), ma*****@hotmail.com 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) ;
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.