0

I have located the problem precisely but I don't know how to solve it.

When I'm on my custom cms page with my new admin login form, Magento gives me a different key_form than my default admin login page.

So when I try to login with my custom form, Magento redirects me to my default admin login page and warns me with the following message Invalid Form Key. Please refresh the page.

My Frontend Custom CMS Admin Login Page:

<input name="form_key" value="cbzRGF9ccU8Ac8Ib"/>

My Backend Default Admin Login Page:

<input name="form_key" value="B9O7srzwq7utjQ79"/>

How to generate a form_key on my custom Login page that will be the same as my default admin login form (www.website.com/admin).

1

You can use something like this to create a URL with a valid form key:

$path = "admin/sales_order"; $adminURL = Mage::helper("adminhtml")->getUrl($path);

Just change the variable path to the path you need in your admin panel.

I am assuming you already did that, but to access an admin URL you need to be logged in with a valid Magento Admin account. You can use this code to log in:

$adminUser = Mage::getModel('admin/user');
$username = "USERNAME";
$password = "PASSWORD";

if ($adminUser->authenticate($username, $password)){
    //Your actions if valid login
}
  • Bruno, thanks for your help but your solution is not good. The form_key generated on my custom cms page is not the same that of my default admin panel. – phpschool Nov 17 '16 at 14:41
  • Yeah, the problem is that the key is generated by Magento, so there is no way to have the exact same key. But you can still have a valid one that works. Is your admin panel not working with the generated key? – Bruno Monteiro Nov 17 '16 at 21:12

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.