I'm trying to fix an issue with permissions in my app, I have a session->userdata('usrclass') set when login with different account class.
I have an ADMIN user who has a usrclass of ADMIN
and I need to show some content based on that.
BUT when I do this:
<?= ($this->session->userdata('usrclass') == "ADMIN") ? 'yes' : 'no'; ?>
It outputs "no"... While it should output "yes". So I tried reading into the sessiondata with this code:
<?= echo $this->session->userdata('usrclass') ?>
This outputs the word ADMIN
... This is a weird behavior, I've tried using ===
, I've tried to figure out other stuff but couldn't.
What could it be?
I'm going to attach some pics of this:
may be there are some extra whitespace(s) in your session data value, try:
<?php
$sess_data = $this->session->userdata('usrclass');
$sess_data = trim($sess_data);
//and echo
echo ($sess_data == "ADMIN") ? "si" : "no";
?>
You could try making sure it's a string coming back from the session. ((string) $this->session->userdata('usrclass') == "ADMIN") ? 'yes' : 'no';
Maybe a long shot but could the first userdata('usrclass') be wiping the value. Try removing the test code. echo $this->session->userdata('usrclass')