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
- Why tableless design, DIV vs. TABLE
- Let your visitors run Drupal cron for you
- What is my IP Address and HostName?
- How to use custom function aliases in PHP
- Redirect webpages with HTML, PHP, .htaccess, Java+Script, CGI-Perl, ASP.NET and ColdFusion
- Fix Google Adsense Search and Drupal Conflict
- Packet Sniffing and Monitoring with Tshark / Wireshark
- Url manipulation with mod_rewrite and php-catcher for beginners
- embedding a php contact form in a html table page
- Prevent hotlinking with htaccess and mod_rewrite
- .htaccess examples
- Server load watch
- Google's bloody javascript annoying
- Howto erase your files/partition with shred in linux
- Howto install dig in Debian 5 (Lenny)
- How to recursively create md5 and sha1 sum of your files.
- Repair all mysql databases-tables with PHP
- Common HTML tags for fast copy-paste
- Web 2.0 Style two Side Background, Dark to Light Effect












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