0

I'm trying to login in a Magento site with curl against a form like this:

<form action="http://www.example.com/es/customer/account/loginPost/" method="post" id="login-form">
<input name="form_key" type="hidden" value="9CR1ydcbOTl9p31r" />
<ul class="form-list">
    <li>
        <label for="email">Email address</label>
        <input type="text" name="login[username]" value="" id="email"/>
    </li>
    <li>
        <label for="pass">Password</label>
        <input type="password" name="login[password]" id="pass" title="Password" />
    </li>
</ul>

With this script, I get the form_key value and sent the login request, with a powershell script in this way:

$formkey = curl.exe -c cookie_urban -s http://www.example.com/es/customer/account/login | Select-String -Pattern ‘value="([A-Za-z0-9]{16,})"‘ | %{$_ -replace '        <input name="form_key" type="hidden" value="', ''} | %{$_ -replace '" />', ''}

curl.exe --cookie "user_allowed_save_cookie=%7B%221%22%3A1%7D" --referer http://www.example.com/es/customer/account/login --user-agent "Mozilla/4.73 [en] (X11; U; Linux 2.2.15 i686)" -b cookie_urban -L -H "Origin: http://www.example.com" --data-urlencode "form_key=$($formkey)&login[username]=email@gmail.com&login[password]=password&send=" http://www.example.com/es/customer/account/loginPost > result.html

The parameters that you see are taken by the developer console of my browser. The problem is that when I click on result.html I can't see that I logged in, why? If you have an explanation please tell me. If you have a solution with another language, tell me! Thanks in advance

0

I think the reason you can't see signs of being logged in is that the loginPostAction from the AccountController redirects in case of any errors or also after the customer data was added to the session.

I don't know how or if it's possible to catch such a redirect with curl but this seems to be needed.

  • So, what do you suggest? If you have a different solution that use wget o something else, please tell me! – DarkSkull Jun 2 '16 at 12:36
  • I don't even know what you're trying to achieve with the curl request. – Anna Völkl Jun 2 '16 at 13:22
  • I'm simply log into the site and then perform such operations as loggedin user. – DarkSkull Jun 2 '16 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.