Using Isset with Native Sessions in CodeIgniter

I read about how CI handles sessions differently than native sessions, and I'm a little unsure of storing all the data in a cookie (?), Unlike a native PHP session that only stores the session identifier (?). So I decided to use my own sessions without the CI native_session library.

Now I know that the input class in CI checks Isset with a true / false statement as follows:

if ($this->input->post('something'))

which makes the Isset function unable to work (it gives an error). However, I would like to test my own sessions using the Isset function, so how can I do this? I tried

if (isset($_SESSION['keyHere']))

which gives me an error.

So, to summarize: I want to use Isset in my session array, since I feel like using

if ($_SESSION['keyHere'])

without Isset it can be "dangerous / stupid."

Also, as a last question, I wonder which session processing you think is safer? CI session class or inline PHP processing with server storage, etc.? I would really like to feel as safe as possible when it comes to sessions, regardless of whether this means that I will have to write longer code.

+5
source share
7 answers

So let's talk about the problem you are having with isset! I agree with all the answers behind, an empty function is a good attempt using array_key_exists too, but isset has its place in php.

, , bu, @GolezTrol , session_start().

. config/config.php , , index.php

, . , .

, , PHP, , Codeigniter .

Codeigniter , , , , - , , , , Codeigniter , .

cookie, , . , !

, .

+2

array_key_exists isset. isset , null, , null false. , , , , array_key_exists.

.: D

, session_start().

PHP , -.

+1
$data=$this->session->userdata("session variable");

if($data)
{
  // do something
}

CI. !

+1
$logindata = $this->session->userdata('username');

if ($logindata !== FALSE)
{
  //it exists
}

!

+1

php function empty();, -, , .

  • , return FALSE
  • NULL, FALSE

CI 2.0.2. "" , sess_use_database true. sess_encrypt_cookies true , , , IP- , sess_match_ip. , , .

PHP , CI , . , .

, !

0

CodeIgniter? , , isset().

.

$this->session->userdata("keyHere");  // returns false if not set
0

sessionigniter session. db, cookie . cookie codeigniter.

Then, when you access the session information, it acts like normal input methods, so you can just do if ($ this-> session-> userdata ('name')) and not use isset or empty or whatever- something else.

0
source

All Articles