i want to set my session data in my view but Conditionally, so in javascript portion of my view i have
$('#demo').click(function(){
$this->session->set_userdata('sample',10);
});
However , whenever i refresh my page , without clicking the button , the session data , “sample” is set, is there a way i can get this session data set ONLY after i click the button ?
Thank you
You’re mixing Javascript and PHP (client-side and server-side). You can do it by using Ajax like this:
And in your
Mycontroller.phpfile, you should create a function called “sessions”:If you need to pass information from Javascript to PHP:
More information about Ajax in JQuery http://api.jquery.com/jQuery.ajax/
EDIT:
To check if a session variable exists in CodeIgniter:
Section “Retrieving Session Data” http://codeigniter.com/user_guide/libraries/sessions.html