Because i always get from time to time pms asking about how do i make the avatar changing all the time i decided to write a little guide, its not that hard:
First you need webspace where you can run something like php and which allows you to use the mod rewrite or to change extensions.
Then you need to write a little script which handles the img output in my case it looks like this:
it gets a random number between 1-71 which is the number of pictures i have in the database, and get the img and send the context to the browser.
It is important to send the Cache-Control so the browser dont cache that image, otherwise it would always show the same img untill the browser cache expires.
You should maybe builtin a referer check as well, so that your image isnt missused on other sites by other ppl.
if you want use such a check just put it in front of the other code, in this example it would check if the refer is set and is elitepvpers.com or empty if it doesnt match it would show the file warning.gif and stops the execution of the script.
The reason for the empty referer check is that some ppl use tools or browsers which clears the referer and we dont want to show them the warning.
Next todo is then to activate that the webserver redirect the image to the scripts, which you can define either in the config file of the webserver if you have the access to it or in the .htaccess
this will redirect all [Only registered and activated users can see links. Click Here To Register...] to image.php and execute the script to print out the image.
a more advance version would be for example:
this would redirect image1.jpg to image.php?p=1 so that you can overgive paramters to the files to use 1 file for diff things, i use for example the same file for avatar and signature.
the [0-9] means all numbers between 0-9 are valid and the [1,5] that the number can be 1-5 positions long, so from 0-99999
If a request doesnt match that rule it wont rewrite it, for example image22222222.jpg will just look for that file.
First you need webspace where you can run something like php and which allows you to use the mod rewrite or to change extensions.
Then you need to write a little script which handles the img output in my case it looks like this:
Code:
$mysql_host = ""; $mysql_user = ""; $mysql_password = ""; $mysql_db = ""; @mysql_connect($mysql_host, $mysql_user, $mysql_password); @mysql_select_db($mysql_db); $ran = rand(1,71); $data = mysql_query('SELECT pic FROM images where id='.$ran); $wfile = mysql_result($data,0,'pic'); header("Cache-Control: no-cache, must-revalidate"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Content-type: image/gif"); $img=file_get_contents('./img/'.$wfile); echo $img;
It is important to send the Cache-Control so the browser dont cache that image, otherwise it would always show the same img untill the browser cache expires.
You should maybe builtin a referer check as well, so that your image isnt missused on other sites by other ppl.
Code:
$such = strpos($_SERVER['HTTP_REFERER'], 'elitepvpers.com');
if(isset($_SERVER['HTTP_REFERER']) && $such === false && $_SERVER['HTTP_REFERER']!=''){
* * * *header("Cache-Control: no-cache, must-revalidate");
* * * * header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
* * * * header("Content-type: image/gif");
* * * * $img=file_get_contents('./warning.gif');
* * * * echo $img;
* * * * exit;
}
The reason for the empty referer check is that some ppl use tools or browsers which clears the referer and we dont want to show them the warning.
Next todo is then to activate that the webserver redirect the image to the scripts, which you can define either in the config file of the webserver if you have the access to it or in the .htaccess
Code:
RewriteEngine on RewriteRule ^image\.jpg$ image.php
a more advance version would be for example:
Code:
RewriteEngine on
RewriteRule ^image([0-9]{1,5})\.jpg$ image.php?p=$1
the [0-9] means all numbers between 0-9 are valid and the [1,5] that the number can be 1-5 positions long, so from 0-99999
If a request doesnt match that rule it wont rewrite it, for example image22222222.jpg will just look for that file.