Way to put PHP code into raw image pages - php

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.

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.

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

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.

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">

What you need is called pixel tracking also called web bug.
Take a look at this answer:
https://stackoverflow.com/a/13079838/797495

Related

How to output files from Dropbox with Dropbox PHP Core SDK

I want to output a file from Dropbox onto my website with Dropbox PHP Core SDK. To give an example, I upload an image to Dropbox. Now, how do I display that image to my website from Dropbox's servers. Keep in mind, I don't want to download this file from Dropbox and then display that image. Is it possible to display an image or another file directly from Dropbox using Dropbox PHP Core SDK?
EDIT:Would you mind being more clear on #1
How do I use the custom URL?
Can I do this: header("location: $url);
Is this how you use the custom url? Thanks!
Using the PHP Core SDK, the main way of accessing file content is using the getFile method, or for images where you don't need the full resolution, the getThumbnail method. However, these return the data directly, e.g., to save on your server and serve back to the user, so that doesn't suit your needs as described.
It sounds like you'd prefer the API to return a link to the image that you can use as the source for the images in the HTML of your page. The Dropbox API doesn't offer a method particularly well suited for that, but there are some non-ideal options:
1) You can use createTemporaryDirectLink to get a direct URL to the image. Note that these links expire after four hours though.
Using it would look like:
list($url, $expires) = $client->createTemporaryDirectLink("/default.png");
2) You can use createShareableLink to get a preview URL for the image. These links don't expire. Note that these don't link directly to the image data though, so you'd need to modify them as documented in this help article.
Using it would look like:
$url = $client->createShareableLink("/default.png");
Also, not that both of these are subject to bandwidth restrictions, per this help article.

How is an image created by a PHP script?

I was looking at an possibly fraudulent eBay auction. However I am confused by an image within it, since it does not appear to be an image.
youneedtobuy.intothis.org/win.php
The complete HTML content of the url above is:
<body>
<img src="http://youneedtobuy.intothis.org/win.php" >
</body>
Here is a screen copy of the image, with the email address blurred out by me. There is no JS scripting, no CSS to speak of, just one line of code.
So, essentially the scammer can insert an 'image' into their eBay ad, and that image won't be scanned by normal tools.
How is this image created? And how could the friendly folks at ebay include a scanner in their system that has the ability to "see" this image (and preclude the scam from re-occurring?)
The image is likely created using PHP's file_get_contents() function. For example, the following PHP script will display the contents of myimage.jpg to the browser, but the file could be called show-image.php:
<?php
header("Content-Type: image/jpeg");
header("Content-Length: ".(string)(filesize('myimage.jpg')));
echo file_get_contents('myimage.jpg');
?>
As you can see, this is achieved by telling PHP to serve up the image/jpeg MIME type.
Any image can be returned by a script instead of a real file.
An alternative answer shows methods of doing this, but by using a script one can serve different images to different users, log IP address and other information thus tracking viewers etc.
It is also a common technique used to return thumbnail or summary images. e.g. using PHP and ImageMagick to generate an image of the first page of a PDF file.
Incidentally the image will be scanned by normal tools - they simply look for the image tags, not what extension the file has. What you are really saying is that the text contained within the image won't be processed or analysed, and the image does invite you to directly connect to someone, which is against eBays terms and conditions.

MP4 video delivery via PHP fails in Google Chrome

I'm currently trying to deliver MP4 video for use in HTML5 video (using video-js) via a PHP script for controlling video access. After some research I was able to get this working, with the help of the stackoverflow article found here. If I navigate to the PHP script, I can view the video as if I were viewing it via its absolute path (for instance localhost/myvideo.mp4 rather than localhost/myscript.php) in Firefox, Safari and IE. My problem is with Google Chrome, which simply shows a blacked out screen with a small media player in the centre, and does nothing.
I did try using a quick rewrite such as localhost/avideo.mp4 which routes to the PHP script, but unfortunately this didn't change anything.
Here's my script:
if (is_file($uri)) {
header('Content-Type: video/mp4');
if (isset($_SERVER['HTTP_RANGE'])) {
$this->rangeDownload($uri);
exit;
} else {
header("Content-Length: ".filesize($uri));
$this->readfile_chunked($uri);
exit;
}
} else {
//error
}
The rangeDownload method has been taken directly from appendix A of this link as suggested in the aforementioned stackoverflow article.
Maybe the problem is with the URL (more specifically, the extension). Normally, you would use Content-Disposition header, but I understand that this is not desirable when delivering content to mobiles.
Try using localhost/myscript.php/myvideo.mp4
It is important not to use the "Content-Disposition" HTTP header, since some phones refuse to accept content when using it.
By including the filename on the URL, you will trick the phone to think it's a real file and to accept it.
Now, when you send the download URL to the customer, you don't normally know yet what device the customer has, so you don't know what file formats the device will support. Therefore, you can't include the filename on that URL, and once again, you will need an intermediate download page. Once more, we will use a URL like:
http://wap.mydomain.tld/get.php/123456abcdef
This time, when the customer connects to download the content, the get.php script will not create a temporary file, but point to another script which streams the file contents.
Supposing the resultant content to download will be "image.jpg", the intermediate download page could point the customer to a URL like:
http://wap.mydomain.tld/download.php/123456abcdef/image.jpg
From ( http://mobiforge.com/developing/story/content-delivery-mobile-devices )
I understand you're using video-js but I recommend using html5media (also check out the github page for more info). I had to make videos available on a website for work and I tried a few things including video-js but html5media was the only one that I could get working in all browsers.
A side note that might help others: One of the requirements was that we hosted all files so that we wouldn't be reliant on third-party servers to serve JavaScript files or flash players, I can't remember if with video-js this was easy but I know with html5media we were able to download flowplayer and have everything on our servers.
And to generate the 3 recommend video formats (mp4, WebM and Theora) I used Miro Video Converter

PHP Using imagegrabscreen

How could I use imagegrabscreen to get a thumbnail image and a full size image of a specific website.
I was thinking that I could have an array that I feed the wanted uri's into but I am a bit stuck on how I would set the wxh of the image I need to grab. I also think that I would need a thumbnail class and a fullimage class and call them when required.
Any better Ideas?
Keep in mind that imagaegrabscreen is Windows-only. If you have multiple displays set up, this function will only grab the primary display. Also, for this to work, your Apache service must be set to Allow service to interact with desktop otherwise you will just get a blank image.
This discussion covers the use of imagegrabscreen pretty well: Getting imagegrabscreen to work
There are a lot of other discussions about saving webpages as images, too - here are a few:
Website screenshots
Web Page Screenshots with PHP?
How can I generate a screenshot of a webpage using a server-side script?
PHP: How to capture browser window screen with php?
What is the best way to create a web page thumbnail?
Screenshot of current page using PHP
shell tool which renders web site including javascript
In any languages, Can I capture a webpage and save it image file? (no install, no activeX)

Masking or hiding the path to a background image

I'm displaying pieces of an image in a large grid created from divs. I'm using the background-image and background-position to display portions of the image. The problem I'm running in to is that a user can simply open up firebug and see the entire image (which defeats the purpose of the game).
I've attempted to mask the path using a php script as the URL but if the user navigates to the php file, they can still see the image. It would appear that anything I do with the CSS is entirely client side so denying everything outside the localhost in my .htaccess won't work.
Any suggestions?
The over arching goal is to have an automated way to split and display pieces of the image into a grid.
If you deliver the whole image to the browser, the browser holds the image and has every right to show it to a user. I don't think you can prevent the browser from showing it. I'm afraid you will have to deliver the image in pieces, or perhaps write your whole game using <canvas> and play around with images as pixel data. :)

Categories