PHP: Using SOCKS4 with SSL connection


Please read first: PHP SOCKS4 Interface

Try to grab data from a HTTPS page like: https://www.google.com

$sock = fsocks4sockopen('199.127.98.31','1080','www.google.com','443');

if(!$sock) die('error');

$packet = "GET / HTTP/1.1
Host: www.google.com:443
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:8.0.1) Gecko/20100101 Firefox/8.0.1
Connection: close

";

fwrite($sock,$packet);

$res = '';
while(!feof($sock)){
    $res .= fgets($sock,4096);
}

var_dump($res);

we get a empty string

string(0) “”

or an error 400 Bad Request:

string(526) “

400 Bad Request

Bad Request

Your browser sent a request that this server could not understand.
Reason: You’re speaking plain HTTP to an SSL-enabled server port.
Instead use the HTTPS scheme to access this URL, please.

Hint: https://tutorialspots.com/


Apache/2.2.22 (CentOS) Server at tutorialspots.com Port 443


If use code below:

$sock = fsocks4sockopen('199.127.98.31','1080','www.tutorialspots.com','443');

if(!$sock) die('error');

$packet = "GET / HTTP/1.1
Host: www.tutorialspots.com:443
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:8.0.1) Gecko/20100101 Firefox/8.0.1
Connection: close

";

fwrite($sock,$packet);

$res = '';
while(!feof($sock)){
    $res .= fgets($sock,4096);
}

var_dump($res);

we take an error:

string(422) “400 Bad Request

HTTPS is required

This is an SSL protected page, please use the HTTPS scheme instead of the plain HTTP scheme to access this URL.

Hint: The URL should starts with https://


Powered By LiteSpeed Web Server
http://www.litespeedtech.com

How Do We Solve This?

Part 2: PHP: Using SOCKS4 with SSL connection – part 2

1 Comment

Leave a Reply