Page 1 of 1

Dynamic PHP Image "Loading..."

Posted: Tue Nov 04, 2008 8:35 am
by ansichart
I created a PHP script that checks several TCP ports on the viewer's IP address and then it displays an image corresponding to their open ports. The problem is, the image may take about 5-10 seconds to load since the script has to run a port scan first, before the image is displayed. I was wondering if there is a way (without using JavaScript) to have the image say "Scanning..." with maybe a GIF animation (like an AJAX loader) and then when the scan finishes, the image changes to the port scan result. It is very important that no JavaScript is used... it must all come from the image... meaning it would have to be an animated GIF image... how would I do this?

Re: Dynamic PHP Image "Loading..."

Posted: Tue Nov 04, 2008 9:40 am
by crazycoders
Not possible the way you are explaining this.

An image is a stream of data that you have to send all at once when it is finished. Not just a part of it. You can make the stream sleep but the browser could cut off the connection anytime.

The only way you can do this in a good way would be to send an HTML page with content that says "Please wait for port scan to complete. And image will eventually load below containing the port scan result." Then the image should be output using an image library.

Although this could be prone to attacks, you could use a script that scans for only 1 port at a time and display several images of each test. Just generate a page from PHP with all tests that you wish to do and each image beside each test would trigger the port scan for only one port.

Just remember to test all input from the images or this technique could actually be used to do mass port scans from anytool in the web. I'd limit the port scan capability per IP so that you don't get accused of port scanning the whole world wide web.

:)

Re: Dynamic PHP Image "Loading..."

Posted: Tue Nov 04, 2008 10:16 am
by pickle
Ya, it's not possible with only 1 image. If Javascript is a complete no-go, you could have the page just display no image, and instead display a message saying "Please wait, image is being created" or something else, then have a META refresh that reloads the page in 5 or so seconds. On that reload, if the image exists, display it. If not, display the message again & reload in 5 more seconds.

Re: Dynamic PHP Image "Loading..."

Posted: Wed Nov 05, 2008 9:22 am
by Jenk
Just set the alternate text to "image loading" or perhaps a heading/paragraph/etc with "Loading" then overlay it with the image.

Re: Dynamic PHP Image "Loading..."

Posted: Wed Nov 05, 2008 10:08 am
by onion2k
Actually it is possible... but only if you're willing to delve into the arcane horror of Keep-Alive connections.

Basically you'd need to create an HTTP "Keep Alive" connection and send the headers of an animated gif that doesn't loop, and the first frame, then trickle more "please wait" frames as the scan is happening, and then create and send the final frame with whatever the user should see at the end. The user's browser will display each frame as it arrives and it'll stop on the last one. Which is what you want.

Now, this presents some interesting challenges ... first, I'm not sure how you create a keep alive connection in PHP, or even if it's possible. Second, you won't be able to use GD. GD creates complete images, you only want frames. You'll have to write something to make animated GIFs frame by frame yourself.

If this was 10 years ago and a discussion about Perl then I'd have been able to give you the code to do it because I remember playing with it at university. But it's not. So I can't.

Good luck.

Re: Dynamic PHP Image "Loading..."

Posted: Fri Nov 07, 2008 1:43 pm
by mmj
If you can't use JS then it won't be easy at all; if possible.

Re: Dynamic PHP Image "Loading..."

Posted: Sun Nov 09, 2008 11:23 am
by cboileau
Pretty much impossible using the picture to say loading, however you could always Create a page that says "Scanning..." etc, and then have it redirect once the scan is complete and display the picture.

Re: Dynamic PHP Image "Loading..."

Posted: Sat Nov 15, 2008 1:41 am
by Mordred
onion2k wrote:I'm not sure how you create a keep alive connection in PHP
You basically can't. The brower requests it, the server - if it decides to - accepts it (or denies it).

What you describe though (you eevil, eevil, man ;) ) is certainly doable, because it requires transporting of one HTTP response, which you can do regardless of whether the connection is keep-alive, pipelined or regular.

That said, this would put a strain on the server, as it won't close the connection as fast as it could. But anyway port scanning is a slow busyness, so the OP should be prepared to have a strained server.

And another thing, the easiest solution would be to have a chain of requests, each one scanning only one port and displaying the results from the scan up to now. Store the state in sessions, force the page to reload each X seconds, and voila.

Re: Dynamic PHP Image "Loading..."

Posted: Sat Nov 15, 2008 5:57 am
by VladSun
What about using Content-Type: multipart/x-mixed-replace;boundary=$#@$#@

viewtopic.php?f=1&t=88928 ?