Jump to content

[SOLVED] parsing pages behind a user login...


interpim

Recommended Posts

So, I built a parser that will parse the HTML of a page, but the page I want to parse requires a username and a password to get to it.

 

I have a username and password, but I cannot get my script to access the pages.

 

I have tried cURL (maybe incorrectly) and it doesn't work...

I have tried passing the variables to the page which it looks like the page requires me to do and it doesn't work

 

I am trying to login to this page here http://realmwar.warhammeronline.com/realmwar/Index.war

 

The parser just gets redirected back to this page when it cycles through the URL's I pass to it instead of the actual pages, indicating it isn't logging in.  I am using WAMPP on the same machine that I have logged into the site with, but I still cannot get to it... can anyone offer any suggestions?

You'll need to get all the form values that you need to send for curl

You'll also need to setup a cookiejar to store the login cookie

 

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

 

Take a look at some of the options there and examples and you should get what you need.

hmmm... can you explain the cookie jar?  I have a cURL set up already for it.

$URL="http://realmwar.warhammeronline.com/realmwar/Index.war";
$ch = curl_init();   
curl_setopt($ch, CURLOPT_URL,"$URL"); 
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "war_username=$user_name&war_password=$pword");curl_exec ($ch);    
curl_close ($ch); 

First off, you need to be posting to the actual login URL

Which is this: http://realmwar.warhammeronline.com/realmwar/UserLoginAuthentication.war

Then, you need to be passing the correct parameters, which is actually user and password like so:

 

user=$user_name&password=$pword in the postfields option

 

Then for the cookies and logging in, you need to add

 

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

curl_setopt($ch, CURLOPT_COOKIEFILE, "cookiefilename");

curl_setopt($curl, CURLOPT_COOKIEJAR, "cookiefilename");

 

Then use curl_exec() and assign it to a variable so the output of the login page is stored like so

 

$pageResults = curl_exec($ch);

 

From there you can change the CURLOPT_URL to any page that requires you to be logged in and it should work.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.