开发者

get client IP in socket programming in PHP

开发者 https://www.devze.com 2023-01-18 02:18 出处:网络
开发者_StackOverflow中文版I\'m using PHP to write a using socket library application. How could I get the IP of the client? THanks for any helpUsesocket_getpeername<?php

开发者_StackOverflow中文版I'm using PHP to write a using socket library application. How could I get the IP of the client? THanks for any help


Use socket_getpeername


<?php
if ($_SERVER['HTTP_CLIENT_IP'])
    $visitorIP = $_SERVER['HTTP_CLIENT_IP'];
elseif ($_SERVER['HTTP_X_FORWARDED'])
    $visitorIP = $_SERVER['HTTP_X_FORWARDED'];
elseif ($_SERVER['HTTP_X_FORWARDED_FOR'])
    $visitorIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
else
    $visitorIP = $_SERVER['REMOTE_ADDR'];

?>

For more/discussion - getting visitor's real IP address

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号