Skip to content
Advertisement

PHP cURL/Socket and HTTP authentication

I have a webpage with a list of HTML links for images in a protected subfolder. This folder is protected via .htaccess and HTTP authentication.

Is there a way to use cURL/Socket, or something like that, to access to the subfolder?

Advertisement

Answer

<?php
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'http://www.example.com'); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
curl_setopt(CURLOPT_USERPWD, '[username]:[password]') 
$data = curl_exec(); 
curl_close($ch); 
?>

Source

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement