Skip to content

Instantly share code, notes, and snippets.

@quitequinn
Last active August 29, 2015 14:08
Show Gist options
  • Save quitequinn/23c7de988d15ee6c1645 to your computer and use it in GitHub Desktop.
Save quitequinn/23c7de988d15ee6c1645 to your computer and use it in GitHub Desktop.
<?
function get_client_ip() {
$ipaddress = '';
if (getenv('HTTP_CLIENT_IP'))
$ipaddress = getenv('HTTP_CLIENT_IP');
else if(getenv('HTTP_X_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_X_FORWARDED_FOR');
else if(getenv('HTTP_X_FORWARDED'))
$ipaddress = getenv('HTTP_X_FORWARDED');
else if(getenv('HTTP_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_FORWARDED_FOR');
else if(getenv('HTTP_FORWARDED'))
$ipaddress = getenv('HTTP_FORWARDED');
else if(getenv('REMOTE_ADDR'))
$ipaddress = getenv('REMOTE_ADDR');
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
$user="dbo548510402";
$password="290Characters!";
$database="db548510402";
mysql_connect("db548510402.db.1and1.com",$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
// mysql_query("DROP TABLE yournumber");
mysql_query("CREATE TABLE yournumber (id int(6) NOT NULL auto_increment,ip varchar(15) NOT NULL, PRIMARY KEY (id), UNIQUE id (id), KEY id_2 (id))");
$n=0;
function action(){
$curIP = get_client_ip();
echo $curIP;
$query = "SELECT * FROM yournumber WHERE ip = '$curIP'";
$result=mysql_query($query) or die(mysql_error());
echo " _ _ _ _";
echo $query;
while($row = mysql_fetch_array($result)){
foreach($row as $cname => $cvalue){
print "$cname: $cvalue\t";
}
print "\r\n";
}
if (!$result) {
echo "no result";
if ($n=2) {
echo "ERROR";
return;
}
mysql_query("INSERT INTO yournumber VALUES ('','$curIP')");
$n++;
action();
}else{
$thing = mysql_fetch_array($result);
echo '<h1>'.$thing[0].'</h1>';
};
}
action();
mysql_close();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment