tags:

views:

42

answers:

3

Alright, currently I'm using GD to create a PNG image that logs a few different things, depending on the GET data, for example: http://example.com/file.php?do=this will log one thing while http://example.com/file.php?do=that will log another thing.

However, I'd like to do it without GET data, so instead http://example.com/dothis.php will log one thing, and http://example.com/dothat.php will log the other.

But on top of that, I'd also like to make it accessible via the JPG file extension. I've seen this done but I can't figure out how. So that way http://example.com/dothis.JPG will log one thing, while http://example.com/dothat.JPG logs the other.

The logging part is simple, of course. I simple need to know how to use filenames in place of the GET data and how to set the php file to be accessible via a jpg file extension.

+1  A: 

filename is accessible via $_SERVER array (I hope you can explore this array and find suitable variable)

while extension trick is web-server responsibility
For the Apache module API it could be

RemoveHandler .jpg
AddType application/x-httpd-php .jpg
Col. Shrapnel
Can I just put this in my httpd.conf like this:`<Directory /home/admin/teamwaffle/booter/login/images/>RemoveHandler .jpgAddType application/x-httpd-php .jpg</Directory>`
Rob
Worked. Kind of. It broke the image. I switched it up to a png and now I get **The image “http://mywebsite/images/png.png” cannot be displayed, because it contains errors.** and as a jpg, it only displays the link.
Rob
Nevermind fixed that =]
Rob
Thanks a lot Col. Shrapnel
Rob
A: 

If you don't want to have duplicate scripts / links, and the webserver is apache, then its mod_rewrite you need, e.g.

RewriteEngine On
RewriteRule ^doth/(.*) index.php?page=$1 [L]

C.

symcbean
A: 

If you want to embed PHP inside a file using the extension .jpg, you will need to instruct your web server to parse .jpg files as PHP. One way to do this, if you are using Apache, is to add the following to an .htaccess file in the directory where the files are located:

addtype application/x-httpd-php .jpg .php

Or you can add it to your server configuration. See this page for details on htaccess for Apache.

Next, write your scripts such that they log the appropriate data. In your example, it looks like you won't need GET data anymore, and the script will log different data based simply on the fact it was called. i.e. dothis.jpg "knows" to log this data, whereas dothat.jpg logs that data.

dothis.jpg:

<?php
    header("Content-type: image/jpeg");
    // log "this" code
    $img = imagecreate($x, $y); // example
    // GD image generation code
    imagejpg($img);
?>

dothat.jpg:

<?php
    header("Content-type: image/jpeg");
    // log "that" code
    $img = imagecreate($x, $y); // example
    // GD image generation code
    imagejpg($img);
?>
JYelton