![]() |
please i cant understand session - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: please i cant understand session (/showthread.php?tid=14921) Pages:
1
2
|
please i cant understand session - El Forum - 01-20-2009 [eluser]mrphp[/eluser] any one please explain ci session to me because i red the user guide and i cant understand session from it please i cant understand session - El Forum - 01-20-2009 [eluser]Tri Dang[/eluser] Greetings! Can you let others know what particular points that you don't understand? please i cant understand session - El Forum - 01-20-2009 [eluser]mrphp[/eluser] 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); } function login () { $name=$_POST['name']; $pass=$_POST['password']; $users = array('username' => $_POST['name'],'logged_in' => TRUE); $sql=$this->db->query("select * from users where user_name='$name' and password='$pass'"); if($sql->num_rows()==1) { echo "hello".$name ; echo anchor('index.php','back to home'); } else { echo "wrong user name or password"; } } please i cant understand session - El Forum - 01-20-2009 [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 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')){ please i cant understand session - El Forum - 01-20-2009 [eluser]mrphp[/eluser] iam sorry i think iam stupid in this point but if you can to put a full example in using session it will be greate as i mention i have two function index and login please i cant understand session - El Forum - 01-20-2009 [eluser]whobutsb[/eluser] They are easy. Two basic functions reading and writing. To write a session you use: Code: $this->session->set_userdata('variable_name_of_session', 'value_of_session'); To read a session: Code: $this->session->userdata('variable_name_of_session'); Thats pretty much all there is to it. please i cant understand session - El Forum - 01-20-2009 [eluser]Michael Wales[/eluser] Code: class Home extends Controller { please i cant understand session - El Forum - 01-20-2009 [eluser]whobutsb[/eluser] [quote author="Michael Wales" date="1232510115"] Code: class Home extends Controller { Nicely explained. please i cant understand session - El Forum - 01-20-2009 [eluser]mrphp[/eluser] i add a link in the index function to go to login page in login page appear 'No session was found' but i think it would be 'This is some text' Quote:class Home extends Controller { please i cant understand session - El Forum - 01-20-2009 [eluser]mrphp[/eluser] ok I modify the code and it work with me Quote:class Home extends Controller { now the code work very good but i want to change $this->session->set_userdata(array('text' => 'This is some text')); to $this->session->set_userdata(array('text' =>$this->input->post('name')); post('name') will hold data in one page only but i want to have the data in every page |