Dynamic Favicon

mastram

New Member
Dynamic Favicon - vBulletin.org Forum

Version: 3.7.x

>> Note: This requires Apache & mod rewrite. If you do not have these, I cannot help you. <<

What does it do?
This little code snippet and directory setup, combined with mod rewrite will allow you to dynamically generate a favicon for your site based on the user's style preference.

What is required for this to run properly?
Apache & mod rewrite. If you do not have these, the mod will not function properly.

Absolutely no change or addition in vBulletin code is necessary.

For those of you who want to skip code addition and upload the files, I've attached the PHP code to the post, however you will need to be sure you rename htaccess.txt to .htaccess once you've uploaded it. If you have an existing .htaccess file, please do not overwrite it, instead follow the instructions I've provided here. Also, please read the PHP code section and make sure you update the file paths if necessary.

First, create a new file in the root directory of your forum called favicon.php
If you do not know where this is, navigate to vBulletin Options -> Site Name / URL / Contact Details and look at the URL provided for Forum URL. This is the root directory of your forum.

In this new file, you will need to add the following code.

>> NOTE: YOU WILL NEED TO CHANGE THE FILE PATHS FOR THIS TO FUNCTION PROPERLY. <<
To do this, locate /skins/default/misc/favicon.ico
You will need to change this to the misc images directory path of your DEFAULT FORUM SKIN. For example, if the directory path is /images/default/misc/ then you will need to change it to /images/default/misc/favicon.ico

PHP:
<?php
require_once('global.php');
$favicon = (file_exists(".{$stylevar['imgdir_misc']}/favicon.ico") ? $vbulletin->options['bburl'].$stylevar['imgdir_misc'].'/favicon.ico' : $vbulletin->options['bburl'].'/skins/default/misc/favicon.ico');
$ico = @file_get_contents($favicon);
header("Content-Type: image/x-icon");
echo $ico;
?>
Now, save favicon.php and create a new file in the same directory as this one. We will call this file .htaccess
If you already have a .htaccess file, you will need to make a few additions to it to make sure the PHP code we just added is properly used.

At the top of your .htaccess file, add the following lines.

Code:
RewriteEngine on
RewriteRule favicon.ico favicon.php
If you already have mod rewrite enabled, RewriteEngine on can be omitted from this entry.

Now that we've set up the code and instructed Apache to look at favicon.php for our favicon, we need to set up the directory structure. Note that if you do not have a favicon in all directories, the code will automatically use the favicon from your default skin.

>> Note: You will need to leave favicon.ico in your root directory along with favicon.php. It does not matter what this icon looks like, it merely matters that it exists in the directory for purposes of mod rewrite. <<

Simply locate your /skins/style/misc/ directories, and add your own custom favicon for each one until you are satisfied with them.

Note that the change may not be immediate, depending on your browser. You may have to clear history and/or cache for it to update, and in some cases, it may not update at all, or for awhile even.

This mod is final. No updates will be made except for newer variable names.
 
Top