当我有这个if语句时,为什么我不能用FF看到源代码? [英] Why I am not able to see source code with FF when I have this if statement?

查看:114
本文介绍了当我有这个if语句时,为什么我不能用FF看到源代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有谁能告诉我为什么要这样做?

  if(!isset($ _ SESSION ['userid'])|| $ _SESSION ['userid']< 1){
$ this- > session-> set_flashdata('error',您必须登录!);
重定向('welcome / verify','refresh');





这个代码位于下面的控制器中。

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

if(!isset($ _ SESSION ['userid'])|| $ _SESSION ['userid']< 1){
$ this-> session-> set_flashdata '错误','您必须登录!
重定向('welcome / verify','refresh');




$ b整个页面都是空白的;没有看到HTML标签或内容。

解决方案

您发布的代码是服务器端代码,它被解析并运行托管该页面的服务器并不会被发送到浏览器(Mozilla Firefox)。它只能看到从服务器发送的客户端代码。考虑下面的例子:

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

这是运行服务器端的php代码。 file_get_contents php函数打开一个文件并读取内容。 echo命令向浏览器发送一个字符串。放在一起,这一行打开文件 test.html 并将其输出到浏览器作为响应。



test.html的内容如下:

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

当您选择查看源代码时,您看不到 <?php echo file_get_contents(test.html); ?> ,即使这是您正在查看的页面的真实来源。您实际上可以看到test.html的内容,因为这是响应中返回的数据。


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.

解决方案

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.

这篇关于当我有这个if语句时,为什么我不能用FF看到源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆