Skip to content

Instantly share code, notes, and snippets.

@Alexander-Pop
Last active June 11, 2019 15:29
Show Gist options
  • Save Alexander-Pop/ea09cbf24a8b2792a47b3555f4085ecc to your computer and use it in GitHub Desktop.
Save Alexander-Pop/ea09cbf24a8b2792a47b3555f4085ecc to your computer and use it in GitHub Desktop.
Magento - set/get Session Variable
<?php
/*
* create new session variable foo_data
* You have two options, for the session name, "frontend" for frontend session or "adminhtml" for admin session
*/
Mage::getSingleton("core/session", array("name" => "frontend"));
// This will get the session of the current logged in user.
$session = Mage::getSingleton('customer/session');
$session->setFooData($login['passcode']); //$login['passcode'] is example
$session = Mage::getSingleton('customer/session');
if($session) {
$myData = $session->getFooData();
}
//And this will login to Magento from outside:
$session = Mage::getSingleton('customer/session', array('name' => 'frontend'));
$session->login($row['mail'], $row['field_magentopass_value']);
$session->setCustomerAsLoggedIn($session->getCustomer());
//$row['mail'] is the email with user is registered $row['field_magentopass_value'] is the password
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment