Jump to content

Changing images with php


MetalAxeToby

Recommended Posts

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 to

if( !$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 by MetalAxeToby
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.