Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Actually these answers didn't work because I was running code in a subdirectory of Magento. Magento looks at the dirname of your SCRIPT_NAME variable, and sets it there. So if you're setting the session from /foo/test.php then the cookie will only be valid for /foo/, if magento is at "/", it won't see the cookie.</p> <p>In this case, if your script is the one initially creating the cookie, you have to force the cookie to be valid for "/".</p> <p>The symptoms is that your changes don't take affect, and you can see two sessions in "/var/session". It seems unpredictable, but the different is if Magento creates the session first, its valid for all paths. If your script creates it first, its not valid for Magento, the browser omits it, and Magento creates a new session.</p> <p>Example working code:</p> <pre><code>&lt;?php ini_set('display_errors', 1); require_once $_SERVER['DOCUMENT_ROOT'] . '/app/Mage.php'; Mage::app('mystore', 'website'); $session = Mage::getSingleton('core/session', array('name' =&gt; 'frontend')); $sessionName = $session-&gt;getSessionName(); $sessionId = $session-&gt;getSessionId(); /** * Magento sets the cookie valid for the path "/recommend", but we need it available always (path "/") */ setcookie($sessionName, $sessionId, null, '/'); </code></pre> <p>(The reason I used DOCUMENT_ROOT is because I'm using a modman mapping from this module, which runs the code through a symlink). The important part is the setcookie(). You'll see from examining the http headers two cookies are set. One for "/foo" and one for "/". Without the call to setCookie, only the first session is created, which isn't visible to Magento when accessed through "/index.php" instead of "/foo/test.php"</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload