1

In CodeIgniter, checking if an input exists is easy.

Rather than using

$something = isset($_POST['something']) ? $_POST['something'] : NULL;

You can simply do:

$something = $this->input->post('something');

My question is, is it the same with session?

$something = isset($_SESSION['something']) ? $_SESSION['something'] : NULL;

the same with

$something = $this->session->something;
3

2 Answers 2

1

Check whether session variable is set or not using $this->session->has_userdata('variable'); so try like this..

$something = $this->session->has_userdata('something')? $this->session->userdata('something') : NULL;

if session variable is not set then $something has NULL value otherwise it has session value.

For more see codeigniter session

Sign up to request clarification or add additional context in comments.

Comments

1

Yes, $this->session->something will work just fine.

Just remember to load the library. And read the manual if you like:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.