Categories > TinyButStrong general >

_session var cannot be loaded

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: handoko
Date: 2010-06-11
Time: 13:41

_session var cannot be loaded

Dear team.

i have a problem in loading _session var in the field. the story is here,
i have a few templete, like header, login, main and footer. i want to debug for the value of _session['grupid'] when a user was logged in to the user page this value changed into "1" for example. and i display it on footer templete. But unfortunatenly the value was null. What s wrong with my code.??

By: TomH
Date: 2010-06-11
Time: 14:08

Re: _session var cannot be loaded

Hello,
Sorry, you forgot to show your code
By: handoko
Date: 2010-06-11
Time: 14:19

Re: _session var cannot be loaded

Here is the code

  <span class="copyright"><small>Copyright @ erozashop - 2009   </small></span>
  <br />
  [var.footertext;htmlconv=no;noerr]
    <span>Module [var.module;htmlconv=no] </span> <br />
    <span>$_SESSION['admin'] [var._SESSION.admin;htmlconv=no] </span> <br />
    <span>$_GET['page'] [var._GET.page;htmlconv=no] </span> <br />
    <span>$_SESSION["groupid"] [var._SESSION.grupid;htmlconv=no] </span>
  </div>

By: Skrol29
Date: 2010-06-11
Time: 16:59

Re: _session var cannot be loaded

Hi,

grupid or groupid ?
By: handoko
Date: 2010-06-12
Time: 12:40

Re: _session var cannot be loaded

Hi Skrol,

Yes it is a little mistaken,

however it still doesn't show the value of var_session.groupid except i refresh the page,

what is wrong with my code?
By: TomH
Date: 2010-06-12
Time: 15:27

Re: _session var cannot be loaded

If it works when you refresh the page it is telling you that you have not yet set or retrieved the SESSION so that var is not yet available maybe because it is the first cycle through the code and SESSION is not yet been set and retrieved

You need to show the PHP code too...
By: handoko
Date: 2010-06-12
Time: 22:58

Re: _session var cannot be loaded

Here is the code,

if ($_POST["act"]=="login") {
    if ($_POST["loginpwd"]=="") $loginMsg = "Masukan password anda";
    if ($_POST["loginuser"]=="") $loginMsg = "Masukan userid anda";
    if (empty($loginMsg)) {
        $q = "select u.*, c.custid, g.isadmin from eroza_users u left join eroza_usergroup g on g.groupid = u.groupid left join eroza_customers c on c.userid = u.userid where u.userid = '$_POST[loginuser]' and u.userpwd = md5('$_POST[loginpwd]') and u.active = '1'";
        $rs = $db->get_results($q,ARRAY_A);
        if (empty($rs)) {
            $loginMsg = "Invalid userid / password";
        } else {
            $_SESSION["userid"] = $rs[0]["userid"];
            $_SESSION["username"] = $rs[0]["username"];
            $_SESSION["groupid"] = $rs[0]["groupid"];
            $_SESSION["custid"] = $rs[0]["custid"];
            $_SESSION["logintime"] = date("H:i:s");
            $_SESSION["islogon"] = "1";
            $_SESSION["isadmin"] = $rs[0]["isadmin"];
            $db->query("update eroza_users set islogon = '1', lastlogon = now(), exp_session = date_add(now(),INTERVAL 15 minute) where userid = '$_POST[loginuser]'");
            $expire = time() + (60*15);
            $db->query("UPDATE eroza_users_session SET user_id='".$_SESSION['userid']."' , session_expire='".date("Y-m-d H:i:s",$expire)."',session_ip='".$_SERVER['REMOTE_ADDR']."' WHERE session_id='".session_id()."'");
        }
    }
}

the _session.groupid set here once the user admin has just logged in. it should be show up on the admin page at the first time.
By: TomH
Date: 2010-06-13
Time: 01:22

Re: _session var cannot be loaded

Good,
the line for "$q" looks suspsicious

can you be sure that you are getting a db result?

echo the [val.q] to the screen
or
do $db->debug(); after $db->get_results
By: handoko
Date: 2010-06-13
Time: 02:12

Re: _session var cannot be loaded

Yes, i am sure that $rs has already contain value of "_session.groupid" which is "1" as i see it on debug result.
By: handoko
Date: 2010-06-13
Time: 03:00

Re: _session var cannot be loaded

Hi all,

solved,
this is due to my login templete load later than my footer templete (which display the result). After i move login templete into the first position than footer templete, it's work fine.

thanks