+ Reply to Thread
Results 1 to 5 of 5

Thread: Images in PHP Coding?

  1. #1
    TheJeffsta's Avatar
    TheJeffsta is offline x10 Lieutenant TheJeffsta is an unknown quantity at this point
    Join Date
    Sep 2005
    Location
    New Zealand
    Posts
    492

    Question Images in PHP Coding?

    OK, currently I have set up a server status page, using the code from another post.

    Code:
    <center><script language='JavaScript' type='text/javascript' src='http://x10hosting.com/advert/adx.js'></script>
    <script language='JavaScript' type='text/javascript'>
    <!--
       if (!document.phpAds_used) document.phpAds_used = ',';
       phpAds_random = new String (Math.random()); phpAds_random = phpAds_random.substring(2,11);
       
       document.write ("<" + "script language='JavaScript' type='text/javascript' src='");
       document.write ("http://x10hosting.com/advert/adjs.php?n=" + phpAds_random);
       document.write ("&amp;what=zone:1&amp;target=_blank");
       document.write ("&amp;exclude=" + document.phpAds_used);
       if (document.referrer)
          document.write ("&amp;referer=" + escape(document.referrer));
       document.write ("'><" + "/script>");
    //-->
    
    </script><noscript><a href='http://x10hosting.com/advert/adclick.php?n=a7fb3e9d' target='_blank'><img src='http://x10hosting.com/advert/adview.php?what=zone:1&amp;n=a7fb3e9d' border='0' alt=''></a></noscript></center>
    <p></p>
    <p align="center"><u><b><font size="7">x10Hosting Free Hosting Server Status</font></b></u>
    <p></p>
    <?
    error_reporting(0);
    $IP = array(
    "HTTP" => "70.86.136.178:80",
    ); while(list($ServerName,$Host)=each($IP)) {
    list($IPAddress,$Port)=explode(":",$Host);
    if($fp=fsockopen($IPAddress,$Port,$ERROR_NO,$ERROR_STR,(float)0.5)) {
    echo("<font color=\"black\"><b>HTTP</b>&nbsp;-&nbsp;<font color=\"green\"><b>Online</b></font>");
    fclose($fp);
    }
    else {
    echo ("<font color=\"black\"><b>HTTP</b>&nbsp;-&nbsp;<font color=\"red\"><b>Offline</b></font>");
    }
    echo ("");
    }
    ?>
    <p></p>
    <?
    error_reporting(0);
    $IP = array(
    "FTP" => "70.86.136.178:25",
    ); while(list($ServerName,$Host)=each($IP)) {
    list($IPAddress,$Port)=explode(":",$Host);
    if($fp=fsockopen($IPAddress,$Port,$ERROR_NO,$ERROR_STR,(float)0.5)) {
    echo("<font color=\"black\"><b>FTP</b>&nbsp;-&nbsp;<font color=\"green\"><b>Online</b></font>");
    fclose($fp);
    }
    else {
    echo ("<font color=\"black\"><b>FTP</b>&nbsp;-&nbsp;<font color=\"red\"><b>Offline</b></font>");
    }
    echo ("");
    }
    ?>
    <p></p>
    <?
    error_reporting(0);
    $IP = array(
    "MySQL" => "70.86.136.178:3306",
    ); while(list($ServerName,$Host)=each($IP)) {
    list($IPAddress,$Port)=explode(":",$Host);
    if($fp=fsockopen($IPAddress,$Port,$ERROR_NO,$ERROR_STR,(float)0.5)) {
    echo("<font color=\"black\"><b>MySQL</b>&nbsp;-&nbsp;<font color=\"green\"><b>Online</b></font>");
    fclose($fp);
    }
    else {
    echo ("<font color=\"black\"><b>MySQL</b>&nbsp;-&nbsp;<font color=\"red\"><b>Offline</b></font>");
    }
    echo ("");
    }
    ?>
    <p></p>
    <?
    error_reporting(0);
    $IP = array(
    "POP3" => "70.86.136.178:110",
    ); while(list($ServerName,$Host)=each($IP)) {
    list($IPAddress,$Port)=explode(":",$Host);
    if($fp=fsockopen($IPAddress,$Port,$ERROR_NO,$ERROR_STR,(float)0.5)) {
    echo("<font color=\"black\"><b>POP3</b>&nbsp;-&nbsp;<font color=\"green\"><b>Online</b></font>");
    fclose($fp);
    }
    else {
    echo ("<font color=\"black\"><b>POP3</b>&nbsp;-&nbsp;<font color=\"red\"><b>Offline</b></font>");
    }
    echo ("");
    }
    ?>
    <p></p>
    <?
    error_reporting(0);
    $IP = array(
    "SMTP" => "70.86.136.178:25",
    ); while(list($ServerName,$Host)=each($IP)) {
    list($IPAddress,$Port)=explode(":",$Host);
    if($fp=fsockopen($IPAddress,$Port,$ERROR_NO,$ERROR_STR,(float)0.5)) {
    echo("<font color=\"black\"><b>SMTP</b>&nbsp;-&nbsp;<font color=\"green\"><b>Online</b></font>");
    fclose($fp);
    }
    else {
    echo ("<font color=\"black\"><b>SMTP</b>&nbsp;-&nbsp;<font color=\"red\"><b>Offline</b></font>");
    }
    echo ("");
    }
    ?>
    <p></p>
    <?
    error_reporting(0);
    $IP = array(
    "cPanel" => "70.86.136.178:2082",
    ); while(list($ServerName,$Host)=each($IP)) {
    list($IPAddress,$Port)=explode(":",$Host);
    if($fp=fsockopen($IPAddress,$Port,$ERROR_NO,$ERROR_STR,(float)0.5)) {
    echo("<font color=\"black\"><b>cPanel</b>&nbsp;-&nbsp;<font color=\"green\"><b>Online</b></font>");
    fclose($fp);
    }
    else {
    echo ("<font color=\"black\"><b>cPanel</b>&nbsp;-&nbsp;<font color=\"red\"><b>Offline</b></font>");
    }
    echo ("");
    }
    ?>
    <p></p>
    <?
    error_reporting(0);
    $IP = array(
    "DNS" => "70.86.136.178:53",
    ); while(list($ServerName,$Host)=each($IP)) {
    list($IPAddress,$Port)=explode(":",$Host);
    if($fp=fsockopen($IPAddress,$Port,$ERROR_NO,$ERROR_STR,(float)0.5)) {
    echo("<font color=\"black\"><b>DNS</b>&nbsp;-&nbsp;<font color=\"green\"><b>Online</b></font>");
    fclose($fp);
    }
    else {
    echo ("<font color=\"black\"><b>DNS</b>&nbsp;-&nbsp;<font color=\"red\"><b>Offline</b></font>");
    }
    echo ("");
    }
    ?>
    <p></p>
    <?
    error_reporting(0);
    $IP = array(
    "IMAP" => "70.86.136.178:143",
    ); while(list($ServerName,$Host)=each($IP)) {
    list($IPAddress,$Port)=explode(":",$Host);
    if($fp=fsockopen($IPAddress,$Port,$ERROR_NO,$ERROR_STR,(float)0.5)) {
    echo("<font color=\"black\"><b>IMAP</b>&nbsp;-&nbsp;<font color=\"green\"><b>Online</b></font>");
    fclose($fp);
    }
    else {
    echo ("<font color=\"black\"><b>IMAP</b>&nbsp;-&nbsp;<font color=\"red\"><b>Offline</b></font>");
    }
    echo ("");
    }
    ?>
    <p></p>
    <?
    $uptime = @exec('uptime');
    preg_match("/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/", $uptime, $avgs);
    $uptime = explode(' up ', $uptime);
    $uptime = explode(',', $uptime[1]);
    $uptime = $uptime[0] .', '. $uptime[1];
    $start = mktime(0, 0, 0, 1, 1, date('Y'), 0);
    $end = mktime(0, 0, 0, date('m'), date('j'), date('y'), 0);
    $diff = $end - $start;
    $days = @($diff / 86400);
    $percentage = @($uptime / $days) * 100;
    $load = $avgs[1] + $avgs[2] + $avgs[3];
    $load = $load / 3;
    $load = round($load, 3);
    
    // $load holds the load.
    echo "<b>Server Load</b> - $load%";
    ?>
    <p></p>
    <?
    $uptime = shell_exec("cut -d. -f1 /proc/uptime");
    $days = floor($uptime/60/60/24);
    $hours = $uptime/60/60%24;
    $mins = $uptime/60%60;
    $secs = $uptime%60;
    echo "<b>Server Uptime</b> - $days days, $hours hours, $mins minutes and $secs seconds";
    ?>
    <script>
    <!--
    
    /*
    Auto Refresh Page with Time script
    By JavaScript Kit (javascriptkit.com)
    Over 200+ free scripts here!
    */
    
    //enter refresh time in "minutes:seconds" Minutes should range from 0 to inifinity. Seconds should range from 0 to 59
    var limit="0:10"
    
    if (document.images){
    var parselimit=limit.split(":")
    parselimit=parselimit[0]*60+parselimit[1]*1
    }
    function beginrefresh(){
    if (!document.images)
    return
    if (parselimit==1)
    window.location.reload()
    else{ 
    parselimit-=1
    curmin=Math.floor(parselimit/60)
    cursec=parselimit%60
    if (curmin!=0)
    curtime=curmin+" minutes and "+cursec+" seconds left until page refresh!"
    else
    curtime=cursec+" seconds left until page refresh!"
    window.status=curtime
    setTimeout("beginrefresh()",1000)
    }
    }
    
    window.onload=beginrefresh
    //-->
    </script>
    The code at the top is the ad code, the code right at the bottom is a code to automatically refresh the page every 10 seconds.

    The code posted above works perfectly but I want to change the
    Code:
    <font color=\"red\"><b>Offline</b></font>
    and
    Code:
    <font color=\"red\"><b>Online</b></font>
    to display the images (http://www.thejeffsta.x10hosting.com/Status/offline.gif and http://www.thejeffsta.x10hosting.com/Status/offline.gif) - the script page is hosted in my /Status/ directory (set to not show contents via HTTP).

    If you could please tell me how to do it, It would be much appreciated.
    TheJeffsta (Jeffrey N)

    "No matter how much you try, the end result will always end up the way you DO NOT want it!"

  2. #2
    Cynical's Avatar
    Cynical is offline Lord Of The Keys Cynical is an unknown quantity at this point
    Join Date
    Sep 2005
    Location
    Massachusetts, USA
    Posts
    1,744

    Re: Images in PHP Coding?

    Couldn't you just replace <font color=\"red\"><b>Offline</b></font> with <img src=\"http://www.thejeffsta.x10hosting.com/Status/offline.gif\">?
    Seven: This rule is so underrated, keep your family and business completely separated.

  3. #3
    TheJeffsta's Avatar
    TheJeffsta is offline x10 Lieutenant TheJeffsta is an unknown quantity at this point
    Join Date
    Sep 2005
    Location
    New Zealand
    Posts
    492

    Re: Images in PHP Coding?

    I've tried that, when I try to browse to the page is just displays it as a blank php page.
    TheJeffsta (Jeffrey N)

    "No matter how much you try, the end result will always end up the way you DO NOT want it!"

  4. #4
    dharmil's Avatar
    dharmil is offline x10 Elder dharmil is an unknown quantity at this point
    Join Date
    Sep 2005
    Location
    Avenel New Jersey
    Posts
    828

    Re: Images in PHP Coding?

    Just try this

    Description

    This script will as the previously posted script, check the current online status but it will output a image instead of text.

    Server IPs and ports are defined inside the script so people can't use it script to check whatever they like.

    Usage

    Copy and save the below script into a php file and use

    PHP Code:
    <img src="scriptname.php?server=serverid"
    scriptname.php should be replaced with whatever name you give the script.
    serverid should be what you name the servers in the script.

    Explanation

    The code below shows three ways of setting an array.

    First one,
    PHP Code:
    array('123.123.123'123), 
    will use the next number in the array. This become zero as arrays start on zero and there were none set before this.

    second one,
    PHP Code:
    11 => array('123.123.123.123'123), 
    ... you guessed it, it will be number 11

    third one,
    PHP Code:
    'http' => array('123.123.123.123'123), 
    will of course be http. This isn't so hard is it... Remember to use single quotes ( ' ) if you use anything else but numbers.

    Fourth and last one is the same as the first. It will use the next number in the array which is now 12 because we set number 11 before.

    Script

    You either need to save or create two images and put them in the same folder as the script. online.gif () and offline.gif (). If you want to change you'll have to edit the script.

    Just copy and paste this into a php file.

    PHP Code:
    <?php

    # Change the below as following
    # array('IP number', Port number);
    # Remove the ones you don't use.

    $servers = array(
               array(
    '123.123.123.123'123), # Next number in array, zero if first
     
    11     => array('123.123.123.123'123), # Number 11
     
    'http' => array('123.123.123.123'123), # Named http
               
    array('123.123.123.123'123), # This becomes 12 because have set 11
    );

    function 
    getConnectionStatus($address$port)
    {
     
    $sock fsockopen($address$port$errno$errstr5);
     if (!empty(
    $sock)) $status true;
     else 
    $status false;
     
    fclose($sock);
     return 
    $status;
    }

    if (isset(
    $_GET['server']) && array_key_exists($_GET['server'], $servers))
    {
     
    $status getConnectionStatus($servers[$_GET['server']][0], $servers[$_GET['server']][1]);
     
    header("Cache-Control: no-cache, must-revalidate");
     
    header("Expires: Sat, 16 Aug 1986 05:00:00 GMT");
     
    header('Content-type: image/gif');
     if (
    $status) @readfile('online.gif');
     else @
    readfile('offline.gif');
    }

    ?>

    Here are some Ports
    Code:
    HTTP           80      
    SSL         443     
    FTP         21     
    Telnet         23     
    IMAP         143     
    SIMAP         933 
    SSL/POP2:     995 
    POP3         110     
    SMTP         25     
    SSH         22     
    FINGER         79     
    IDENT         103     
    NNTP         119     
    GOPHER         70         
    NTP         123     
    PPTP        1723     
    Carbon Copy 32     
    CITRIX         1494     
    CU-SeeMe    7648             Version: Cornell 1.1
    CU SeeMe     1748, 24032     Version: White Pine 3.1.2
    CU SeeMe     1748, 24032     Version: White Pine 4.0 (Pro)
    Last edited by dharmil; 05-19-2006 at 08:07 PM.

  5. #5
    TheJeffsta's Avatar
    TheJeffsta is offline x10 Lieutenant TheJeffsta is an unknown quantity at this point
    Join Date
    Sep 2005
    Location
    New Zealand
    Posts
    492

    Re: Images in PHP Coding?

    Thats an entirely different script. I do not want a different variation to the script, I just want to try and replace the 'Offline'/'Online' to the Offline/Online images that I have.

    Thanks anyway!
    TheJeffsta (Jeffrey N)

    "No matter how much you try, the end result will always end up the way you DO NOT want it!"

+ Reply to Thread

Similar Threads

  1. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 10:46 AM
  2. tons of PHP Resources
    By Chris S in forum Scripts & 3rd Party Apps
    Replies: 10
    Last Post: 01-16-2009, 11:07 AM
  3. [PHP] PHP For Starters
    By Complex in forum Tutorials
    Replies: 24
    Last Post: 06-15-2008, 12:40 AM
  4. Unstand PHP?
    By o0slowpaul0o in forum Tutorials
    Replies: 8
    Last Post: 01-07-2008, 10:16 PM
  5. PHP Coding For Points
    By [TX]-Ghost in forum The Marketplace
    Replies: 3
    Last Post: 11-26-2007, 10:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers