Duwex Posted March 7, 2017 Share Posted March 7, 2017 I'm new to using cURL and its hard to find good resources for it. What I'm trying to do is login to a remote site, by having curl do the login form and then send back that it was successful. The code I have doesn't seem to work and only tries to show the main page of the site $ch = curl_init();curl_setopt($ch, CURLOPT_URL, 'http://m.algadon.com/login.php?act=login');curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/32.0.1700.107 Chrome/32.0.1700.107 Safari/537.36');curl_setopt($ch, CURLOPT_POST, true);curl_setopt($ch, CURLOPT_POSTFIELDS, "username=kontol&password=kontol");curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_COOKIESESSION, true);curl_setopt($ch, CURLOPT_COOKIEJAR, '$ckfile'); //could be empty, but cause problems on some hostscurl_setopt($ch, CURLOPT_COOKIEFILE, '$ckfile'); //could be empty, but cause problems on some hosts$answer = curl_exec($ch);if (curl_error($ch)) { echo curl_error($ch);}//another request preserving the sessioncurl_setopt($ch, CURLOPT_URL, 'http://m.algadon.com/login.php?act=login');curl_setopt($ch, CURLOPT_POST, false);curl_setopt($ch, CURLOPT_POSTFIELDS, "");$answer = curl_exec($ch);if (curl_error($ch)) { echo curl_error($ch);} Quote Link to comment Share on other sites More sharing options...
zamight Posted March 9, 2017 Share Posted March 9, 2017 I don't know the host's code. Since the form submits via POST and your only passing two parts of the form when there are three. Including the button which is name="Submit" and value="Login" this could pose a problem from the host if they check for the value of the button. This is just a guess. I don't really use curl to login websites. Quote Link to comment 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.