Monday, 19 August 2013

Get page content of a page which is using a form-based authentication

Get page content of a page which is using a form-based authentication

Recently, I have succeeded to get the content of a wiki page using JSON
Plugin:
$username = '****';
$password = '****';
$sc = new Serverclient_helper();
$login =
"http://********/api.php?action=login&lgname=$username&lgpassword=$password";
$content = $sc->getContent($login,array(),false);
$host = "http://******/api.php?action=parse&format=json&page=Main";
$content = $sc->getContent($host);
$content = json_decode($content);
Today I have tried to do the same, but with another page which requires
login too, like the wiki page. It wasn't successful. I think it is because
of the fact that this page has not structure of a wiki page. Here
something to wiki pages. I have read a lot and I understood that my page
is using a form based authentication. But I still want to know how to
access the whole content of the page.
I have also used curl_setopt, but it hasn't helped me to get the content.
Only the login page was diplayed, but I wasn't logged in.
Here is my code:
$username='*****';
$password='*****';
$location='http://*****/startphp';
$mycurl = curl_init ();
curl_setopt($mycurl,CURLOPT_URL,$location);
curl_setopt($mycurl,CURLOPT_RETURNTRANSFER,1);
curl_setopt($mycurl,CURLOPT_USERPWD,"$username:$password");
curl_setopt($mycurl, CURLOPT_TIMEOUT, 10);
$result = curl_exec ($mycurl);
var_dump($result);
Thanks in advance!

No comments:

Post a Comment