Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am having trouble with reloading a page in magento and not being able to hold a session variable.

Here are some code snippets from my project

view.phtml

 <?php
 //Get the session object
 $session = Mage::getSingleton("core/session", array("name"=>"frontend"));  
 $groupid = $session->getMyGroupId("myGroupID");
 echo $groupid;

This is at the top of my view page. There is a drop down menu that with a submit button that goes off to another page called other.php - which takes the value of the drop down and puts it into a session variable

<?php 
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app();

//Set groupid
$data = $_POST['county_select'];
$session = Mage::getSingleton("core/session", array("name"=>"frontend"));
$session->setMyGroupId($data);

header('Location: '.$_SERVER["HTTP_REFERER"]);
?>

This redirects back to the page I was on with the drop down menu and the correct value is echoed out on screen.

Now, if I just refresh this page, the session variable disappears. It's as if it has been unset. Can anyone spot what I am doing wrong please? If I choose from the dropdown menu again, everything comes back fine as before, but a straight refresh means nothing gets echoed out for groupid so I know the session variable is no good now.

Thanks. DS

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
173 views
Welcome To Ask or Share your Answers For Others

1 Answer

replace view.phtml code with this:

echo Mage::getSingleton("core/session", array("name"=>"frontend"))->getMyGroupId();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...