2

I am trying to login to a website Using cURL I have read many answers on this website and still not able to get it. Please can someone help me find a solution

$url = 'https://secure.chess.com/login';

$postfields = "c1=USERNAME&loginpassword=PASSWORD&rememberme=";

$cookie = "cookie.txt";


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
$response = curl_exec($ch);

echo $response;
2
  • Paste your code, any errors, curl_info dumps, etc. Question is too tiny to even begin trying. Commented Dec 7, 2012 at 5:59
  • this should work stackoverflow.com/questions/8872071/… Commented Dec 7, 2012 at 5:59

1 Answer 1

1

You seem to be missing a lot of post variables, among which an important state hash which has to be fetched before posting:

c1:USERNAME
loginpassword:PASSWORD
Qform__FormControl:btnLogin
Qform__FormEvent:QClickEvent
Qform__FormParameter:
Qform__FormCallType:Server
Qform__FormUpdates:
Qform__FormCheckableControls:rememberme
Qform__FormState:9661e98ced2596072a3ca5d70cd57ff5
Qform__FormId:LoginForm

An incorrect Qform_FormState yields absolutely no error messages, which proves to be confusing. You have to get the page first, rip out the Qform_FormState hash from the HTML and submit it along. There's also an occasional c4 CAPTCHA field.

I was able to do this without much ado:

curl https://secure.chess.com/login -v | grep -Po '(?<=Qform__FormState" value=").*(?=")'
# 9b6b7d849c1d4fa16ed25b7b886cf88b
# note Set-Cookie: PHPSESSID=vvtk4stb22e34ac7jhg7m6i142; path=/; domain=.chess.com

curl \
    --header "Cookie: PHPSESSID=vvtk4stb22e34ac7jhg7m6i142" \
    --data="c1=USERNAME&loginpassword=PASSWORD... *snip* ...&Qform__FormState=9b6b7d849c1d4fa16ed25b7b886cf88b ..." \
    https://secure.chess.com/login -v
Sign up to request clarification or add additional context in comments.

2 Comments

So I am missing form information? So how would I implement what you have in PHP?
You are indeed; I just answered your question as to why your doesn't work. Based on the information above just make sure you supply all the form field, and get the FormState right (extract from a GET first, use SimpleXML for example).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.