php tutorial to obtain the client ip address This tutorial provides several code to obtain the ip address, each has its own advantages, users get ip is the use of global variables php to achieve, the following to see if you are looking for. * / // The easiest way
$ ip = $ _server ["remote_addr"]; Echo $ ip; / / Most useful to obtain the user ip address code
function get_real_ip () { $ ip = false; if (! empty ($ _ server ["http_client_ip"])) { $ ip = $ _server ["http_client_ip"]; } if (! empty ($ _ server ['http_x_forwarded_for'])) { $ ips tutorial = explode (",", $ _server ['http_x_forwarded_for']); if ($ ip) { array_unshift ($ ips, $ ip); $ ip = false; } for ($ i = 0; $ i <count ($ ips); $ i ++) { if (! eregi ("^ (10 | 172.16 | 192.168).", $ ips [$ i])) { $ ip = $ ips [$ i]; break; } } } return ($ ip? $ ip: $ _server ['remote_addr']); } echo get_real_ip (); / / Get ip address and port number
$ ip = $ _ server ["remote_addr"]; $ port = $ _server ['remote_port']; Echo $ ip. $ port; / / A little meaning
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.