WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : A simple script to count and report hits and the last modification time of an HTML page. Requires MySQL support (other DBs should work too, except possibly mSQL).
Categories : HTTP, MySQL, PHP, Databases Update Picture
Cary Collett
Date : May 13th 1998
Grade : 4 of 5 (graded 2 times)
Viewed : 13516
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Cary Collett
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<?php
/*
Pagestats v1.0

Copyright 1998 Cary Collett. Use it freely, distribute it freely, tell me
how great it is freely and send me any cool mods you come up with for it,
freely.

cary@ratatosk.org


Changes

1.1 Now using SCRIPT_FILENAME everywhere instead of SCRIPT_NAME. Using
SCRIPT_NAME could result in collisions if virtual hosts are being used.
I.e. hits for www.foo.com/index.html and www.bar.com/index.html would
both be collected for the same URI. Of course this makes the column
name URI a misnomer. Change it if it really bothers you. ;-)
*/
/*

A simple script to be included that reports hits, last modification
and when the hit counting started. You'll need MySQL support.
Though it should be easy to port this to any decent DBMS (mSQL
might be a little sticky becuase of it's severely limited
feature set; I don't use it anymore so I don't know for sure.)

This mysql table must exist in the database 'php' (or you can edit
stuff to suit you).

create table pagestats (
uri varchar(96) primary key,
hits bigint not null default 0,
since datetime
);

It defines several variables:

$hits = Number of hits counted
$since = full blown date & time since the counter started
$lastmod = full blown date & time of the last modification (ctime) of
the file

The following Unix epochs are set. Users can use these if they don't like
default format.

$sincesecs = Unix epoch of since
$modsecs = Unix epoch of lastmod

An example of usage:

1. Put this file somewhere in your PHP include path.
2. Stick something like this in your page:


<? include("pagestats.php3"); ?>

<? echo $hits . " hits since " . date('F d, Y',$sincesecs); ?>.
<p>
Last modified: <? echo $lastmod; ?>
<p>


*/

$link = mysql_pconnect('localhost','logger','');
mysql_select_db('php',$link);

$qs = "UPDATE pagestats SET hits=hits+1 WHERE uri = '$SCRIPT_FILENAME'";

$r = mysql_query($qs,$link);

if (mysql_affected_rows($link) < 1) {
/* oops, no row for this page, create one */
mysql_query("INSERT INTO pagestats VALUES ('$SCRIPT_FILENAME',1,SYSDATE())",
$link);
}

$res = mysql_query("SELECT hits, UNIX_TIMESTAMP(since) as since FROM pagestats
WHERE uri = '$SCRIPT_FILENAME'",$link);

$sincesecs = mysql_result($res,0,'since');
$modsecs = filectime($SCRIPT_FILENAME);

$hits = mysql_result($res,0,'hits') + 1;

/*
see the date() docs if you want to change this
The format 'l F d, Y h:i:s A' makes dates like this:
Friday May 08, 1998 04:22:08 PM
*/

$dateformat = 'l F d, Y h:i:s A';

$since = date($dateformat,$sincesecs);
$lastmod = date($dateformat,$modsecs);
?>



Simple pipe delimited file export program that downloads to a local machine
Categories : PHP, Filesystem, Databases, MySQL, HTTP
The simple counter with use MySql and gd.
Categories : MySQL, HTTP, Graphics, PHP, Databases
Identify and log search engine access (spiders, robots, etc.) to a page.
Categories : HTTP, Environment Variables, PHP, MySQL, Databases
This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server.
Categories : Databases, MySQL, Complete Programs, PHP, Databases
bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager
Categories : MySQL, PHP, MySQL, Complete Programs, Databases
This is Yet Another Sql Abstraction Library. Include it in your script and you can use the most important SQL functions without worrying about the SQL backend.
Categories : Databases, PHP, ODBC, MySQL, PostgreSQL
Cut your MySQL Connections to 1 line of code
Categories : PHP, Beginner Guides, Databases, MySQL
simple script to send emails via a html-form to different users
Categories : Email, MySQL, PHP, Databases
Displaying records of database in more than one page (paging)
Categories : Databases, MySQL, PHP
html split bar used to split in multiple pages a database result
Categories : HTML and PHP, Databases, MySQL, PHP
Tropicalm Genetree Family (MySQL based family tree)
Categories : PHP, Interfaces, Databases, MySQL, Complete Programs
Report Generation in Microsoft Access from a MYSQL database
Categories : PHP, MySQL, Databases, MS Access
Automatically printing the contents of an sql table in MySQL.
Categories : MySQL, PHP, HTML and PHP, Databases
Email a user with out exposing email address
Categories : PHP, Databases, MySQL, Email
http://phpMySearch.web4.hm - The phpMySearch search engine system is a completeworld wide web indexing and searching system for a small domain or intranet.
Categories : Search Engines, PHP, Databases, MySQL