Jump to content

Execute javascript using curl


ankhmor

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); 

Link to comment
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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