...

View Full Version : how to put a PHP hit counter



san_crazy
03-18-2009, 05:10 PM
HI friends,

I have two issues

I want to put a

1) website visit counter in my website
2) A download hits counter in my download page

I haven't used PHP to design my website, only HTML and javascript.

I think it's not possible to have these features using a client side script like javascript, and I think PHP would solve my problem.

but how can I run a PHP script in a HTML page, is it possible?
what would be the best way so that I will need to learn PHP?

Killermud
03-18-2009, 05:22 PM
Well i would add a field in my MYSQL database called views, i would then edit my main page and add something like this :


<?
$sql="SELECT * FROM views";
$result=mysql_query($sql);

$rows=mysql_fetch_array($result);

$views=$rows['views'];

$views2= $views+1;

$sql2="UPDATE views set views='$views2' where views='$views'";
$result2=mysql_query($sql2)

echo $views;

?>

Hope this helps!

EDIT : sorry not INSERT, update :)

steelaz
03-18-2009, 06:20 PM
If you're just starting out with PHP perhaps it would be easier to do counter using simple text file.

Save following code as counter.php



<?php
// Open file for reading
$file = fopen('count.txt', 'r');
// Read file
$data = fread($file, 1024);
// Close file
fclose($file);

// Open file for writing
$file = fopen('count.txt', 'w');
// Write new visitor count increased by 1
fwrite($file, $data+1);
// Close file
fclose($file);

// Show visitor count on the page
echo $data;
?>


Also create new empty file called count.txt, it will hold your visitor count. Place both files to directory where you web page is located. Rename you web page extension from .html to .php and add this code where you like visitor count to appear:


<?php include('counter.php'); ?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum