Welcome Guest, Not a member yet? Register   Sign In
Undefined Variable _SESSION
#1

[eluser]MydKnight[/eluser]
I have warnings turned on, and this one identifies as merely a notice, but I wanted to be sure I wasn't doing anything wrong here. When I load the page I get the following:

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: _SESSION

Filename: controllers/welcome.php

Line Number: 40

This is the code block that is causing it:

function verify()
{
if ($this->input->post('username')){
$u = $this->input->post('username');
$pw = $this->input->post('password');
$this->m_user->verifyUser($u,$pw);
if ($_SESSION['userid'] > 0){
redirect('index','refresh');
}
}
$data['main'] = 'login';
$data['title'] = "Login Page";
$data['navlist'] = array(
'home' => 'Home'
);
$this->load->vars($data);
$this->load->view('abctemplate',$data);
}

Do I have anything to be worried about?
#2

[eluser]Colin Williams[/eluser]
$_SESSION is not available until session_start() is called. You might want to consider using the Session class CI provides if you aren't comfortable doing native PHP sessions.
#3

[eluser]JasonS[/eluser]
I would recommend using the native CI session class instead of using the default PHP sessions. CI doesn't use php session's and instead rely's on cookies. To amend this notice you can add session_start() to the index.php file if you wish to continue with what you are doing.
#4

[eluser]bmgz[/eluser]
Rather use natvie PHP Sessions, CI sessions often don't work with IE...
#5

[eluser]John_Betong[/eluser]
 
Beware that calling session_start() must always precede any browser output code.
 
 
 
#6

[eluser]designfellow[/eluser]
Hi,

You've 2 options here.

1.You have to avoid using PHP's native session & can use CI Session library instead.
2.If you still want to use it, then include the below line in CI's main index.php file as the first line of the file.

session_start();


Happy Coding,
DesignFellow




Theme © iAndrew 2016 - Forum software by © MyBB