MySQL_Narb Posted October 14, 2009 Share Posted October 14, 2009 Alright, I don't get any errors or anything, and my website works fine. But please do tell me why this isn't storing the IP like it's suppose to. 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>"; } ?> Link to comment https://forums.phpfreaks.com/topic/177627-whats-wrong-with-this-script/ Share on other sites More sharing options...
MySQL_Narb Posted October 14, 2009 Author Share Posted October 14, 2009 Bump Link to comment https://forums.phpfreaks.com/topic/177627-whats-wrong-with-this-script/#findComment-936554 Share on other sites More sharing options...
ialsoagree Posted October 14, 2009 Share Posted October 14, 2009 At a quick glance, it looks like all your IP processing is done in functions, but there's never actually any call to those functions so the $ip variable remains undefined in the global scope through the duration of your script. I think you just need to call one of your IP functions to actually return the IP to a variable. Maybe?: <?php $write = mysql_query("INSERT INTO posts VALUES ('','$name','$message', 'getip()')") or die(mysql_eror()); ?> Link to comment https://forums.phpfreaks.com/topic/177627-whats-wrong-with-this-script/#findComment-936555 Share on other sites More sharing options...
mikesta707 Posted October 14, 2009 Share Posted October 14, 2009 you get the clients IP address with the following $_SERVER['REMOTE_ADDR'] Edit: im completely wrong. ignore me Link to comment https://forums.phpfreaks.com/topic/177627-whats-wrong-with-this-script/#findComment-936556 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.