coolkid
coolkid

Reputation: 543

get client IP in socket programming in PHP

I'm using PHP to write a using socket library application. How could I get the IP of the client? THanks for any help

Upvotes: 3

Views: 9202

Answers (2)

Satya Prakash
Satya Prakash

Reputation: 3502

<?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

Upvotes: -6

nos
nos

Reputation: 229088

Use socket_getpeername

Upvotes: 10

Related Questions