...

View Full Version : Trace an IP via submitting a comment



SRBuckey5266
10-14-2009, 02:16 AM
Is there anyway I can get someones IP when they click submit on one of my forms, it's a comment page and I don't want spammers. I have some moderators, but I want them to be able to do stuff. I can store the IP in my database, but I want to know how do I get the IP from users?

Does anyone have any scripts, or tutorials? Thanks, and I really appreciate the help.

(I'm sorry I've been posting so many help threads, I'm working on a script of mine and I want it to be perfect, and see if their are some different ways to do things.)

SRBuckey5266
10-14-2009, 03:04 AM
Anyone?

treeleaf20
10-14-2009, 03:53 AM
This should do the trick:
http://www.teachmejoomla.net/code/php/remote-ip-detection-with-php.html

SRBuckey5266
10-14-2009, 04:02 AM
I've added it, but why doesn't it submit the IP to the database?

Code:


<center><style type="text/css">

a:link {
color:#24374C;
text-decoration:bold;
}

a:visited {
color:#24374C;
text-decoration:bold;
}

a:active {
outline: none;
color:#24374C;
text-decoration:bold;
}

body {background-color:#b0c4de}

hr.{backround-color:#b0c4de}

div.box {
width:265px;
padding:10px;
border:3px double #000000;
margin:10px;
background-color:#74AFF2;
}
</style>
<?php

$con = mysql_connect('', '', '') or die(mysql_errno());
if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())
{
$_POST = array_map('stripslashes', $_POST);
}

$name = mysql_real_escape_string($_POST['name']);
$message = mysql_real_escape_string($_POST['message']);

if (strlen($message)<=1)
echo "<div class='box'><b><span style='color:red'>Please enter a message!</span></b></div>";
else
{

function validip($ip) {

if (!empty($ip) && ip2long($ip)!=-1) {

$reserved_ips = array (

array('255.255.255.0','255.255.255.255')

);


foreach ($reserved_ips as $r) {

$min = ip2long($r[0]);

$max = ip2long($r[1]);

if ((ip2long($ip) >= $min) && (ip2long($ip) <= $max)) return false;

}

return true;

} else {

return false;

}
}

function getip() {

if (validip($_SERVER["HTTP_CLIENT_IP"])) {

return $_SERVER["HTTP_CLIENT_IP"];

}

foreach (explode(",",$_SERVER["HTTP_X_FORWARDED_FOR"]) as $ip) {

if (validip(trim($ip))) {

return $ip;

}

}

if (validip($_SERVER["HTTP_X_FORWARDED"])) {

return $_SERVER["HTTP_X_FORWARDED"];

} elseif (validip($_SERVER["HTTP_FORWARDED_FOR"])) {

return $_SERVER["HTTP_FORWARDED_FOR"];

} elseif (validip($_SERVER["HTTP_FORWARDED"])) {

return $_SERVER["HTTP_FORWARDED"];

} elseif (validip($_SERVER["HTTP_X_FORWARDED"])) {

return $_SERVER["HTTP_X_FORWARDED"];

} else {

return $_SERVER["REMOTE_ADDR"];

}
}

//connect
$connect = mysql_connect("","","") or die("Connection failed!");
mysql_select_db("") or die("Database fail!");

//write
$write = mysql_query("INSERT INTO posts VALUES ('','$name','$message', '$ip')") or die(mysql_eror());

echo "<div class='box'><font face='arial'><b><span style='color:green'>Posted! Your name was:</span> $name</b> - Your message was....<br><br><b>$message - <a href='index.php'>View it!</a></b>";
}


?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum