Codeigniter - 奇怪的参数'favicon.ico' [英] Codeigniter - Weird parameter 'favicon.ico'

查看:285
本文介绍了Codeigniter - 奇怪的参数'favicon.ico'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Codeigniter PHP框架。
我有用于显示页面的typicall Pages控制器。我还添加了用于存储在会话变量中的代码,用户在登录前的页面。事情是我得到作为参数favicon.ico没有意义,因为被调用的页面是登录,并显示后,。

I am working with Codeigniter PHP framework. I have the typicall Pages controller for displaying pages. I also added code for storing in the session variable in which page was the user before login. The thing is I'am getting as parameter 'favicon.ico' which make no sense because the page that was called was 'login' and displays well after that.

首先作为一个临时解决方案,我检查了'favicon.ico'的$ page变量,奇怪的是,在检查后,我在$ page变量'登录'。这是非常奇怪,我不得不第二次检查登录页面,你看到这里使其工作。 :

First as a temporary solution I checked the $page variable for the 'favicon.ico', and the weird thing was that after checking it I had inside the $page variable 'login'. It was very weird, I had to make a second check for login page as you see here for making it work. :

    public function view($page = 'index')
{
    if($page != 'favicon.ico'){
        if($page != "login"){
            $this->session->set_userdata('actual_page', $page);
        }               
    }

    if ( ! file_exists('application/views/pages/'.$page.'.php'))
    {
        // Whoops, we don't have a page for that!
        $page="error";
    }
    // guardamos la página actual en la sesión


    $data['title'] = ucfirst($page); // Capitalize the first letter

    $this->load->view('templates/header', $data);
    $this->load->view('pages/'.$page, $data);       
    $this->load->view('templates/footer', $data);

}

我的问题是,发生了什么?为什么如果我只检查$ page =='登录'它不工作。这太疯狂了。

My question is, what is happening? Why if I only check for $page == 'login' it doesn't work. This is crazy.

推荐答案

浏览器向您的网络服务器发送请求

The browser sends a request to your web server

GET /favicon.ico HTTP/1.1

a href =http://en.wikipedia.org/wiki/Favicon =nofollow> Favicon 。

in order to retrieve Favicon. You can change the location of favicon with a link tag as described in the wikipedia article.

尝试移动 file_exists 检查之前设置会话数据?网络应用程序需要能够处理丢失的资源并相应地返回404。

Try moving the file_exists check before you set the session data? The web application will need to be able to handle missing resources and return 404 accordingly.

这篇关于Codeigniter - 奇怪的参数'favicon.ico'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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