MetalAxeToby Posted January 5, 2014 Share Posted January 5, 2014 (edited) So i have this code wich checks if my server is online: <?php$ip = "example.com"; //IP or web addy$port = "80"; //Port$sock = @fsockopen( $ip, $port, $num, $error, 2 ); //2 is the ping time, you can sub what you need//Since fsockopen function returns TRUE or FALSE we can just plug it into the IF/THEN statement. An IF/ELSE would have worked toif( !$sock ){//Do this if it is closed echo( "offline" ); }if( $sock ){//Do this if it is open echo( "online" ); fclose($sock);} ?> and i've got: <img class="img-circle" src="ico/online.png" alt="Server status"> I want to use the php script to change the image source in the html.I have an online.png and an offline.png image.I need to somehow change it and I don't know how. I am fairly new to php. Edited January 5, 2014 by MetalAxeToby Quote Link to comment https://forums.phpfreaks.com/topic/285109-changing-images-with-php/ Share on other sites More sharing options...
paddy_fields Posted January 5, 2014 Share Posted January 5, 2014 <?php if( !$sock ){ //Do this if it is closed echo( "offline" ); $image = 'offline.png'; } if( $sock ){ //Do this if it is open echo( "online" ); fclose($sock); $image = 'online.png'; } ?> <img class="img-circle" src="ico/<?php echo $image; ?>" alt="Server status"> Quote Link to comment https://forums.phpfreaks.com/topic/285109-changing-images-with-php/#findComment-1463938 Share on other sites More sharing options...
MetalAxeToby Posted January 5, 2014 Author Share Posted January 5, 2014 Thanks alot everytime i tried to make it change the variable content it gave me an error.Thank you again, Quote Link to comment https://forums.phpfreaks.com/topic/285109-changing-images-with-php/#findComment-1463940 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.