0

Is it possible to put PHP code into raw images?

For example: http://gifsec.com/wp-content/uploads/GIF/2014/05/GIF-When-white-guys-dance.gif

If you go to that url you'll just see the raw image on a white page. Is it possible to somehow put code into this raw page? For example, you may want to put Google analytics tracking into raw image files so you can track people on reddit sharing raw files.

Mike Laren
  • 8,028
  • 17
  • 51
  • 70

5 Answers5

0

Not that I know of, what you may want to consider is having people share the link to that file so they can download it and then put code into the page that link redirects to that tracks or counts visitors. Tracking the visitor is harder and leads into ethical issues, so I would just set up google analytics and put their code into that page.

pbcub1
  • 10
  • 3
0

No,

http://gifsec.com/wp-content/uploads/GIF/2014/05/GIF-When-white-guys-dance.gif

is a resource on your server. that URL simply directs the browser to where the image is stored on the server.

to achieve what you want. simply create a page and include the image into

http://gifsec.com/GIF-When-white-guys-dance

<img src=''> on this page you can then add your Google analytic code.

Images are transferred from server to browser with binary encoding. this is why it will not work how you are thinking

Jay P
  • 596
  • 7
  • 23
0

You can hide anything you want in an image file. This is called steganography. The problem is that the code won't be executed unless it's uploaded to a server that is specifically set up to extract and run it.

rjdown
  • 9,162
  • 3
  • 32
  • 45
0

It's not silly, just difficult. What you would have to do is use a PHP script to process it back. As such, your dance.gif would become dance.php and you would link to that. It will add some overhead to your server to do this so just be aware, however, this would allow you to track it via PHP. You could then import that data into Google Analytics at a later date.

Here's some pseudo code (we'll call this dance.php)

<?php
//Insert some tracking here, like a Database INSERT statement
$img = imagecreatefromgif('/path/to/dance.gif');
header('Content-Type: image/gif');
imagegif($image);
imagedestroy($image);

Then in your HTML

<img src="dance.php">
Machavity
  • 30,841
  • 27
  • 92
  • 100
  • Wouldn't you need to generate all the php files? I could redirect any raw .gif request to .php. But I'd need a program that will auto generate a .php file with some code in, for each .gif file on my site. – user3305089 Apr 12 '15 at 01:17
0

What you need is called pixel tracking also called web bug.
Take a look at this answer:

https://stackoverflow.com/a/13079838/797495

Community
  • 1
  • 1
Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268