开发者

In php's fsockopen() findout user's port number

开发者 https://www.devze.com 2023-01-31 11:43 出处:网络
How to find out the port number on the user\'s machine from which the 开发者_如何学JAVAconnection is made?fsockopen returns a stream resource.I\'ve searched through the PHP documentation and can\'t fi

How to find out the port number on the user's machine from which the 开发者_如何学JAVAconnection is made?


fsockopen returns a stream resource. I've searched through the PHP documentation and can't find a way to get the client port from the stream resource.

However, if you go one level lower and use sockets you can easily get at this info. http://www.php.net/manual/en/book.sockets.php

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_connect($socket, 'stackoverflow.com', 80);
socket_getsockname($socket, $host, $port);
var_dump($port);
socket_close($socket);


Try running the netstat command.

netstat -an


It's available as part of the $_SERVER super global

$port = $_SERVER['REMOTE_PORT'];
0

精彩评论

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