Home > Article > Backend Development > How to hide ip in php
How to hide IP in php: First, use the strripos function to find the last position of "."; then use the substr function to intercept the string before the last "."; then add the "*" sign to the string ;Finally, output the hidden result through "echo $hide_ip;".
Recommendation: "PHP Video Tutorial"
PHP method to hide the last digit of the IP address
A long time ago, I wrote an article about using ASP to hide the last digit of the IP address. That is, sometimes in order to protect the user's privacy, the user's IP address will be hidden to achieve an effect similar to 222.222.222.*.
Now I want to use PHP to implement it. After trying it, it is actually very simple. It only needs to use two PHP string functions.
The steps are:
First, use the strripos() function to find the last occurrence of ".";
Then, use the substr() function to intercept the last "." The previous string
$dot = strripos($ip,"."); //查找“.”最后出现的位置 $hide_ip = substr($ip,0,$dot).".*"; //输出“.”最后出现位置之前的字符串并加上*号 echo $hide_ip;
If $ip = 222.222.222.222, the output result is: 222.222.222.*
The above is the detailed content of How to hide ip in php. For more information, please follow other related articles on the PHP Chinese website!