![]() |
help with boolean - 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: help with boolean (/showthread.php?tid=26739) |
help with boolean - El Forum - 01-21-2010 [eluser]KrizzAngel[/eluser] im really confused. i know im a noob XD anyways can u guys help me with this: Quote:function checker()i made that function but i dont know how to use it to my index() and other page lol.. what i want to happen is if a user try to access certain page it will redirect to login(home page) if user is not logged in and on the other hand i dont want to access home page if the user is still logged in. help with boolean - El Forum - 01-21-2010 [eluser]bretticus[/eluser] [quote author="KrizzAngel" date="1264151612"] Code: function checker() Code: $this->session->userdata('is_logged_in') ...according to the manual this call will either return the value you set in it (boolean perhaps?) or FALSE if that session key (is_logged_in) is not found. isset() simply checks to see if the variable is set. Since you set it before your if statement, Code: !isset($is_logged_in) Code: isset($is_logged_in) In fact, as long as you are setting boolean values to the session item, you can probably make this function a one-liner: Code: function checker(){ help with boolean - El Forum - 01-22-2010 [eluser]Eric Cope[/eluser] if this is always checked, consider placing it in the constructor. help with boolean - El Forum - 01-22-2010 [eluser]KrizzAngel[/eluser] constructor?? i dont know if u guys gets what i mean hehe.. i just dont know how "return" value works.. for example i was coding my index() function. i wrote Quote:function index() does this mean that if the checker returns true it will continue to load the home page?? what if its false.. how can i express the other code so that it will load another page if its false/ help with boolean - El Forum - 01-22-2010 [eluser]n0xie[/eluser] [quote author="KrizzAngel" date="1264174356"] does this mean that if the checker returns true it will continue to load the home page?? what if its false.. [/quote] No it will just return TRUE or FALSE. Since you don't actually do anything with the function, the return value gets lost. Quote:how can i express the other code so that it will load another page if its false/ Try this: Code: function index(){ help with boolean - El Forum - 01-22-2010 [eluser]KrizzAngel[/eluser] ok ty.. ill try that.. help with boolean - El Forum - 01-22-2010 [eluser]Yorick Peterse[/eluser] [quote author="KrizzAngel" date="1264174356"]constructor?? i dont know if u guys gets what i mean hehe.. i just dont know how "return" value works.. for example i was coding my index() function. i wrote Quote:function index() does this mean that if the checker returns true it will continue to load the home page?? what if its false.. how can i express the other code so that it will load another page if its false/[/quote] The return statement, as the name might suggest, does nothing more than returning a certain value (or whatever it's supposed to return). If you place this statement in a function (as shown below), it will skip everything after the return statement. Code: <?php The difference between return and echo is that echo outputs it to the screen (or console) whereas return does nothing more than returning it. You can use the return statement as following: Code: <?php help with boolean - El Forum - 01-22-2010 [eluser]KrizzAngel[/eluser] ok that was clear.. i got it now.. but another problem i got here.. can u guys assess my code.. Quote: function index()*edited ok i thought its my logout that had a problem but its not.. i closed my browser but it seems that index always redirect me to upanel XD help with boolean - El Forum - 01-22-2010 [eluser]KrizzAngel[/eluser] *bump* |