Home > Backend Development > PHP Problem > How to hide ip in php

How to hide ip in php

藏色散人
Release: 2023-03-06 19:48:01
Original
1868 people have browsed it

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;".

How to hide ip in php

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;
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template