php - saving IP address in mysql database -


I have a problem saving the IP address in the database

In this way I get the IP:

  function getUserIP () {$ client = @ $ _ server ['HTTP_CLIENT_IP']; $ Forward = @ $ _ Server ['HTTP_X_FORWARDED_FOR']; $ Remote = $ _SERVER ['REMOTE_ADDR']; If (filter_var ($ client, FILTER_VALIDATE_IP)) {$ ip = $ client; } Otherwise (filter_var ($ Forwarded, FILTER_VALIDATE_IP)) {$ ip = $ Forwarded; } And {$ ip = $ remote; } Return IP; } $ User_ip = getUserIP ();  

This is my DB table creation php file

  $ sql = "Turn on Subscription (" ". VARARAR (60) COLLATE utf16_general_ci,". "IPAD INT Unsamelled Faucet Default Null,". "Primary Key (ID));"; $ Revualcle = misc_query ($ sql, $ conn);  

In this way I need to protect the IP

  ("DBConnection.php"); Required ("getIP.php"); Echo $ user_ip "& Lt; br & gt;"; If ($ user_ip === '' 1 ') {$ user_ip =' 127.0.0.1 '; } $ User_ip = ip2long ($ user_ip); Echo $ user_ip "& Lt; br & gt;"; // Click on your website. $ SelectData = mysql_query ("Select * From User"); If (! $ Checkdata) {dead ('Could not retrieve data:' mysql_error ()); } And {$ i = 1; There is no information for // index $ guest = 'guest'. $ I; While ($ row = mysql_fetch_array ($ selectData)) {if ($ line [1] == $ guest & amp; $ line [2]! = $ User_ip) {$ i ++; $ Guest = 'guest' $ I; }} $ Sql ​​= "INSERT" cssgendb`.users` (`id`,` guest`, 'ipad') values ​​('0', '$ guest', '$ user_ip'); $; _SESSION ['is_logged'] = true; $ [_SESSION ['name'] = $ guest;} $ retval = mysql_query ($ sql, $ conn); if (! $ Retval) {dead ('data did not enter Mysql_error ());} echo "session start successfully \ n"; mysql_close ($ Conn);  

My Idea users have to get the IP and save it. If the user is not present in the IP database, the account will be created like "Guest1" ... IPAdd "127.0.0.1";

You have 2 options:

  1. Change the IPad datatype
  2. Long Before calling the IP in time format, before converting it

, as someone else had previously said, you can either switch from mysql * to mysqli or PDO_MySQL Should consider because mysql * functions are excluded.


Comments