Get customer login form key












0














I want create login functionality outside magento, but same server.
For this I created a login form, but without correct form key it is useless.



Is there way to get customer login form key?



Here is my code. But it gives different key



<?php
require 'store/app/Mage.php';
Mage::app();
// Define the path to the root of Magento installation.
define('ROOT', Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB));

// Obtain the general session and search for an item called 'customer_id'
$coreSession = Mage::getSingleton('core/session', array('name' => 'frontend'));

$key = Mage::getSingleton('core/session')->getFormKey();
?>

<form action="mydomain/store/customer/account/loginPost/" method="post">
<input name="form_key" value="<?php echo $key; ?>" type="hidden">
<input type="text" name="login[username]" value="username" />
<input type="password" name="login[password]" value="password" />
<input type="submit" name="submit" value="submit" />
</form>




Edit



My Problem is $this->getBlockHtml('formkey'); and Mage::getSingleton('core/session')->getFormKey() not same is there any way to use real form key.










share|improve this question
















bumped to the homepage by Community yesterday


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Not sure about this but try $coreSession = Mage::getSingleton('core/session', array('name' => 'frontend'))->start(); instead of $coreSession = Mage::getSingleton('core/session', array('name' => 'frontend'));.
    – Prateek
    Jan 2 '16 at 10:29










  • its not work i want to get same key mydomain/customer/account/login/ form and this page (i want to use this outside login form as login)
    – srinath madusanka
    Jan 2 '16 at 10:35










  • How did you resolve this issue?
    – Anshu Mishra
    Nov 21 '17 at 9:22










  • no. i disable core file key validation part unfortunately
    – srinath madusanka
    Nov 23 '17 at 3:55
















0














I want create login functionality outside magento, but same server.
For this I created a login form, but without correct form key it is useless.



Is there way to get customer login form key?



Here is my code. But it gives different key



<?php
require 'store/app/Mage.php';
Mage::app();
// Define the path to the root of Magento installation.
define('ROOT', Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB));

// Obtain the general session and search for an item called 'customer_id'
$coreSession = Mage::getSingleton('core/session', array('name' => 'frontend'));

$key = Mage::getSingleton('core/session')->getFormKey();
?>

<form action="mydomain/store/customer/account/loginPost/" method="post">
<input name="form_key" value="<?php echo $key; ?>" type="hidden">
<input type="text" name="login[username]" value="username" />
<input type="password" name="login[password]" value="password" />
<input type="submit" name="submit" value="submit" />
</form>




Edit



My Problem is $this->getBlockHtml('formkey'); and Mage::getSingleton('core/session')->getFormKey() not same is there any way to use real form key.










share|improve this question
















bumped to the homepage by Community yesterday


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Not sure about this but try $coreSession = Mage::getSingleton('core/session', array('name' => 'frontend'))->start(); instead of $coreSession = Mage::getSingleton('core/session', array('name' => 'frontend'));.
    – Prateek
    Jan 2 '16 at 10:29










  • its not work i want to get same key mydomain/customer/account/login/ form and this page (i want to use this outside login form as login)
    – srinath madusanka
    Jan 2 '16 at 10:35










  • How did you resolve this issue?
    – Anshu Mishra
    Nov 21 '17 at 9:22










  • no. i disable core file key validation part unfortunately
    – srinath madusanka
    Nov 23 '17 at 3:55














0












0








0


1





I want create login functionality outside magento, but same server.
For this I created a login form, but without correct form key it is useless.



Is there way to get customer login form key?



Here is my code. But it gives different key



<?php
require 'store/app/Mage.php';
Mage::app();
// Define the path to the root of Magento installation.
define('ROOT', Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB));

// Obtain the general session and search for an item called 'customer_id'
$coreSession = Mage::getSingleton('core/session', array('name' => 'frontend'));

$key = Mage::getSingleton('core/session')->getFormKey();
?>

<form action="mydomain/store/customer/account/loginPost/" method="post">
<input name="form_key" value="<?php echo $key; ?>" type="hidden">
<input type="text" name="login[username]" value="username" />
<input type="password" name="login[password]" value="password" />
<input type="submit" name="submit" value="submit" />
</form>




Edit



My Problem is $this->getBlockHtml('formkey'); and Mage::getSingleton('core/session')->getFormKey() not same is there any way to use real form key.










share|improve this question















I want create login functionality outside magento, but same server.
For this I created a login form, but without correct form key it is useless.



Is there way to get customer login form key?



Here is my code. But it gives different key



<?php
require 'store/app/Mage.php';
Mage::app();
// Define the path to the root of Magento installation.
define('ROOT', Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB));

// Obtain the general session and search for an item called 'customer_id'
$coreSession = Mage::getSingleton('core/session', array('name' => 'frontend'));

$key = Mage::getSingleton('core/session')->getFormKey();
?>

<form action="mydomain/store/customer/account/loginPost/" method="post">
<input name="form_key" value="<?php echo $key; ?>" type="hidden">
<input type="text" name="login[username]" value="username" />
<input type="password" name="login[password]" value="password" />
<input type="submit" name="submit" value="submit" />
</form>




Edit



My Problem is $this->getBlockHtml('formkey'); and Mage::getSingleton('core/session')->getFormKey() not same is there any way to use real form key.







magento-1.9 form-key






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 3 '17 at 21:00









sv3n

9,64062352




9,64062352










asked Jan 2 '16 at 9:03









srinath madusanka

317619




317619





bumped to the homepage by Community yesterday


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community yesterday


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.














  • Not sure about this but try $coreSession = Mage::getSingleton('core/session', array('name' => 'frontend'))->start(); instead of $coreSession = Mage::getSingleton('core/session', array('name' => 'frontend'));.
    – Prateek
    Jan 2 '16 at 10:29










  • its not work i want to get same key mydomain/customer/account/login/ form and this page (i want to use this outside login form as login)
    – srinath madusanka
    Jan 2 '16 at 10:35










  • How did you resolve this issue?
    – Anshu Mishra
    Nov 21 '17 at 9:22










  • no. i disable core file key validation part unfortunately
    – srinath madusanka
    Nov 23 '17 at 3:55


















  • Not sure about this but try $coreSession = Mage::getSingleton('core/session', array('name' => 'frontend'))->start(); instead of $coreSession = Mage::getSingleton('core/session', array('name' => 'frontend'));.
    – Prateek
    Jan 2 '16 at 10:29










  • its not work i want to get same key mydomain/customer/account/login/ form and this page (i want to use this outside login form as login)
    – srinath madusanka
    Jan 2 '16 at 10:35










  • How did you resolve this issue?
    – Anshu Mishra
    Nov 21 '17 at 9:22










  • no. i disable core file key validation part unfortunately
    – srinath madusanka
    Nov 23 '17 at 3:55
















Not sure about this but try $coreSession = Mage::getSingleton('core/session', array('name' => 'frontend'))->start(); instead of $coreSession = Mage::getSingleton('core/session', array('name' => 'frontend'));.
– Prateek
Jan 2 '16 at 10:29




Not sure about this but try $coreSession = Mage::getSingleton('core/session', array('name' => 'frontend'))->start(); instead of $coreSession = Mage::getSingleton('core/session', array('name' => 'frontend'));.
– Prateek
Jan 2 '16 at 10:29












its not work i want to get same key mydomain/customer/account/login/ form and this page (i want to use this outside login form as login)
– srinath madusanka
Jan 2 '16 at 10:35




its not work i want to get same key mydomain/customer/account/login/ form and this page (i want to use this outside login form as login)
– srinath madusanka
Jan 2 '16 at 10:35












How did you resolve this issue?
– Anshu Mishra
Nov 21 '17 at 9:22




How did you resolve this issue?
– Anshu Mishra
Nov 21 '17 at 9:22












no. i disable core file key validation part unfortunately
– srinath madusanka
Nov 23 '17 at 3:55




no. i disable core file key validation part unfortunately
– srinath madusanka
Nov 23 '17 at 3:55










1 Answer
1






active

oldest

votes


















0














You need to some change at your code;



Call a frontend design by Mage::app()->loadArea('frontend');



then Call formkey block from current exiting layout $layout = Mage::getSingleton('core/layout');



get block by code:



$layout = Mage::getSingleton('core/layout');

//load default xml layout handle and generate blocks
$layout->getUpdate()->load('default'); // add default handler
$layout->generateXml()->generateBlocks();

//get the loaded head and header blocks and output
$BlockHtml = $layout->getBlock('BlockName');

echo $BlockHtml->toHtml()


For this case you will get same session form_key value:



Modified code:



<?php
require '../app/Mage.php';
umask(0);
Mage::app()->loadArea('frontend');
define('ROOT', Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB));

$layout = Mage::getSingleton('core/layout');

//load default xml layout handle and generate blocks
$layout->getUpdate()->load('default');
$layout->generateXml()->generateBlocks();

//get the loaded head and header blocks and output
$formkeyBlock = $layout->getBlock('formkey');
$key= Mage::getSingleton('core/session')->getFormKey();
?>
<form action="mydomain/store/customer/account/loginPost/" method="post">
<input name="form_key" value="<?php echo $key; ?>" type="hidden">
<input type="text" name="login[username]" value="username" />
<?php echo $formkeyBlock->toHtml() ?>
<input type="password" name="login[password]" value="password" />

<input type="submit" name="submit" value="submit" />

</form>





share|improve this answer





















  • form key key= Mage::getSingleton('core/session')->getFormKey(); and mydomain/customer/account/login/ form key value is differant.any way to get same key.
    – srinath madusanka
    Jan 2 '16 at 10:31










  • because after post this form cant login
    – srinath madusanka
    Jan 2 '16 at 10:33










  • using this key i cant login.any way to create login form outside magento
    – srinath madusanka
    Jan 2 '16 at 10:36










  • @amit : How much of times the formkey valid, its keep updating right?
    – zus
    Jan 10 '18 at 8:40










  • @amit , i am send mail to the customer after buy product and send product review form in customer's mail inside mail customer rate that product and submit review and that review automatically save in magento database , all things working fine except "form key", can you tell me how to add a product review form key in mail template
    – Sanjay Gohil
    Mar 31 '18 at 6:23











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f95693%2fget-customer-login-form-key%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You need to some change at your code;



Call a frontend design by Mage::app()->loadArea('frontend');



then Call formkey block from current exiting layout $layout = Mage::getSingleton('core/layout');



get block by code:



$layout = Mage::getSingleton('core/layout');

//load default xml layout handle and generate blocks
$layout->getUpdate()->load('default'); // add default handler
$layout->generateXml()->generateBlocks();

//get the loaded head and header blocks and output
$BlockHtml = $layout->getBlock('BlockName');

echo $BlockHtml->toHtml()


For this case you will get same session form_key value:



Modified code:



<?php
require '../app/Mage.php';
umask(0);
Mage::app()->loadArea('frontend');
define('ROOT', Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB));

$layout = Mage::getSingleton('core/layout');

//load default xml layout handle and generate blocks
$layout->getUpdate()->load('default');
$layout->generateXml()->generateBlocks();

//get the loaded head and header blocks and output
$formkeyBlock = $layout->getBlock('formkey');
$key= Mage::getSingleton('core/session')->getFormKey();
?>
<form action="mydomain/store/customer/account/loginPost/" method="post">
<input name="form_key" value="<?php echo $key; ?>" type="hidden">
<input type="text" name="login[username]" value="username" />
<?php echo $formkeyBlock->toHtml() ?>
<input type="password" name="login[password]" value="password" />

<input type="submit" name="submit" value="submit" />

</form>





share|improve this answer





















  • form key key= Mage::getSingleton('core/session')->getFormKey(); and mydomain/customer/account/login/ form key value is differant.any way to get same key.
    – srinath madusanka
    Jan 2 '16 at 10:31










  • because after post this form cant login
    – srinath madusanka
    Jan 2 '16 at 10:33










  • using this key i cant login.any way to create login form outside magento
    – srinath madusanka
    Jan 2 '16 at 10:36










  • @amit : How much of times the formkey valid, its keep updating right?
    – zus
    Jan 10 '18 at 8:40










  • @amit , i am send mail to the customer after buy product and send product review form in customer's mail inside mail customer rate that product and submit review and that review automatically save in magento database , all things working fine except "form key", can you tell me how to add a product review form key in mail template
    – Sanjay Gohil
    Mar 31 '18 at 6:23
















0














You need to some change at your code;



Call a frontend design by Mage::app()->loadArea('frontend');



then Call formkey block from current exiting layout $layout = Mage::getSingleton('core/layout');



get block by code:



$layout = Mage::getSingleton('core/layout');

//load default xml layout handle and generate blocks
$layout->getUpdate()->load('default'); // add default handler
$layout->generateXml()->generateBlocks();

//get the loaded head and header blocks and output
$BlockHtml = $layout->getBlock('BlockName');

echo $BlockHtml->toHtml()


For this case you will get same session form_key value:



Modified code:



<?php
require '../app/Mage.php';
umask(0);
Mage::app()->loadArea('frontend');
define('ROOT', Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB));

$layout = Mage::getSingleton('core/layout');

//load default xml layout handle and generate blocks
$layout->getUpdate()->load('default');
$layout->generateXml()->generateBlocks();

//get the loaded head and header blocks and output
$formkeyBlock = $layout->getBlock('formkey');
$key= Mage::getSingleton('core/session')->getFormKey();
?>
<form action="mydomain/store/customer/account/loginPost/" method="post">
<input name="form_key" value="<?php echo $key; ?>" type="hidden">
<input type="text" name="login[username]" value="username" />
<?php echo $formkeyBlock->toHtml() ?>
<input type="password" name="login[password]" value="password" />

<input type="submit" name="submit" value="submit" />

</form>





share|improve this answer





















  • form key key= Mage::getSingleton('core/session')->getFormKey(); and mydomain/customer/account/login/ form key value is differant.any way to get same key.
    – srinath madusanka
    Jan 2 '16 at 10:31










  • because after post this form cant login
    – srinath madusanka
    Jan 2 '16 at 10:33










  • using this key i cant login.any way to create login form outside magento
    – srinath madusanka
    Jan 2 '16 at 10:36










  • @amit : How much of times the formkey valid, its keep updating right?
    – zus
    Jan 10 '18 at 8:40










  • @amit , i am send mail to the customer after buy product and send product review form in customer's mail inside mail customer rate that product and submit review and that review automatically save in magento database , all things working fine except "form key", can you tell me how to add a product review form key in mail template
    – Sanjay Gohil
    Mar 31 '18 at 6:23














0












0








0






You need to some change at your code;



Call a frontend design by Mage::app()->loadArea('frontend');



then Call formkey block from current exiting layout $layout = Mage::getSingleton('core/layout');



get block by code:



$layout = Mage::getSingleton('core/layout');

//load default xml layout handle and generate blocks
$layout->getUpdate()->load('default'); // add default handler
$layout->generateXml()->generateBlocks();

//get the loaded head and header blocks and output
$BlockHtml = $layout->getBlock('BlockName');

echo $BlockHtml->toHtml()


For this case you will get same session form_key value:



Modified code:



<?php
require '../app/Mage.php';
umask(0);
Mage::app()->loadArea('frontend');
define('ROOT', Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB));

$layout = Mage::getSingleton('core/layout');

//load default xml layout handle and generate blocks
$layout->getUpdate()->load('default');
$layout->generateXml()->generateBlocks();

//get the loaded head and header blocks and output
$formkeyBlock = $layout->getBlock('formkey');
$key= Mage::getSingleton('core/session')->getFormKey();
?>
<form action="mydomain/store/customer/account/loginPost/" method="post">
<input name="form_key" value="<?php echo $key; ?>" type="hidden">
<input type="text" name="login[username]" value="username" />
<?php echo $formkeyBlock->toHtml() ?>
<input type="password" name="login[password]" value="password" />

<input type="submit" name="submit" value="submit" />

</form>





share|improve this answer












You need to some change at your code;



Call a frontend design by Mage::app()->loadArea('frontend');



then Call formkey block from current exiting layout $layout = Mage::getSingleton('core/layout');



get block by code:



$layout = Mage::getSingleton('core/layout');

//load default xml layout handle and generate blocks
$layout->getUpdate()->load('default'); // add default handler
$layout->generateXml()->generateBlocks();

//get the loaded head and header blocks and output
$BlockHtml = $layout->getBlock('BlockName');

echo $BlockHtml->toHtml()


For this case you will get same session form_key value:



Modified code:



<?php
require '../app/Mage.php';
umask(0);
Mage::app()->loadArea('frontend');
define('ROOT', Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB));

$layout = Mage::getSingleton('core/layout');

//load default xml layout handle and generate blocks
$layout->getUpdate()->load('default');
$layout->generateXml()->generateBlocks();

//get the loaded head and header blocks and output
$formkeyBlock = $layout->getBlock('formkey');
$key= Mage::getSingleton('core/session')->getFormKey();
?>
<form action="mydomain/store/customer/account/loginPost/" method="post">
<input name="form_key" value="<?php echo $key; ?>" type="hidden">
<input type="text" name="login[username]" value="username" />
<?php echo $formkeyBlock->toHtml() ?>
<input type="password" name="login[password]" value="password" />

<input type="submit" name="submit" value="submit" />

</form>






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 2 '16 at 10:24









Amit Bera

57.2k1374170




57.2k1374170












  • form key key= Mage::getSingleton('core/session')->getFormKey(); and mydomain/customer/account/login/ form key value is differant.any way to get same key.
    – srinath madusanka
    Jan 2 '16 at 10:31










  • because after post this form cant login
    – srinath madusanka
    Jan 2 '16 at 10:33










  • using this key i cant login.any way to create login form outside magento
    – srinath madusanka
    Jan 2 '16 at 10:36










  • @amit : How much of times the formkey valid, its keep updating right?
    – zus
    Jan 10 '18 at 8:40










  • @amit , i am send mail to the customer after buy product and send product review form in customer's mail inside mail customer rate that product and submit review and that review automatically save in magento database , all things working fine except "form key", can you tell me how to add a product review form key in mail template
    – Sanjay Gohil
    Mar 31 '18 at 6:23


















  • form key key= Mage::getSingleton('core/session')->getFormKey(); and mydomain/customer/account/login/ form key value is differant.any way to get same key.
    – srinath madusanka
    Jan 2 '16 at 10:31










  • because after post this form cant login
    – srinath madusanka
    Jan 2 '16 at 10:33










  • using this key i cant login.any way to create login form outside magento
    – srinath madusanka
    Jan 2 '16 at 10:36










  • @amit : How much of times the formkey valid, its keep updating right?
    – zus
    Jan 10 '18 at 8:40










  • @amit , i am send mail to the customer after buy product and send product review form in customer's mail inside mail customer rate that product and submit review and that review automatically save in magento database , all things working fine except "form key", can you tell me how to add a product review form key in mail template
    – Sanjay Gohil
    Mar 31 '18 at 6:23
















form key key= Mage::getSingleton('core/session')->getFormKey(); and mydomain/customer/account/login/ form key value is differant.any way to get same key.
– srinath madusanka
Jan 2 '16 at 10:31




form key key= Mage::getSingleton('core/session')->getFormKey(); and mydomain/customer/account/login/ form key value is differant.any way to get same key.
– srinath madusanka
Jan 2 '16 at 10:31












because after post this form cant login
– srinath madusanka
Jan 2 '16 at 10:33




because after post this form cant login
– srinath madusanka
Jan 2 '16 at 10:33












using this key i cant login.any way to create login form outside magento
– srinath madusanka
Jan 2 '16 at 10:36




using this key i cant login.any way to create login form outside magento
– srinath madusanka
Jan 2 '16 at 10:36












@amit : How much of times the formkey valid, its keep updating right?
– zus
Jan 10 '18 at 8:40




@amit : How much of times the formkey valid, its keep updating right?
– zus
Jan 10 '18 at 8:40












@amit , i am send mail to the customer after buy product and send product review form in customer's mail inside mail customer rate that product and submit review and that review automatically save in magento database , all things working fine except "form key", can you tell me how to add a product review form key in mail template
– Sanjay Gohil
Mar 31 '18 at 6:23




@amit , i am send mail to the customer after buy product and send product review form in customer's mail inside mail customer rate that product and submit review and that review automatically save in magento database , all things working fine except "form key", can you tell me how to add a product review form key in mail template
– Sanjay Gohil
Mar 31 '18 at 6:23


















draft saved

draft discarded




















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f95693%2fget-customer-login-form-key%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

An IMO inspired problem

Management

Investment