Note that there are some explanatory texts on larger screens.

plurals
  1. PORedirect in PHP Codeigniter
    text
    copied!<p>I have some problems using Code Igniter and I feel there is something I don't understand because I can't get my redirects and my headers to work. Here is the situation :</p> <p>When site is entered, the default "home" controller is called.</p> <pre><code> public function initialize() { printf("CONSTRUCTION OF HOME CONTROLLER - \n"); // print_r($_SESSION); //TODO : CONSIDER CREATING A LIBRARY TO AVOID WRITING THIS OFTEN. NOT // SESSION TROLLING DETECTION if( isset($_SESSION['banana'])) { echo "SPLITTING THE TRUTH"; } // GETTING AS SERIOUS AS GREG if( !isset($_SESSION['username'])) { printf("USERNAME IS NOT SET. SETTING UP THE LOGIN PAGE. \n"); redirect('home_invite'); } else { $this-&gt;load-&gt;view('welcome_message'); } } public function index() { //INITIALIZING THE PATH USED FOR THIS NAVIGATION printf("TROLLING THE BEGINNING OF THIS CONTROLLER HOME - "); $this-&gt;initialize(); printf("TROLLING THE END OF THIS CONTROLLER HOME - "); //TODO : CONSIDER CREATING A LIBRARY TO AVOID WRITING THIS OFTEN } </code></pre> <p>Index calls initialize who verify if the user has already a session variable with username in it. If that's the case, we would proceed to check his level of privileges, etc, and load corresponding view. Thats not the problem.</p> <p>If the session is not started, I want to load the "login" view, called here "home_invite". And I want to redirect him to that page. But if I use this code, the page will show a 404 error.</p> <p>If I use <code>$this-&gt;load-&gt;view('home_invite')</code>, it works, but I don't understand and I feel it isn't what I want it to do. </p> <p>Why is redirect not working in this context?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload