Since this is not a BASIC AUTH (eg. protected via .htaccess in apache for example) and instead seems to be session/cookie based, you need to submit the username/password first the same way a regular browser would via a POST request. When successful, the web application will return to you a cookie name/value pair that you will need to use for the next request (ie. to request the page you want to read).
You can either use all the cookies key/value pairs that the server wants you to set or figure out what the important session cookie is. It depends on how the web application works. To figure out what the session cookie name should be and what the usual value looks like try looking at the HTTP requests via a tool like firebug or chrome's dev tools. Once you have figured out what the important cookie name/value is make sure you send that when attempting to read the page within your next request.
The easiest way to do all this in PHP is to use cURL. The rough idea has two parts:
1) Post the username/password to form's action="" processor and return the cookie value pair. See curl_init()
, curl_setopt()
, and curl_exec()
to see how to initialize the request, set its options (eg to set its type as POST, set browser agent string in case the processing script only responds to real browsers, set the request as a headers only request, etc) then execute.
More details on how to do this and get the cookie value can be found on a similar post here.
2) Once you get the session cookie key/value pair, read the page by supplying the cookie/value pair so the website knows you have been authenticated previously. You will want to use the CURLOPT_COOKIE
option with curl_setopt()
when setting this second request and supply the cookie=value pair. More details on how to send a cookie via cURL can be found on a related post here.