Jump to content

Archived

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

ankhmor

Execute javascript using curl

Recommended Posts

Here's a situation:

I need to log in into a site.

But instead of a normal submit button they have an image with

onclick="document.getElementById('safemls-login').submit(); return false;"

When I just type

javascript:document.getElementById('safemls-login').submit()

into browser address bar i can log in.

When i try to use

curl_setopt($init, CURLOPT_URL,"javascript:document.getElementById('safemls-login').submit()");

I get a search page displayed.

Can someone tell me how to log in into this website

Thank you

 

 

 

Here's my complete code:

$user_id = "pass";
$pin = "pass";
$auth =  "";
$user_agent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)";
$postfields = "username=$user_id&pin=$pin&password=$auth";


$init = curl_init();

curl_setopt($init, CURLOPT_HEADER, 1); // Get the header
curl_setopt($init, CURLOPT_FOLLOWLOCATION, 1); // Allow redirection
curl_setopt($init, CURLOPT_USERAGENT, $user_agent);
curl_setopt($init, CURLOPT_URL,"http://www.torontomls.net/Login.asp");
curl_setopt($init, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($init, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt ($init, CURLOPT_RETURNTRANSFER, 1);

curl_setopt ($init, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($init, CURLOPT_POST, 1);
curl_setopt($init, CURLOPT_POSTFIELDS, "$postfields");
curl_setopt($init, CURLOPT_URL,"javascript:document.getElementById('safemls-login').submit()");
ob_start(); // prevent any output
$log_in = curl_exec($init);
ob_end_clean(); // stop preventing output

echo $log_in;
curl_close($init); 

Share this post


Link to post
Share on other sites

Javascript is executed in the browser. I don't believe cUrl can do Javascript. You will have to find another way.

 

Ken

Share this post


Link to post
Share on other sites

Regardless of how it's actually done, a request must be sent to the server. You need some way of copying this request. If you get the Live HTTP Headers extension for Firefox, you'll be able to see exactly what's being sent to where. Make your cURL request copy that.

 

Also, you should note that, if you need to log in and then grab some information, you must make two separate cURL requests

Share this post


Link to post
Share on other sites

×
×
  • 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.