rockwood Posted June 10, 2013 Posted June 10, 2013 How can i make sure my client IP is safe and perfect ? Quote
Dave Posted June 10, 2013 Posted June 10, 2013 What do you define as being "safe and perfect"? There are a number of ways you can check the IP, but not sure what you're trying to achieve. Quote
rockwood Posted June 10, 2013 Author Posted June 10, 2013 i wanna save ip in database by number format ,can suggest me string is better way or number ? like this function vaild_ip($ip) { $ip = trim($ip); if (filter_var($ip, FILTER_VALIDATE_IP)) { $ip = sprintf('%d', ip2long($ip)); return $ip; } } $ip = vaild_ip($_SERVER['REMOTE_ADDR']); Quote
Dave Posted June 10, 2013 Posted June 10, 2013 You could save the results of ip2long into your database then when you pull it out again run the data through long2ip. You also have the option to INET_NTOA to convert the IP to and from an int, then you can store it into an int unsigned. Check out the following stack overflow: http://stackoverflow.com/questions/2542011/most-efficient-way-to-store-ip-address-in-mysql Quote
Guest Posted June 10, 2013 Posted June 10, 2013 filter validate IP validates the IP Returns the filtered data, or FALSE if the filter fails. So if it's false the IP is malformed/malicious. It has to be a string as a number wouldn't allow dots (.) I think EDIT: Dave beat me >.< Quote
Dave Posted June 10, 2013 Posted June 10, 2013 (edited) They're MySQL functions. I'd suggest using MySQL as it'll be more efficient then having to pass everything through to PHP. http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_inet-aton http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_inet-ntoa Edited June 10, 2013 by Dave Macaulay Quote
rockwood Posted June 10, 2013 Author Posted June 10, 2013 filter validate IP validates the IP So if it's false the IP is malformed/malicious. It has to be a string as a number wouldn't allow dots (.) I think EDIT: Dave beat me >.< check this function please ip2long Quote
rockwood Posted June 10, 2013 Author Posted June 10, 2013 They're MySQL functions. I'd suggest using MySQL as it'll be more efficient then having to pass everything to PHP. http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_inet-aton http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_inet-ntoa i am using PDO then ? Quote
Guest Posted June 10, 2013 Posted June 10, 2013 check this function please ip2long What do you mean check this function? Quote
Dave Posted June 10, 2013 Posted June 10, 2013 i am using PDO then ? http://www.php.net/manual/en/intro.pdo.php PDO provides a data-access abstraction layer, which means that, regardless of which database you're using, you use the same functions to issue queries and fetch data. PDO does not provide a database abstraction; it doesn't rewrite SQL or emulate missing features. You should use a full-blown abstraction layer if you need that facility. Quote
rockwood Posted June 10, 2013 Author Posted June 10, 2013 ip2long — Converts a string containing an (IPv4) Internet Protocol dotted address into a proper address Quote
rockwood Posted June 10, 2013 Author Posted June 10, 2013 http://www.php.net/manual/en/intro.pdo.php such a very help full guidance and Thanks Dave Macaulay Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.