Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

[SOLVED] Dynamically Generated Session Index


Reply


2 Posts   856 Views

Avatar
zenmonkey

Community Member, 532 Posts

2 October 2009 at 8:56am

Edited: 02/10/2009 9:51am

I'm trying to Dynamically Generate a Session Index and Check if isset. When the page that checks if its set loads I get an Unidentified Index error. Is there a way I could Set it to 0 or 1 when a Visiter firsts visits the site but doesn't re-write that value on Page Load which it would do if I fired it on init in the Page.php?

Here is my Check Function in my PageType.php if it helps

function CodeCheck(){
      $arIndex= strtolower(str_rot13(str_ireplace(" ","",$this->Title)));
      if ($_SESSION[$arIndex] == strtolower($this->AccessCode)) {
         return true;
      }
      else
      {
         return false;
      }
   }

As you can see it checks $_SESSION[$arIndex] for a specific value, however if the User Hasn't visited this page its not set and I get the UnIdentified Index error. If I write something to it in the init() function it gets over written with each page load thereby erasing the Visitor submitted data.

Is there an existing $_SESSION array in the system that only gets written on the Visitors FIRST pageload?

Avatar
zenmonkey

Community Member, 532 Posts

2 October 2009 at 9:50am

Solved thanks to IRC

FYI in my init function I used

$sesCheck = Session::get($arIndex);
      if (isset($sesCheck)){
      }
      else
      {
         Session::addToArray($arIndex, 1);
      }

Using the Session Class instead of $_Session, and did all my checks against the Session Class.