PHP code once per IP Address

chickenugget

Newbie
Joined
Feb 24, 2009
Messages
47
Reaction score
10
Hi All,

I have a script that I only want to run once per IP address on my website. Is there some PHP code that I can use for this?

Cheers
Nugget
 
what language is the script you want to run written in?
 
here you go. i have included comments to help you.
:detective

PHP:
<?php
//note: you must make a table in your
//database called ips with a field called ipaddress
//
//set your mysql options here
$sqlserver = "localhost";
$sqluser = "yourMySqlUsername";
$sqlpassword = "yourMysqlPass";
$sqldatabase = "YourMysqlDB-name";
//end mysql settings

mysql_connect($sqlserver, $sqluser, $sqlpassword);
mysql_select_db($sqldatabase) or die(mysql_error() );

$ip=$_SERVER['REMOTE_ADDR'];

$ipsearch = mysql_query("SELECT * FROM ips WHERE `ipaddress` = '$ip'");

if(mysql_num_rows($ipsearch) < 1){

  //
  //Run your script here.
  //
  
  mysql_query("INSERT INTO ips (`ipaddress`) VALUES('$ip') ");
}

?>
 
Back
Top