ankhmor Posted November 2, 2008 Share Posted November 2, 2008 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); Quote Link to comment https://forums.phpfreaks.com/topic/131111-execute-javascript-using-curl/ Share on other sites More sharing options...
kenrbnsn Posted November 2, 2008 Share Posted November 2, 2008 Javascript is executed in the browser. I don't believe cUrl can do Javascript. You will have to find another way. Ken Quote Link to comment https://forums.phpfreaks.com/topic/131111-execute-javascript-using-curl/#findComment-680717 Share on other sites More sharing options...
GingerRobot Posted November 2, 2008 Share Posted November 2, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/131111-execute-javascript-using-curl/#findComment-680734 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.