Page generation time and http-referers with PHP
Webmasters want to know where all visitors coming from, which pages they visit and how long does it take webpages to load in miliseconds. This tutorial shows how to save your visitors/website details like referrer, browser/client, ip-address, langind-page in three steps. Remember if your scripts ends with exit() or die() command, footer code will not work. Just remove that commands or put them below footer code.
- Create your mysql table
- Add top-code
- Add bottom-code
SQL Query
Execute this code with phpMyAdmin or a similar tool to create your mysql table.
CREATE TABLE IF NOT EXISTS `monitoref` ( `id` int(11) NOT NULL auto_increment, `dtime` timestamp NOT NULL default CURRENT_TIMESTAMP, `pg` double NOT NULL, `url` varchar(255) NOT NULL, `ref` varchar(255) NOT NULL, `ip` varchar(15) NOT NULL, `browser` varchar(120) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;
Start code at the top of page
Put this code at the top of your .php file (config.php rewrite-catcher etc)
define("STARTMICROTIME", array_sum( explode(' ', microtime() ) ) );
End code at the bottom of file
Add this code to your last .php file, in most cases footer.php. Be sure that no exit() or die() command placed above this code.
$page_gen_time = round(array_sum( explode(" ", microtime())) - STARTMICROTIME, 2);
$url = mysql_real_escape_string($_SERVER[REQUEST_URI]);
$ref = mysql_real_escape_string($_SERVER[HTTP_REFERER]);
$browser = mysql_real_escape_string($_SERVER[HTTP_USER_AGENT]);
$ip = mysql_real_escape_string($_SERVER[REMOTE_ADDR]);
mysql_query("insert into monitoref ( pg, url, ref, ip, browser)
values
('$page_gen_time', '$url', '$ref', '$ip', '$browser')");
Now you can analyze your visitors and page generation time with phpMyAdmin.
Similar entries
- MSIE8 BrowserProxy.System is Null or no-object
- Server Benchmark with PHP 5 : ThePlanet, Hosteurope, Hetzner
- [Howto Fix] Table './eximstats/sends' is marked as crashed and should be repaired
- Let your visitors run Drupal cron for you
- Why tableless design, DIV vs. TABLE
- What is my IP Address and HostName?
- How to use custom function aliases in PHP
- Packet Sniffing and Monitoring with Tshark / Wireshark
- php
- Redirect webpages with HTML, PHP, .htaccess, Java+Script, CGI-Perl, ASP.NET and ColdFusion
- Fix Google Adsense Search and Drupal Conflict
- web development tool Firebug for Firefox
- Prevent hotlinking with htaccess and mod_rewrite
- Url manipulation with mod_rewrite and php-catcher for beginners
- search for files and create an archive with them (tar,find,linux)
- CMS for a nice-looking news website
- .htaccess examples
- Howto erase your files/partition with shred in linux
- Howto install dig in Debian 5 (Lenny)

Comments
thanks for this useful posts.
thanks for this useful posts. Really, i need this!
Post new comment