Home > Backend Development > PHP Tutorial > A function to get the client IP

A function to get the client IP

巴扎黑
Release: 2023-03-01 12:02:01
Original
1293 people have browsed it

<?php
functiontep_get_ip_address(){
if(isset($_SERVER)){
if(isset($_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;])){
$ip=$_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;];
}elseif(isset($_SERVER[&#39;HTTP_CLIENT_IP&#39;])){
$ip=$_SERVER[&#39;HTTP_CLIENT_IP&#39;];
}else{
$ip=$_SERVER[&#39;REMOTE_ADDR&#39;];
}
}else{
if(getenv(&#39;HTTP_X_FORWARDED_FOR&#39;)){
$ip=getenv(&#39;HTTP_X_FORWARDED_FOR&#39;);
}elseif(getenv(&#39;HTTP_CLIENT_IP&#39;)){
$ip=getenv(&#39;HTTP_CLIENT_IP&#39;);
}else{
$ip=getenv(&#39;REMOTE_ADDR&#39;);
}
}
return$ip;
}
echotep_get_ip_address();
?>
Copy after login


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