Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我想在PHP代码中使用代理_Php_Sockets_Proxy_Whatsapp - Fatal编程技术网

我想在PHP代码中使用代理

我想在PHP代码中使用代理,php,sockets,proxy,whatsapp,Php,Sockets,Proxy,Whatsapp,我想每次都更改我的请求ip,所以我想使用代理。 如何在下面的代码中实现代理 提前谢谢你 $Socket = fsockopen(static::WHATSAPP_HOST, static::PORT); if ($Socket !== false) { stream_set_timeout($Socket, static::TIMEOUT_SEC, static::TIMEOUT_USEC); $this->socket =

我想每次都更改我的请求ip,所以我想使用代理。 如何在下面的代码中实现代理

提前谢谢你

 $Socket = fsockopen(static::WHATSAPP_HOST, static::PORT);
        if ($Socket !== false) {
            stream_set_timeout($Socket, static::TIMEOUT_SEC, static::TIMEOUT_USEC);
            $this->socket = $Socket;
            $this->eventManager()->fireConnect(
                $this->phoneNumber,
                $this->socket
            );

我假设代理有一个静态ip,所以您的请求ip不会每次都改变。它只会得到代理ip而不是你的

不过,下面是一个使用fsockopen连接到代理的示例。您可能需要自定义命令行,具体取决于您希望获取/发送到服务器/代理的内容。有关更多信息,请查看HTTP命令

将fsockopen与代理一起使用:

<?php
    //URL
    $server      = '1.1.1.1'; //or url
    $server_port = '123';

    //Proxy
    $proxy      = '2.2.2.2';
    $proxy_port = 8080;

    //Open connection
    $socket = fsockopen( $proxy, $proxy_port );

    //Send command to proxy
    fputs($socket, "GET $server:$server_port HTTP/1.0\r\nHost: $proxy\r\n\r\n");

    //Get data
    $data = '';
    while ( !feof($socket) ) {
        $data .= fgets( $socket );  //Save each row to $data
    }

    //Close connection
    fclose($socket);

    //Dump data
    var_dump($data); //Or whatever you want to do
?>