title: How do I create a Magento session outside of Magento?
body: <p>I am able to access an existing session outside of Magento perfectly fine using the popular method below.</p>
  
  <pre><code>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 );
  Mage::getSingleton ( 'core/session', array ('name' =&gt; 'frontend' ) );
  </code></pre>
  
  <p>This works great, but how do I actually <strong>create</strong> a Magento session outside of Magento that would populate the log_url, log_visitor, etc. tables as well as assigning the visitor data to the session?</p>
  
  <p>Currently, the user arrives at a page on my site directly from another website.  This specific page is <strong>outside</strong> of Magento but I need to access their Visitor ID using the following code:</p>
  
  <pre><code>Mage::getSingleton ( 'log/visitor' )-&gt;getId()
  </code></pre>
  
  <p>This works fine if the user has previously been to my Magento store, but if not, it just returns a boolean false.  What I would like to do is check to see if there is a value set for the Visitor ID and if not, create the visitor on this first page which is outside of Magento so I can use the Visitor ID right on this page.  It is also important that as soon as the user enters my Magento store, the same Visitor ID will be applied throughout their navigation of my catalog, i.e. the same session.  Any ideas?</p>