My random sig/avatar script and .htaccess

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
FrankieX
Forum Newbie
Posts: 2
Joined: Mon Feb 20, 2006 9:06 am

My random sig/avatar script and .htaccess

Post by FrankieX »

I have been trying to make a script which will allow me to have a random/rotating sig with matching avatar on a forum I frequent, with mixed success. I have managed to make one based around cookies but that unfortunately is stopped from working by Firefox's (and presumably other browsers') tools to stop tracking cookies. My solution to this has been to have the sig and avatar use the time to coordinate, resulting in this script:

Code: Select all

<?
$f[] = "http://www.mywebhost.com/sig1.gif";
$f[] = "http://www.mywebhost.com/sig2.gif";
$f[] = "http://www.mywebhost.com/sig3.gif";


$currdate=getdate();
$currhours=$currdate["hours"];
$currsigs=count($f);
$fnum=$currhours%$currsigs;

$file=$f[$fnum];

$imageInfo = pathinfo($_GET['file']);
$contentType = 'Content-type: '.$imageInfo['extension'];
header ($contentType);
header("Pragma: no-cache");
header("Expires: Sun, 18 May 1980 16:32:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
readfile( $file );
?>
This works perfectly as a .php file on my server. My problem is this: the forum I want to use it on doesn't allow the php extension inside the (IMG) tags so I need the script to run from a file with an image extension (I've chosen .png). My host allows .htaccess use, so this is what is inside .htaccess:

Code: Select all

AddHandler application/x-httpd-php .png
Just to be clear, this definitely works on my server. In fact, the one I made using cookies ran from a png file in the same directory with almost the exact same code. These are the only lines NOT in my previously working code:

Code: Select all

$currdate=getdate();
$currhours=$currdate["hours"];
$currsigs=count($f);
$fnum=$currhours%$currsigs;

$file=$f[$fnum];
My problem is that my host is not parsing this file, and I must conclude it is due somehow to these lines. My host is using PHP 4.4.2 and Apache 1.3.34 (Unix). Any help you could give me to get this working would be great
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Is your host running PHP in CGI? I'd doubt that. AddHandler is for CGI. AddType is for ISAPI (modules.)
FrankieX
Forum Newbie
Posts: 2
Joined: Mon Feb 20, 2006 9:06 am

Post by FrankieX »

I'm sorry for not replying sooner, I thought I had put this thread on watch but was clearly mistaken.

After asking my host in a vague manner about this (I'm not sure if it would be against their TOS) it appears that I can only do AddTypes (and even Rewrites/Aliases) either within html or non-html files. In other words, I can't make a image link to run a .php file, but I can do so for a .htm link.

Thanks for the reply, and sorry again for the delay
Post Reply