Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Session on php file not showing on phtml page - ajax
 
counterfoxx
Jr. Member
 
Total Posts:  29
Joined:  2012-08-07
 

I have some jQuery with ajax in an Magento phtml file which POSTs to an custom php script I have. What I want to do is create an Magento session in the custom php script which value is available in the phtml file where the ajax call is made.

For example the phtml file (category list page) has the ajax call:

$.ajax({     
type
"POST",     
url"/php/process.php",     
datadataString,     
success: function(){       
location
.reload();
        
}     
        }
);

Which successfully calls to my custom php script (process.php).

process.php contains the following code for testing:

require_once ("/app/Mage.php");
umask(0);
Mage::app();  
$returnedString"123";
Mage::getSingleton('core/session')->setMyValue($returnedString);

I have also tried this with session_start().

Now in the phtml file to test the session is active I have the following test code:

if(Mage::getSingleton('core/session')->getMyValue()=='123'):
    echo 
"Session created";
else:
    echo 
"Session not created";

endif;

If I display the session array in the phtml file the session isn’t visible as well. I’m not sure where I’m going wrong.

Any help is greatly appreciated. Thanks in advance.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top