Php functions for obtaining website domain names and IP addresses-PHP source code

Source: Internet
Author: User
If you need a php function to retrieve website domain names and IP addresses, refer. If you need a php function to retrieve website domain names and IP addresses, refer.

Script ec (2); script

The Code is as follows:

Function PMA_getenv ($ var_name ){
If (isset ($ _ SERVER [$ var_name]) {
Return $ _ SERVER [$ var_name];
} Elseif (isset ($ _ ENV [$ var_name]) {
Return $ _ ENV [$ var_name];
} Elseif (getenv ($ var_name )){
Return getenv ($ var_name );
} Elseif (function_exists ('apache _ getenv ')
& Apache_getenv ($ var_name, true )){
Return apache_getenv ($ var_name, true );
}
Return '';
}
If (empty ($ HTTP_HOST )){
If (PMA_getenv ('HTTP _ host ')){
$ HTTP_HOST = PMA_getenv ('HTTP _ host ');
} Else {
$ HTTP_HOST = '';
}
}
Echo htmlspecialchars ($ HTTP_HOST );
?>

I put the code for getting the IP address in

The Code is as follows:

Function GetIP (){
If (isset ($ _ SERVER ["HTTP_X_FORWARDED_FOR"])
$ Ip = $ _ SERVER ["HTTP_X_FORWARDED_FOR"];
Else if (isset ($ _ SERVER ["HTTP_CLIENT_IP"])
$ Ip = $ _ SERVER ["HTTP_CLIENT_IP"];
Else if (isset ($ _ SERVER ["REMOTE_ADDR"])
$ Ip = $ _ SERVER ["REMOTE_ADDR"];
Else if (getenv ("HTTP_X_FORWARDED_FOR "))
$ Ip = getenv ("HTTP_X_FORWARDED_FOR ");
Else if (getenv ("HTTP_CLIENT_IP "))
$ Ip = getenv ("HTTP_CLIENT_IP ");
Else if (getenv ("REMOTE_ADDR "))
$ Ip = getenv ("REMOTE_ADDR ");
Else
$ Ip = "Unknown ";
Return $ ip;
}
Echo GetIP ();
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.