0

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?

2 Answers 2

3

If you are talking about HTTP Basic authentication, then you can provide the necessary credentials with

curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); // enable HTTP Basic auth
curl_setopt($curl, CURLOPT_USERPWD, "username:password"); // credentials

There are also some other options that may be of interest such as CURLOPT_PROXYUSERPWD (if you are going through a proxy) and CURLOPT_UNRESTRICTED_AUTH (if the initial host redirects you to another domain where the actual authentication takes place).

Sign up to request clarification or add additional context in comments.

Comments

1
<?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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.