How to access Magento customer's session from outside Magento?
You will need to enter in .domain.com
in Magentos admin->system->configuration->web->cookie domain
. Like erickthered mentioned, you will need to make the cookie available to your other subdomains in order for it to be read. This is the same with all web applications.
Reference: http://www.magentocommerce.com/wiki/modules_reference/english/mage_adminhtml/system_config/edit/web#session_cookie_management_field_descriptions
How to access Magento user's session from outside Magento?
I would recommend checking the path of the cookie that Magento sets. Most likely, it is set to /shop
, so the cookie will not be accessible to your file above it.
You can modify the path that Magento uses to set its cookie in the control panel under System -> Configuration -> Web (under the General heading) -> Session cookie management
How do I create a Magento session outside of Magento?
Well, I've figured it out. Although I must admit it's not the cleanest solution, it works exactly as I had hoped. For anyone else who's looking to do this, I've pasted my code excerpt below:
require 'app/Mage.php';
$mageRunCode = isset ( $_SERVER ['MAGE_RUN_CODE'] ) ? $_SERVER ['MAGE_RUN_CODE'] : '';
$mageRunType = isset ( $_SERVER ['MAGE_RUN_TYPE'] ) ? $_SERVER ['MAGE_RUN_TYPE'] : 'store';
$app = Mage::app ( $mageRunCode, $mageRunType );
$core_session = Mage::getSingleton ( 'core/session', array ('name' => 'frontend' ) );
$write = Mage::getSingleton ( 'core/resource' )->getConnection ( 'core_write' );
$url = Mage::getUrl ( '*/*/*', array ('_current' => true ) );
Mage::getSingleton ( 'core/session' )->setLastUrl ( $url );
$visitor_id = $_SESSION ['core'] ['visitor_data'] ['visitor_id'];
if (! empty ( $visitor_id )) {
Mage::getSingleton ( 'log/visitor' )->setId ( $visitor_id );
} else {
Mage::getSingleton ( 'customer/session' )->setWishlistItemCount ( 0 );
Mage::getSingleton ( 'catalog/session' )->setCatalogCompareItemsCount ( 0 );
$write->query ( "INSERT INTO log_url_info (url, referer) VALUES (?, ?)", array ($url, Mage::helper ( 'core/http' )->getHttpReferer ( true ) ) );
$url_id = $write->lastInsertId ();
$log_visitor = Mage::getSingleton ( 'log/visitor' )->initServerData ()->setFirstVisitAt ( now () )->setIsNewVisitor ( true )->setLastVisitAt ( now () )->setLastUrlId ( $url_id )->save ();
$write->query ( "INSERT INTO log_url (url_id, visitor_id, visit_time) VALUES (?, ?, ?)", array ($url_id, $log_visitor->getId (), now () ) );
$core_session->setVisitorData ( $log_visitor->getData () );
$visitor_id = $log_visitor->getId ();
}
I hope this helps someone else so they're not ripping their hair out like I was.
Checking for Magento login on external page
Using the code above, I created a php file in the Magento folder. From there, added the number of items in the cart and whether you were logged in or not to an array and encoded it as json. I used some jquery on my external page to grab the file and pull the data I needed.
Not quite the ideal situation, but it works for now.
How to Create session for customer login with session outside magento
Sessions are stored in database session table or something like that or, more commonly, in var/session. Depends on the install.
Login user programmatically in magento not working properly?
tells you how to log someone into magento "outside" of the magento. I do think the answer in the link is missing:
Mage::app('mysite');
before running the code. So something like this:
Mage::app('mysite');
$session = Mage::getSingleton( 'customer/session' );
try
{
$session->login( $email, $password );
$session->setCustomerAsLoggedIn( $session->getCustomer() );
return true;
}
catch( Exception $e )
{
//error handling code
}
to create a user look here:
http://inchoo.net/ecommerce/magento/programming-magento/programatically-create-customer-and-order-in-magento-with-full-blown-one-page-checkout-process-under-the-hood/
Related Topics
How to Get Page Number on Dompdf PDF When Using "View"
File Attachment with PHPmailer
Trying to Access Array Offset on Value of Type Bool
PHP - Merge Two Arrays (Same-Length) into One Associative
Unknown Modifier '/' Error in PHP
Best Way to Store Passwords in MySQL Database
Trying to Send Mail Using Swift Mailer, Gmail Smtp, PHP
How to Execute PHP with Extension File.Php.Jpg
Tilde Operator in Regular Expressions
Do I Really Need to Do MySQL_Close()
PHP Sample Script for Pagination
Get All Orders Ids from a Product Id in Woocommerce
Is Is Bad Practice to Use Array_Walk with MySQLi_Real_Escape_String