mercredi 24 mai 2017

If/else for https connection through proxy

I am using this code to check a proxy server, before doing anything else. When the connection is ok, I have a file_get_contents line to connect to a website.

$host = '123.45.678.90'; 
$port = 80; 
$waitTimeoutInSeconds = 1; 
if($fp = fsockopen($host,$port,$errCode,$errStr,$waitTimeoutInSeconds)){   
    $aContext = array(
    'http' => array(
    'proxy' => 'tcp://123.45.678.90:80',
    'request_fulluri' => true,
    ),
    );
    $cxContext = stream_context_create($aContext);

    // connect to website using a proxy server
    $file_content = file_get_contents('http://ift.tt/2rKteoW', False, $cxContext);
} else {
   // It didn't work 
} 
fclose($fp);

But though the proxy connection was succesfull, I see this: Warning Cannot connect to HTTPS server through proxy? Is there any chance to have an if/else statement, that allows me to do something if there is no warning and stop doing something if there is a warning? I have looked and googled a lot, but haven't found anything I could try.

Thanks for your help!

Aucun commentaire:

Enregistrer un commentaire