0

I am using PHP to set my favicon by using

<link rel="shortcut icon" href="<?php echo "/SysFiles/img/ico/". $favicon; ?>">

This will work properly on Firefox but not on Chrome. How can I get Chrome to reget the icon whenever the icon is changed?

EDIT: This file sits in /SysFiles/navbar.php, it is PHP included on every page on the server including the page I am testing on

EDIT: navbar.php

    <?php
        session_start();
        if ($_COOKIE['darktheme'] == "1") {
          $_SESSION['darktheme'] = true;
          $_SESSION['SETHEME'] = 1;
        } else {
          $_SESSION['darktheme'] = false;
          $_SESSION['SETHEME'] = 1;
        }
    $addr = "http://" . $_SERVER['SERVER_ADDR'];
    $myfile = fopen("$addr/Data/Points/makarios", 'r');
    $makarios = fgets($myfile);
    fclose($myfile);

    $myfile = fopen("$addr/Data/Points/sozo", 'r');
    $sozo = fgets($myfile);
    fclose($myfile);

    $myfile = fopen("$addr/Data/Points/kaleo", 'r');
    $kaleo = fgets($myfile);
    fclose($myfile);

    $myfile = fopen("$addr/Data/Points/katharos", 'r');
    $katharos = fgets($myfile);
    fclose($myfile);

    $myfile = fopen("$addr/Data/Points/charis", 'r');
    $charis = fgets($myfile);
    fclose($myfile);

    $myfile = fopen("$addr/Data/Points/agape", 'r');
    $agape = fgets($myfile);
    fclose($myfile);

    $cookie_name = "REENT";
    $cookie_value = $makarios + $sozo + $kaleo + $katharos + $charis;
    if ($cookie_value != $_COOKIE["REENT"]) {
    $newcooksit = true;
    }
    setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/");
    if ($newcooksit == true) {
      echo '<br><br><br><div class="alert alert-info"><strong>Look!</strong> Points have changed since your last visit! Check the new values <a href="results.php">here!</a> </div>';
    } else {
      echo '<br><br><br>';
    }
    ?>


<?php
$sid = $_SERVER['SERVER_ADDR'];
$items = ["/SysFiles/img/ico/makarios.ico", "/SysFiles/img/ico/agape.ico", "/SysFiles/img/ico/kaleo.ico", "/SysFiles/img/ico/charis.ico", "/SysFiles/img/ico/sozo.ico", "/SysFiles/img/ico/katharos.ico"];
//echo $items[array_rand($items)];
$ico = $items[array_rand($items)];
 ?>
<head>
  <meta charset="utf-8">
  <?php $favicon = $_COOKIE['houseicn']; ?>
<link rel="icon" href="<?php echo "/SysFiles/img/ico/". $favicon; ?>">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  <?php
  if ($_SESSION['darktheme'] == true) {
  ?>
  <link rel="stylesheet" type="text/css" href="SysFiles/sys/darktheme.css">
  <?php
}
?>
</style>
</head>
<?php
if ($_SESSION['darktheme'] == true) {
?>
<font color='white'>
  <?php
}
if ($_SERVER['SETHEME'] == 1) {
  if ($_SERVER['SETHEMED'] !== 1) {
  header("Refresh:0");
}
  $_SERVER['SETHEMED'] == 1;
}
 ?>



<?php
if ($_SESSION['ACCESS'] > 0) {
 ?>
 <nav class="navbar navbar-inverse navbar-fixed-top">
   <div class="container-fluid">
     <div class="navbar-header">
       <a class="navbar-brand" href="index.php">House Points</a>
     </div>
     <ul class="nav navbar-nav">
       <li><a href="http://<?php echo $_SERVER['SERVER_ADDR']; ?>/index.php">Home</a></li>
       <li><a href="http://<?php echo $_SERVER['SERVER_ADDR']; ?>/results.php">Current Results</a></li>
       <li><a href="http://<?php echo $_SERVER['SERVER_ADDR']; ?>/archive.php">Old Results</a></li>
       <li><a href="http://<?php echo $_SERVER['SERVER_ADDR']; ?>/submit.php">Teacher Submission</a></li>
       </ul>
     <ul class="nav navbar-nav navbar-right">
       <li><a href="http://<?php echo $_SERVER['SERVER_ADDR']; ?>/logout.php"><span class="glyphicon glyphicon-log-out" aria-hidden="true"></span> Logout</a></li>
       <li class="dropdown">
   <a class="dropdown-toggle" data-toggle="dropdown" href="#">About
   <span class="caret"></span></a>
   <ul class="dropdown-menu">
 <?php include "sysinfo"; ?>
   </ul>
 </li>
 </ul>
   </div>
 </nav>
 <?php } else { ?>
<nav class="navbar navbar-inverse navbar-fixed-top">
  <div class="container-fluid">
    <div class="navbar-header">
      <a class="navbar-brand" href="index.php">House Points</a>
    </div>
    <ul class="nav navbar-nav">
      <li><a href="http://<?php echo $_SERVER['SERVER_ADDR']; ?>/index.php">Home</a></li>
      <li><a href="http://<?php echo $_SERVER['SERVER_ADDR']; ?>/results.php">Current Results</a></li>
      <li><a href="http://<?php echo $_SERVER['SERVER_ADDR']; ?>/archive.php">Old Results</a></li>
      <li><a href="http://<?php echo $_SERVER['SERVER_ADDR']; ?>/submit.php">Teacher Submission</a></li>
    </ul>
    <ul class="nav navbar-nav navbar-right">
      <li class="dropdown">
  <a class="dropdown-toggle" data-toggle="dropdown" href="#">About
  <span class="caret"></span></a>
  <ul class="dropdown-menu">
<?php include "sysinfo"; ?>
  </ul>
</li>
</ul>
  </div>
</nav>
<?php }  ?>
  • You might just need to set `type="image/ico"` in the link element – James Paterson Apr 15 '16 at 00:15
  • Sadly, that didn't work. – DatOneLefty Apr 15 '16 at 00:17
  • @JamesPaterson - Depends on the file type (extension) that is being used. OP, what is the extension (file type) of `$favicon`? – mferly Apr 15 '16 at 00:17
  • it equals hiddeniconname.ico – DatOneLefty Apr 15 '16 at 00:18
  • 1
    @Marcus I guessed .ico because of the file path. According to https://bugs.chromium.org/p/chromium/issues/detail?id=51270 there is a bug preventing chrome from getting the favicon not through a web path. Try fully qualifying the URL like "http://somewebsite.com/SysFiles/img/ico/". $favicon; – James Paterson Apr 15 '16 at 00:19
  • i tried ` " />` and it still kept the original icon – DatOneLefty Apr 15 '16 at 00:22
  • Maybe try uploading the file to a web server, and getting it from there? If you use the stackoverflow favicon URL - http://cdn.sstatic.net/Sites/stackoverflow/img/favicon.ico - Does it work? – James Paterson Apr 15 '16 at 00:24
  • I have no idea why, but this did not work... – DatOneLefty Apr 15 '16 at 00:32
  • When you say *reget*, do you mean you mean *refresh* after you've changed the icon? How often are you changing the icon? WHy is the icon name stored in a variable to begin with? It's the type of thing that *typically* gets updated when re-branding a company.. so almost never. Hardly needs to be a variable entity. With that said, are you sure `$favicon` is holding the correct value? – mferly Apr 15 '16 at 00:42
  • The icon is changed by request for each user and their chosen icon is stored in a cookie. the cookie contains only the name of the file like icon1.ico. It works on firefox and not chrome. so it is the correct value – DatOneLefty Apr 15 '16 at 01:02

2 Answers2

1

According to bugs.chromium.org/p/chromium/issues/detail?id=51270 there is a bug preventing Chrome from getting the favicon not through a web path.

Try fully qualifying the URL like:

<link rel="shortcut icon" href="<?php echo "http://example.com/SysFiles/img/ico/". $favicon; ?>">
James Paterson
  • 2,652
  • 3
  • 27
  • 40
0

I, personally, haven't used rel="shortcut icon" in as long as I can remember. Simply using:

<link rel="icon" href="<?php echo "/SysFiles/img/ico/". $favicon; ?>">

Should do the trick. Just tested and works (as it always has for me) in both Chrome and Firefox. Relative path, too. Not absolute.

Methods to bust the cache, if need be:

  • Change the filename, eg. /favicon.ico to favicon2.ico
  • Enter the direct path to the .ico in the browser and refresh the page multiple times, ie. Open Chrome/Firefox/whatever and enter http://example.com/path/to/favicon.ico into the address bar. Hit enter. Then hit Ctrl+Shift+R multiple times until it changes.
  • Append a querystring to the .ico path in <link>, eg. <link rel="icon" href="http://example.com/path/to/favicon.ico?foo=bar">

Reference: https://en.wikipedia.org/wiki/Favicon

mferly
  • 1,646
  • 1
  • 13
  • 19
  • `">` did not change the icon. I made sure there is nothing in /favicon.ico – DatOneLefty Apr 15 '16 at 00:28
  • OK, just try forcing the refresh by appending a query string: `?foo=bar">` – mferly Apr 15 '16 at 00:35
  • Why don't you just try changing the filename completely then for the new icon, ie. `favicon.ico` to `myNewFavIcon.ico`. Are you sure you're overwriting the correct, old file with the new version on the server, per the folder that you're pointing to? – mferly Apr 15 '16 at 00:40
  • i just tried to remove the line linking the icon, and firefox for some reason returns to the first icon even though there is no favicon.ico in the root. All of the .icos are in the same file. – DatOneLefty Apr 15 '16 at 00:43
  • I don't know then, bud. At this point all you can do is ensure there are no erroneous .ico's floating around, and that you're properly overwriting any existing favicon.ico file with the new version, and that you're correctly pointing to it via ``. Aside from that, without me getting into your system and looking around, there's not a whole lot I can do as I'm thinking it's something very insignificant that you're overlooking. – mferly Apr 15 '16 at 00:46
  • Last ditch, try removing the *type* from the `. Made edit above. – mferly Apr 15 '16 at 00:48
  • it didn't work. I will try to find a way to make it so that i only need one icon – DatOneLefty Apr 15 '16 at 01:04
  • Oh so you're dynamically changing the icon from one page to the next? Do you have any internal caching systems in place? Post your PHP code from navbar.php – mferly Apr 15 '16 at 01:11