[eluser]whobutsb[/eluser]
[quote author="mrphp" date="1232497805"]OK in this simple code i want in every page check for session
class home extends controller
{
function index()
{
/*if session echo hello */
echo anchor(index.php/home/login);
}
[/quote]
Well the first thing you want to do is load up the session.
Code:
$this->load->library('session');
Once you've done that or you've autoloaded it in your config. You can start working with CI sessions. Next you want to check a session.
Code:
$mySession = $this->session->userdata('mySession');
//If the session is empty set it
if(!empty($mySession)){
$this->session->set_userdata('mySession', 'myInformation');
}else{
//Display hello because its not empty and there is information associated with it.
echo "hello";
//Or echo whats in the session.
echo $mySession;
}
If you are trying to write a login script to make sure the person is logged in. I usually add this to the top of my controller in the constructor.
Code:
if(!this->session->userdata('logged_in')){
redirect('home');
}