The script I posted will not produce a visible output on-screen. Instead, it will generate a cookie named ‘frontend‘ which tells you that Magento session is running. To double check using the first script if it is working, add the code below which will display an array of classes that has been successfully instantiated. It should include Mage
and Varien
in the list. If it doesn’t, there must be a fatal error somewhere. Add error_reporting(E_ALL);
at the top most part of the file to display any error.
<?php
print_r(get_declared_classes());
?>
Regarding your second script, if your session was started from Magento then you opened WordPress, they won’t share the same session because it uses cookies to authenticate users which in your case, they’re on a different cookie path. It’s similar with what Barry experienced in his comment. To overcome this, you must pass the SID to be used by the PHP session in WP page or vice-versa.
You’re script doesn’t contain the login method. Try this instead (take note of the login part, replace it with your test account):
<?php if(class_exists('Mage')){
Mage::getSingleton('core/session', array('name' => 'frontend'));
}
if(class_exists('Mage')){
$session = Mage::getSingleton("customer/session");
// Add customer credentials here
$session->login('email', 'password');
$magento_message = "Welcome ";
// Generate a personalize greeting
if($session->isLoggedIn()){
$magento_message .= $session->getCustomer()->getData('firstname').' ';
$magento_message .= $session->getCustomer()->getData('lastname').'!';
}else{
$magento_message .= "Guest!";
}
echo $magento_message;
}
?>