Add to Google

Visitors Counter - With PHP (no MySQL needed!)

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > PHP Programming

Visitors Counter - With PHP (no MySQL needed!)

FaLgoR
Well, here we will make an hit counterusing php and an *.txt file. This script is so simple, but very usefull. First, le'ts make an file called counter.php, with the following codes inside:

CODE

<?
$file = 'counter.txt'; // this is the file where the number of visitors will be written
$fopen = fopen("$file", "r"); // open the text file
$count = fread($fopen, 1024); // read the text file
fclose($fp); // close the text file
$count = $count + 1; // add one more hit
echo "$count"; // print the number
$fopen = fopen("counter.txt", "w"); // open the file again
fwrite($fp, $count); // write the new number
fclose($fp); // close the file
?>


That's all, it must e working fine (I'm using it :]). To show the number of hits on your site and add the counter, just insert this line where the counter will be:
CODE

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

It will show the visitors AND add the counter.

Problems, just post ;D


----------------------------- Edited -------------------------------------
I forgot, youll have to make an blank file called counter.txt. Have fun =P

 

 

 


Reply

no9t9
I also used a script like this for counting but I found that it wasn't really enough information. It would be more accurate to count per session using cookies or something. I did a counter with cookies but then I wanted even more information like referrer, time spent, etc. I kind of gave up on this and just joined statcounter.com. They do it for you and you don't have to waste time making the program.

the only problem with statcounter is that it only shows the last 100 page loads for free accounts. But, I find the information very useful.

O, thanks for putting up the code. It actually is a good counter if you aren't worried about analyzing traffic. Many people will undoubtedly find it useful.

Reply

leiaah
HOW ABOUT THIS?


------------------TO INCREMENT HITS BY 1------------------

<?php
$filename= "hits.txt" ;
$fd = fopen ($filename , "r") or die ("PHP script cant open $filename") ;
$fstring = fread ($fd , filesize ($filename)) ;
echo "$fstring" ;
fclose($fd) ;

$fd = fopen ($filename , "w") or die ("PHP script cant open $filename") ;
$fcounted = $fstring + 1 ;
$fout= fwrite ($fd , $fcounted ) ;
fclose($fd) ;
?>

OR

<?php
$filename = "hits.txt" ;

$file = file($filename);
$file = array_unique($file);
$hits = count($file);
echo $hits;

$fd = fopen ($filename , "r");
$fstring = fread ($fd , filesize ($filename)) ;
fclose($fd) ;
$fd = fopen ($filename , "w");
$fcounted = $fstring."\n".getenv("REMOTE_ADDR");
$fout= fwrite ($fd , $fcounted );
fclose($fd);
?>


HOPE THIS HELPS.

 

 

 


Reply

FaLgoR
QUOTE(no9t9 @ Feb 16 2005, 10:53 PM)
I also used a script like this for counting but I found that it wasn't really enough information.  It would be more accurate to count per session using cookies or something.  I did a counter with cookies but then I wanted even more information like referrer, time spent, etc.  I kind of gave up on this and just joined statcounter.com.  They do it for you and you don't have to waste time making the program. 

the only problem with statcounter is that it only shows the last 100 page loads for free accounts.  But, I find the information very useful.

O, thanks for putting up the code. It actually is a good counter if you aren't worried about analyzing traffic.  Many people will undoubtedly find it useful.
*



I am not showing an page tracker, this is just a hit counter! =/

Reply

alexia
Nice Code
You can Make DB (FlatFile) on your host with 755 PM Access For Rewrite on
and then make on php page and when user view this page the page input the 1 to file
for example if in file is 1
the php page get File data and add one to it and rewrite to file
thats all
u can find many CMs for this Post in google or hotscripts or Script Websites

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

Recent Queries:-
  1. visitor php no mysql - 1733.40 hr back. (1)
  2. visitors php no mysql - 1733.53 hr back. (1)
Similar Topics

Keywords : visitors counter php mysql needed

  1. Gallery Help Needed - errors help help (10)
  2. Mysql Won't Update - (5)
    Ok, so I'm making some arcade administration software so I don't have to add games the hard
    way, well anyway, one of the features I have is that on the homepage is a featured author and as
    such I just have it so it updates one line in the mySQL. Well, the page with the form passes on the
    varibles fine and the updating page recieves them because I echoed everything, then I build the
    query and I even echo the query and it comes out exactly how I want it to, but for some reason, the
    database itself won't update even though all the varibles are there. Here's...
  3. Can You Add Images Into A Mysql Database? - Using Php? (21)
    I'm learning php in class right now, but I'm still not that good at it, what I'm
    wondering is when I write the php so that it can connect with a database, can I at the same time
    have it that it is able to display back images that I choose. Like, I want a search feature, where
    you can search for a keyword, and it will bring back a list of all the possible entries with that
    keyword, but each of these entries will have a photo associated with it. Now, do I put these image
    files directly into the database, or do I write the code to link them from my files to th...
  4. Subquery In Mysql - (5)
    Is there anyway to make subqueries work in MySQL? I'm pretty certain someone out there knows
    how. /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> Can anyone help?
    CODE Select * from ITEMS where ID="Select Max(ID) from ORDERS"; This works for MSAccess and
    SQL Server but why not in MySQL? I'll be writing some reports and I've shifted database
    from MSAccess to MySQL. Help! Thanks....
  5. Increment A Mysql Column - how to increment a MySQL column one unit (7)
    Hi, I have a column in a MySQL table which contains a counter of the views of the object described
    by this table. I would like to increment this value by one everytime the object is viewed. Obviously
    came into my mind the possibility of retrieving the value of this field, store it in a variable
    increment this value by one and perform an UPDATE query again with this new value. My question is if
    there is a MySQL option to update the field with its actual value plus an unit increment. I hope you
    understand the issue....
  6. Html Form! - Using MySQL?! (4)
    Hey, I need your help again! I need some good working tutorial how I can update my SQL through HTML
    form. I did use some tutorials online found with the help of google; but they do not work properly;
    I mean there are still small mistakes. I need to have a good tutorial to follow. It should be
    based on security and more things. It has to be done in proper way......
  7. Create Table - Mysql Code - Help - (1)
    I need your feedback about setting the database issues. Please, review them and correct some entries
    in the code if they got some mistakes. This is the code itself: SQL CREATE TABLE `news` (
    `id` int(250) NOT NULL auto_increment, `title` varchar(255) NOT NULL default '',
    `text` text NOT NULL, `author` varchar(255) NOT NULL default '', `valid` varchar(255)
    NOT NULL default '', `date` varchar(255) NOT NULL default '', PRIMARY KEY
    (`id`) ) ENGINE = MyISAM ; ...
  8. Tools Needed! - PHP & MySQL (9)
    Hello, everyone! I need some tools for those two things to test PHP scripts coming together with
    database on my laptop, instead checking them on a web-server which takes time....
  9. Mysql Error - (3)
    ok i need some more help from the wonderful coders here at Trap. I'm almost done with my CMS
    script, but i'm having a problem with the installer.php file, when it trys to inseret the user
    data into the database i keep getting the following error: CODE mySQL Error: You have an error
    in your SQL syntax; check the manual that corresponds to your MySQL server version for the right
    syntax to use near ';INSERT INTO `members` (`id`, `name`, `username`, `password`, `email`,
    `title`) ' at line 1 the code that is being excuted by the php file is this: C...
  10. Tutorial Needed?! - PHP+Ajax (11)
    I need many tutorials based on PHP programming language and AJAX technology. Those tutorials might
    be of any kind. Please post only the links to the trusted and working tutorials!...
  11. Best Php And Mysql Editor For Noobs - anyone any php or mysql editor that is good for noob (6)
    hi there guys, from my previous posting, i am a noob in php and mysql programming. I want to know
    if there are any php and mysql editors which are best for me as a noob. i appreciate your kindness
    ...
  12. Php And Mysql Programming - anyone knows a code for mysql and php (2)
    hi everyone! I am making a program using php and mysql...I am a noob on this so i need your help
    guys...I want to make a simple program that will some values and then store them on a database and
    then retrieve them...uhmm let me give an example out put of what i need. This is the example say..:
    Enter First Name: Enter Last Name:
    Enter Age: Enter Address: ..those are the
    data needed for input values...my question now is how can I make a database whi...
  13. Creating Profiles In Php/mysql ? - (7)
    i've started to learn php..im familiar to basics of php and mysql now.Now for example i want
    that some user can register to my website , and after that he can Login and log out , and he can see
    his profile.is there any tutorial about this ? or any helping url .. or any helping answer please
    /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />...
  14. Creatting A Playlist Through Php - script help needed (5)
    Hi I am trying to make a script so that i can insert songs into a playlist, but i need a script in
    which it opens the playlist file and removes the closing tag at the end, so before i can add more
    entrys. e.g CODE Location 5 Location 4 Location 3 Location 2 Location 1 But to
    add more entrys i would have to get rid of the atx, then use the fputs to place the new entry into
    the file. code tags added Topic title modified. ...
  15. Admin Page - Tutorial Needed? (4)
    I need to look at a nice tutorial how do you create an admin access page with many functions as many
    as possible....
  16. Php Code Needed Iii - (10)
    Hello, everyone. I need your help again! Who might create the PHP code, the picture is above
    this text. Basically, I want when the user fill in all the information in this form, it
    automatically was sent to my email. And, then, the dialog box appears or on the same window, it was
    said that your request has been sent. Moreover, if the user did not fill the entire information,
    the dialog box appears stating that you did not fill some field. Thanks, for help. You always do
    that....
  17. Best Sites For Learning Php-mysql - (4)
    Hi I was reminded of this earlier by a post in a topic, meant to post it but forgot and the topic on
    php books reminded me. Well anyway there is tyhschools for learning php (unless someone else knows
    a better 1) but I wan't to know what is the best site for using php with mysql (using
    phpmyadmin) also whats the difference between postgresql and mysql? though I must admit the
    postgresql version of phpmyadmin whatever it's called looks better (visually)!...
  18. Php Code Needed - Working Together? (5)
    Hello, everyone. I need your help again. This forum is quite good for it. Well, I need create a
    registration form for my web-site using PHP and SQL. The information it should contain: 1) User
    Name 2) First Name 3) Last Name 4) Password 5) e-mail Address 6) Security Image: that images helps
    to protect a random registration, for instance, 56+2=where user have to type an answer in order to
    finish registration. That's all for today. Anymore things, I will post another post over here.
    ...
  19. Php Code - Needed?! (15)
    Well, I am a novice in PHP programming, so there is a script which I wanna get: 1. You go the
    web-site 2. On the main screen, there is a some kind of field windows, the one you get used to type
    in, when you go to google, for instance. 3. He or she types her email address and it's going to
    be saved in my SQL database. 4. That's it. Help me if you can....
  20. Looking For Command Line Based Sql Modification - Program Needed For SQL? (1)
    How I use Windows command prompt client and do modifications to my SQL database. If yes, please
    write the commads I should know for that. If no, please get me the software with which I can do it.
    Topic title modified. Proper English is always required when posting in our forum. ...
  21. Slaed Cms - Book Needed!!! (2)
    Hello, everyone! I need some tutorial for Slaed Engine for any version you might find. I wanna learn
    how you can make modules or blocks for this CMS. Especially, library functions and other things that
    will make the web-site works like virtual library....
  22. Php + Mysql Question! - While inserting data into MySQL, how can I know if the data I'm in (4)
    Basically, I want to know if the Data I'm inserting through a Form is already there or not. Sort
    of a Username registration page. I have this, but it doesn't appear to work... CODE
    $result = mysql_query("SELECT * FROM users WHERE username='$username'"); if($result == 1)
        {     echo ' ERROR! The username you have chosen already exists!';     } ...
  23. [php/mysql]id Trouble [resolved] - (3)
    session_start(); include "database.php"; if (!$_SESSION || $_SESSION { // User not logged in,
    redirect to login page Header("Location: main.php"); } $result = mysql_query("select * from users
    order by id asc"); while($r=mysql_fetch_array($result)) { $username=$r ; $info=$r ; $msn=$r ;
    $email=$r ; $id=$r ; $password=$r ; $userlevel=$r ; echo " user ID
    User Level Username
    Password Email: ...
  24. [mysql/php]need Som Basic Help - (13)
    QUOTE session_start(); include "database.php"; include "edit.inc.php"; if (!$_SESSION ) { //
    User not logged in, redirect to login page Header("Location: main.php"); } if(isset($_POST )){
    $email = $_POST ; $msn = $_POST ; $info = $_POST ; $updateemail = "UPDATE users SET email =
    '$email', msn = '$msn', info = '$info' WHERE username =
    '$username'"; mysql_query($updateemail) or die("culd not edit your info");
    echo "info updated"; } // Display logout link echo " Click here to go back to info page! "; echo
    "$email"; e...
  25. Php Search Engine Script For Mysql Database - (11)
    A search engine is provided to facilitate the user with undemanding and clear-cut search options.
    The search facility includes simple search, search by title, search by word/phrase, ect… Thus, the
    user is at a safe distance from the risk of selecting files/folders ambiguously. In addition, a
    history of recent searches can be preserved for future perusal. Now
    day’s visitors have a large option for his needs on internet and so visitors are not vesting their
    time by following the dead links on your site. So a search engine is essential for your...
  26. [mysql]get Id Of Loged In User? - (7)
    how to get the id number of the loged in user? my db is id. username. password. i have tryed a
    few things.. but i never seem to get it right /ohmy.gif" style="vertical-align:middle" emoid=":o"
    border="0" alt="ohmy.gif" />...
  27. Problem On Mysql "order By" - (5)
    Can someone please help...? I have a problem with using "ORDER BY" in mysql... CODE SELECT *
    FROM `foo` WHERE b='abc' ORDER BY 'number' ASC i want to sort the table out by
    the value in "number" which is a number.. but it came out to be sort by like this way...
    1->10->2->20 it only sort out the front digit.... but what i want is it will sort by how great the
    number is like this... 1->2->3........->10....->20 sorry my english isn't good enough...to
    describe my problem properly... hope you can understand and help me on this.....thx...
  28. Some Mysql Basics - (4)
    Greetings this tutorial will show you some mysql basics.. MySQL is one of the most used database. a
    simple config file at the top add this CODE ?> after $username= "root"; // Username that
    has access to your database $password= ""; //Password that has access to your database $host =
    "localhost"; // The host where the database is (mostly this is localhost) $db = "databasename"; //
    The name of the database where you want to work with //connect to the database
    mysql_connect($host,$username,$password); mysql_select_db($db); Some basic statements Now
    we'r...
  29. Php News Script - how to make news script that uses MySQL writen in PHP (19)
    How to make a News script with PHP + MySQL So..in this tutorial i will explain how to create PHP
    news script. first we have to create the table in My SQL.. with the code below you will do this (
    you have to enter it into SQL field ..in PHPmyADMIN) CODE CREATE TABLE news ( id int(10)
    unsigned NOT NULL auto_increment, postdate timestamp(14) NOT NULL, title varchar(50) NOT NULL
    default '', content text NOT NULL, PRIMARY KEY (id), KEY postdate (postdate), FULLTEXT KEY
    content (content) ) >>>> script files 1 file will show the news ,1 file will...
  30. Wamp Packages Needed To Test Scripts - Set up Apache, PHP, etc on your machine (1)
    In order to test php scripts on your localhost machine, you require a system that includes php
    parsing. A WAMP set-up 'usually' includes a database server, and a database manager, too.
    For Windows machines, theses are usually referred to as WAMP because they include Apache, Mysql, and
    PHP for Windows, hence the acronym WAMP. Wikipedia has a listing of the available packages with
    details about the included versions and often a link to the wikipedia article describing them. The
    list can be found at http://en.wikipedia.org/wiki/Comparison_of_WAMPs Personally, I...



Looking for visitors, counter, php, mysql, needed






*SIMILAR VIDEOS*
Searching Video's for visitors, counter, php, mysql, needed

*MORE FROM TRAP17.COM*
advertisement



Visitors Counter - With PHP (no MySQL needed!)