FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


I want to make a counter in PHP.





CaBz
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.
rfwrangler
What information are you collectingg from the user? If you are collecting the IP/Host address you could use this to advance your counter.
jeremyyak
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~
hexkid
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;
?>
AOP Web Development
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! Wink
CaBz
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 Smile
manum
dude pls post ur code so tht i can comment on the solution.....
CaBz
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();
Related topics
Need script
php counter
PHP Counter?
PHP Counter
Download Counters
Why is this happening ??
[urgent] unknown error
Flat file-based, MySQL-based counter
anyone know of a good php form processer script
php Counter
Contador de visitas
javascript - another way to do this
Php users counter script
How do I count the number of downloads?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.