Hello guys,
I need some help to think on a counter-system. I tried some things, but it seems not enough to be OK.
I want to increment the counther when :
-The user come on the website.
I don't want it to increment when :
-The user changes page.
Special things to know about my website :
-I use $_SESSION variables.
-I don't unset those variables when the user leave the website (I don't know how :s)
So, if you could give me some advices, I'll appreciate.
What information are you collectingg from the user? If you are collecting the IP/Host address you could use this to advance your counter.
Try google, there are a poop load of counter scripts that do that an much more.
They can track how long people stay, their browser, ip, operating system and all that hoorah.
Any good php site will have examples.
~Jeremy~
| CaBz wrote: |
| -I use $_SESSION variables. |
So, most of the work is already done.
When you set your session variables, update the counter (database or file). That's assuming you set the session variable once; if you set it more often, check that it is not already set before updating the counter.
| Code: |
<?php
// set session variables
$_SESSION['whatever'] = 42;
// and update counter
update_counter();
?> |
or
| Code: |
<?php
// if session variable is not set, update counter
if (!isset($_SESSION['whatever'])) {
update_counter();
}
// set session variables
$_SESSION['whatever'] = 42;
?> |
hey dude if you have a mysql database to be sure just store it the unique ip address so that you will know who are the unique user's visit on your website
you can use $_SERVER['REMOTE_ADDR'];
and store it to the database if you are interested i can give you some code of it! 
Naahh, I don't want to store IPs. It will be useless and I'm okay with the $_session stuff.
I did it today and it worked correctly.
Thanks for the tip hexkid, and thanks for help everyone 
dude pls post ur code so tht i can comment on the solution.....
Ok, here is it :
| Code: |
In "functions.php" :
$strSQL = "SELECT * FROM Compteur WHERE NoCompteur=1";
$resultat=mysql_query($strSQL);
$ligne=mysql_fetch_array($resultat);
if(!isset($_SESSION['a name liek this']))
{
$compteur = $ligne['Nombre']+1;
mysql_query("UPDATE Compteur SET Nombre = ".$compteur." WHERE NoCompteur=1");
$_SESSION['a name liek this'] = "Ok.";
}
else
$compteur = $ligne['Nombre']; |
| Code: |
In "logout.php" :
session_start();
$_SESSION = array();
$_SESSION['a name liek this'] = 'Ok.';
header("location:../login.php");
exit(); |