Php – Why I am not able to see source code with FF when I have this if statement

firefoxPHPsession

When I add this code, I am not able to see source code with Firefox.

Can anyone tell me why please?

if (!isset($_SESSION['userid']) || $_SESSION['userid'] < 1){
        $this->session->set_flashdata('error',"You must log in!");  
            redirect('welcome/verify','refresh');
        }

This code is in the following controller.

class Dashboard extends Controller {
  function Dashboard(){
    parent::Controller();
    session_start();

    if (!isset($_SESSION['userid']) || $_SESSION['userid'] < 1){
    $this->session->set_flashdata('error',"You must log in!");  
        redirect('welcome/verify','refresh');
    }
  }

The whole page is blank; no HTML tags or content are seen.

Best Answer

The code you have posted is server-side code, it is parsed and run by the server hosting the page and is never sent to the browser (in your case Mozilla Firefox). It only sees the client side code that is sent from the server. Consider the following example:

<?php echo file_get_contents("test.html"); ?>

This is php code, which runs server side. The file_get_contents php function opens a file and reads the contents. The echo command sends a string to the browser. Put together, the line opens the file test.html and outputs it to the browser as the response.

The contents of test.html are as follows:

<html>
  <body>
    Hello World!
  </body>
</html>

When you choose to view the source, you don't see the line <?php echo file_get_contents("test.html"); ?>, even though that is the true source of the page you are viewing. You actually see the contents of test.html, because this is the data that is returned in the response.

Related Topic