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.

Link to comment
Share on other sites

<?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).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.