11.7 Connecting Through a Proxy Server


You want to use the Net_Curl class from PEAR and set the proxyUser and proxyPassword properties.

Technique

Use the following code:

 <?php // Initialize $conn = new Net_Curl('http://qa.php.net/'); if (Net_Curl::isError($conn)) {     die(sprintf('Error [%d]: %s',                 $conn->getCode(), $conn->getMessage())); } // Set transfer options $conn->proxyUser     = 'sterling'; $conn->proxyPassword = 'secret'; // Execute transfer $data = $conn->execute(); if (Net_Curl::isError($data)) {     die(sprintf('Error [%d]: %s',                 $data->getCode(), $data->getMessage())); } print "The results of your transfer were: \n<br>\n"; print $data; ?> 

Comments

If you need to interact with a proxy server to fetch a URL with the Net_Curl class, set the proxyUser and proxyPassword properties to appropriate values and execute the transfer.



PHP Developer's Cookbook
PHP Developers Cookbook (2nd Edition)
ISBN: 0672323257
EAN: 2147483647
Year: 2000
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net