PHP to retrieve the content of the Password Required pages once i have password? PHP to retrieve the content of the Password Required pages once i have password? curl curl

PHP to retrieve the content of the Password Required pages once i have password?


Use curlcurl_setopt ( resource $ch , int $option , mixed $value )

option = CURLOPT_HTTPAUTHvalue = choose auth type (CURLAUTH_BASIC, ...)

http://www.php.net/manual/en/function.curl-setopt.php


Look at using a Cookie Jar.

When you first authenticate, the "Cookie" that stores your authentication is lost (assuming your not already using a Cookie Jar), so the next request you make, won't know you have logged in.

As a result, you need to use a Cookie Jar to store the authentication cookie.

http://www.electrictoolbox.com/php-curl-cookies/


It depends on the type of authentication required. If it's the widely used Basic Auth type, it's a trivial header added to the request. You can see the technical details well explained at Wikipedia. To add a header to the request using file_get_contents, use the $context parameter, the use of which is explained with an example here.