![]() |
Why my session is not working with error message-Cannot modify header information - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Why my session is not working with error message-Cannot modify header information (/showthread.php?tid=19691) |
Why my session is not working with error message-Cannot modify header information - El Forum - 06-16-2009 [eluser]manojchakri[/eluser] Hi all. Now I wrote a login validation form with database checking.Now after successfully logging in for the user I want to create session variable and get the user data from the session information. But When I am creating session it is giving error like "Cannot modify Header Information".My code is like this. Controller: Code: class Form extends Controller But when session is setting user data then the error like this is coming Quote:A PHP Error was encounteredWhat should I do? I need to display the logged in user name like "welcome <user>" on every page and a logout link which should close the session and display "welcome guest" on every page and login link.Please help me with some sample code..Thanks in advance. Why my session is not working with error message-Cannot modify header information - El Forum - 06-16-2009 [eluser]Dam1an[/eluser] This comes up all the time (search anyone?) It's cause because you prematurely sent some output to the screen, this can be anything, from a string, to a whitespace (eg if you have a newline before the opening PHP tags or after the closing tag) Why my session is not working with error message-Cannot modify header information - El Forum - 06-16-2009 [eluser]manojchakri[/eluser] Ok I got it.Thank you.But How do you know some session data is already set in Codeigniter.Is there any thing like isset() here?? Why my session is not working with error message-Cannot modify header information - El Forum - 06-16-2009 [eluser]Dam1an[/eluser] If you use CI sessions, it will return false if you try to get something which hasn't been set, so you can do something like Code: if($this->session->userdata('logged_in')) { (You could also rewrite this using a ternary operator if you prefer) |