beerLantern beerLantern - 3 years ago 284
PHP Question

Codeigniter - Weird parameter '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.

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!
// 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);


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

Answer Source

The browser sends a request to your web server

GET /favicon.ico HTTP/1.1

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

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download