I am using the following code to access a site that is using basic HTTP-AUTH. $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); if($user && $pass){ curl_setopt($ch, CURLOPT_USERPWD, $user . ':' . $pass); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); } curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30 ); curl_setopt($ch, CURLOPT_TIMEOUT,5 ); $response = curl_exec($ch); PHP: All the variables are correct. If I access a page without HTTP-AUTH it works perfectly. Any input is appreciated. Thanks.
Hello, This site: http://www.higherpass.com/php/tutorials/Using-Curl-To-Query-Remote-Servers/5/ Has neat examples on what you're trying to do. Jay
Thanks for the link. I made my test code cURL and cURL only and started to find my problem. cURL has yet to work - I had just coded a failsafe use of file_get_contents if cURL didn't work. I am working behind a proxy, but my proxy settings don't effect anything. Even trying to pull down contents from (http)localhost/folder/file.txt don't even work. Also - when I include curl_setopt(CURLOPT_USERPWD, 'userassword') the script will not complete. When commented out, the script gets to the end and tells me it failed.
Have you tried: $data = file_get_contents("http://username:password@www.thesite.com/thefile.php"); echo $data; PHP: Or using http://www.php.net/fsockopen (using the "Authorization: Basic [base64-data-here]" header)? Jay
hello, Im stuck with the same problem. But the thing is, I cant use userass@server.com because my script is so huge and it connects to different server and each server uses different type of auth.. Im facing the same problem. When I use this: curl_setopt($ch, CURLOPT_URL, "http://$user:$pass@server.com"); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); // curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); // curl_setopt($ch, CURLOPT_USERPWD, $user.':'.$pass); It works perfectly But when I uncomment the auth parameters .. It just fails :s (doesnt matter if I include userass@ or not.. it fails everytime)