Jump to content

Help turning domain.com/file.php?id=xxx into an image


seriosbrad

Recommended Posts

Alright I have a link that generates an online/offline image according to the status of a server.

 

http://www.domain.com/script.php?ip=11.11.111.111&port=12354

 

By directly going to that  link, it displays the image fine.  However what I want to do is use that link like this:

 

<img src="http://www.domain.com/script.php?ip=11.11.111.111&port=12354">

and

[img=http://www.domain.com/script.php?ip=11.11.111.111&port=12354]

And have that turn into an image based on the status of the server.

 

Here is my script

<?php

$ip = $_GET["ip"];
$port = $_GET["port"];
$timeout = 1;

function ip($address){
list($ip,$port)=explode(":",$address);
        if($fp=@fsockopen($ip,$port,$ERROR_NO,$ERROR_STR,1)) {
        print "<img src='images/status/up.png'>";
        fclose($fp);
        }else{
        print "<img src='images/status/down.png'>";
        }
}



ip("$ip:$port");
?>  

 

Please bare in mind that I am not a coder, I can understand some thing from copy+pasting and trial & error.

<?php

$ip = $_GET["ip"];
$port = $_GET["port"];
$timeout = 1;

header('Content-Type: image/png');

function ip($address){
list($ip,$port)=explode(":",$address);
        if($fp=@fsockopen($ip,$port,$ERROR_NO,$ERROR_STR,1)) {
        //print "<img src='images/status/up.png'>";
        fclose($fp);
        readfile($_SERVER['DOCUMENT_ROOT'] . "/images/status/up.png");
        }else{
        readfile($_SERVER['DOCUMENT_ROOT'] . "/images/status/down.png");
        }
}



ip("$ip:$port");
?>  

 

Give that a shot. This is assuming images is located in your webserver root (IE http://www.yoursite.com/images).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.