Rathlar Posted November 28, 2007 Share Posted November 28, 2007 Ok... well I'm trying to do an online/offline status image code which users can modify the url to output their own custom status checker. here's the code I have so far... I know it's kinda sloppy but I just need it to work and then I can clean it up later. <?php Function testconn() { $socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP); $address = gethostbyname($_GET['host']); $service_port = $_GET['port']; $result = socket_connect($socket, $address, $service_port); if($result == "") { $im = imagecreatefrompng($_GET['offline']); } else { $im = imagecreatefrompng($_GET['online']); } } header("Content-Type: image/png"); testconn(); imagepng($im); imagedestroy($im); ?> I also know this requires allow_url_fopen to be turned on in php.ini which I do have on. So far all I can manage to get is the url displayed in the browser with no errors other than the fact that the image isnt showing up. Any help would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
micah1701 Posted November 28, 2007 Share Posted November 28, 2007 not really sure i'm following your code, but for starters $im is not a global var because its in your function. at the end of your function, before the last bracket } you need: return $im; then, when you call the function, asign $im to a var; like this: $im = testconn(); Quote Link to comment Share on other sites More sharing options...
Rathlar Posted November 28, 2007 Author Share Posted November 28, 2007 I did exactly what you told me and it still won't output the image. } return $im; } header("Content-Type: image/png"); $im = testconn(); imagepng($im); imagedestroy($im); ?> Same exact result as before... Basically what I'm trying to do is when the user uses the URL: /status.php?offline=URL_of_PNG1&online=URL_of_PNG2&host=HOSTNAME&port=PORT_NUM They will be displayed the server status of the server they chose in the URL in png output. More or less a dynamic image based on the user input and conditional based on the results of the socket connection. Quote Link to comment Share on other sites More sharing options...
Rathlar Posted November 28, 2007 Author Share Posted November 28, 2007 Actually I figured out this is a sockets problem... call to undefined function... seems to be a fairly common problem from what I'm reading. Quote Link to comment Share on other sites More sharing options...
Rathlar Posted November 28, 2007 Author Share Posted November 28, 2007 gah... triple posting... i wish i could edit my posts... anyway I fixed it myself... i should have been doing sockets differently... <?php header("Content-Type: image/png"); $address = gethostbyname($_GET['host']); $port = $_GET['port']; if (! $sock = @fsockopen($address, $port, $num, $error, 5)) $im = imagecreatefrompng($_GET['offline']); else{ $im = imagecreatefrompng($_GET['online']); fclose($sock); } imagepng($im); ?> less code and works like a charm Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.