Jump to:

23368 Posts in 18143 Topics by 2863 members

General Questions

SilverStripe Forums » General Questions » [SOLVED] Dynamically Generated Session Index

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

Page: 1
Go to End
Author Topic: 785 Views
  • zenmonkey
    Avatar
    Community Member
    527 Posts

    [SOLVED] Dynamically Generated Session Index Link to this post

    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?

  • zenmonkey
    Avatar
    Community Member
    527 Posts

    Re: [SOLVED] Dynamically Generated Session Index Link to this post

    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.

    785 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.