File_get_contents from url that is only accessible after log-in to website?

Curl is pretty well suited to do it. You don't need to do anything special other than set the CURLOPT_COOKIEJAR and CURLOPT_COOKIEFILE options. Once you've logged in by passing the form fields from the site the cookie will be saved and Curl will use that same cookie for subsequent requests automatically as the example below illustrates Note that the function below saves the cookies to 'cookies/cookie.

Txt' so make sure that directory/file exists and can be written to $loginUrl = 'example.com/login'; //action from the login form $loginFields = array('username'=>'user', 'password'=>'pass'); //login form field names and values $remotePageUrl = 'http://example.com/remotepage.html'; //url of the page you want to save $login = getUrl($loginUrl, 'post', $loginFields); //login to the site $remotePage = getUrl($remotePageUrl); //get the remote page function getUrl($url, $method='', $vars='') { $ch = curl_init(); if ($method == 'post') { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $vars); } curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies/cookies. Txt'); curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies/cookies. Txt'); $buffer = curl_exec($ch); curl_close($ch); return $buffer; }.

Curl is pretty well suited to do it. You don't need to do anything special other than set the CURLOPT_COOKIEJAR and CURLOPT_COOKIEFILE options. Once you've logged in by passing the form fields from the site the cookie will be saved and Curl will use that same cookie for subsequent requests automatically as the example below illustrates.

Note that the function below saves the cookies to 'cookies/cookie. Txt' so make sure that directory/file exists and can be written to. $loginUrl = 'example.com/login'; //action from the login form $loginFields = array('username'=>'user', 'password'=>'pass'); //login form field names and values $remotePageUrl = 'http://example.com/remotepage.html'; //url of the page you want to save $login = getUrl($loginUrl, 'post', $loginFields); //login to the site $remotePage = getUrl($remotePageUrl); //get the remote page function getUrl($url, $method='', $vars='') { $ch = curl_init(); if ($method == 'post') { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $vars); } curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies/cookies.

Txt'); curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies/cookies. Txt'); $buffer = curl_exec($ch); curl_close($ch); return $buffer; }.

This works a treat for what I wanted - thanks – Chris Apr 10 at 11:07.

The http pecl extension can do it, also PEAR::HTTP_Client, Snoopy and many many other libraries/classes. If you (for whatever reason) you want to achieved this with file_get_contents, you can use the stream context options for the http wrapper to set POST and cookie parameters and stream_get_meta_data to read the response headers including the cookies.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions