Home | Scripts | Tutorials | Books | Hosting | Forums | Links|

Navigation:

Home
Source code
Tutorials
RSS feeds
Articles
Wordpress plugins
Books
Sample Chapters
Software
Downloads
Hosting
manuals
Script directory
Training
Our Links






 
 

SPONSORS



 
 

Log Visitors IP addresses in a MySQL database

OK start up MySQL and then enter the following to create the database .

CREATE DATABASE ipvisits;

USE ipvisits;

mysql> CREATE TABLE visitorsips(
-> ip VARCHAR(50),
-> date VARCHAR(50));

Now we will insert our visitors IP addresses into the database with the following code

<?php
//get the visitors ip address
$ip_address = $REMOTE_ADDR;
//get the date
$the_date = date("Y-m-d");
//connect to MySQL using your details
$conn = @mysql_connect("localhost","username","password") or die("cannot connect to MySQL");
//select the database
@mysql_select_db("ipvisits") or die("cannot connect to the database");
//execute the query
@mysql_query("INSERT INTO visitorsips(ip,date) VALUES ('$ip_address','$the_date')");
//close the connection
mysql_close($conn);
?>

Now you have got a system for logging peoples IP addresses that visit your site