OK! so I got this code working, HostGator ended up allowing my sockets etc and it worked!!!

However this lead to more problems...

<?php
/*
Plugin Name: Server Status
Plugin URI: http://minepress.co.uk
Description: Server Status Plugin   
Author: Bradly spicer
Version: 1.0.0
Author URI: http://minepress.co.uk
*/

class ServerStatus extends WP_Widget
{
  function ServerStatus()
  {
    $widget_ops = array('classname' => 'ServerStatus', 'description' => 'Displays Server Status' );
    $this->WP_Widget('ServerStatus', 'Server Status display', $widget_ops);
  }

  function form($instance)
  {
    $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
    $title = $instance['title'];
    $ip= $instance['ip'];
    $Port= $instance['Port'];
?>
  <p><label for="<?php echo $this->get_field_id('title'); ?>">Title: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p>

 <p><label for="<?php echo $this->get_field_id('ip'); ?>">Ip: <input class="widefat" id="<?php echo $this->get_field_id('ip'); ?>" name="<?php echo $this->get_field_name('ip'); ?>" type="text" value="<?php echo attribute_escape($ip); ?>" /></label></p>

 <p><label for="<?php echo $this->get_field_id('Port'); ?>">Port: <input class="widefat" id="<?php echo $this->get_field_id('Port'); ?>" name="<?php echo $this->get_field_name('Port'); ?>" type="text" value="<?php echo attribute_escape($Port); ?>" /></label></p>

<?php
  }

  function update($new_instance, $old_instance)
  {
    $instance = $old_instance;
    $instance['title'] = $new_instance['title'];
    $instance['ip'] = $new_instance['ip'];
    $instance['Port'] = $new_instance['Port'];
    return $instance;
  }

  function widget($args, $instance)
  {
    extract($args, EXTR_SKIP);

    echo $before_widget;
    $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
    $ip = empty($instance['ip']) ? ' ' : apply_filters('ip', $instance['ip']);
    $Port = empty($instance['Port']) ? ' ' : apply_filters('Port', $instance['Port']);

    if (!empty($title))
      echo $before_title . $title . $after_title;;

    // WIDGET CODE GOES HERE
?><div id="Server_status"><?php $online = @fsockopen($ip,$Port, $errno, $errstr, 5);
if($online >= 5) { 
echo '<a href="#" class="MPServer_Online">Online</a>'; 
}
else {
echo '<a href="#" class="MPServer_Offline">Offline</a>'; 
} 
?>
</div>

 <?php
    echo $after_widget;
  }

}
add_action( 'widgets_init', create_function('', 'return register_widget("ServerStatus");') );?>

This code is all fine when I have custom values:

    ?><div id="Server_status"><?php $online = @fsockopen("play.magicacraft.net","25567", $errno, $errstr, 5);

Now, by what I can read and what I can see it should pickup the fields up top but.. it seems to not...

Notes I have made:

  • The $ip and $Port are case sensative (Thats now fixed as they all match up)
  • This is in Wordpress so it may not be collecting information properly?

Update:

<?php
/*
Plugin Name: Server Status
Plugin URI: http://minepress.co.uk
Description: Server Status Plugin   
Author: Bradly spicer
Version: 1.0.0
Author URI: http://minepress.co.uk
*/

class ServerStatus extends WP_Widget
{
  function ServerStatus()
  {
    $widget_ops = array('classname' => 'ServerStatus', 'description' => 'Displays Server Status' );
    $this->WP_Widget('ServerStatus', 'Server Status display', $widget_ops);
  }

  function form($instance)
  {
    $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
    $title = $instance['title'];
    $ip= $instance['ip'];
    $port= $instance['port'];
?>
  <p><label for="<?php echo $this->get_field_id('title'); ?>">Title: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p>

    <p><label for="<?php echo $this->get_field_id('ip'); ?>">Ip: <input class="widefat" id="<?php echo $this->get_field_id('ip'); ?>" name="<?php echo $this->get_field_name('ip'); ?>" type="text" value="<?php echo attribute_escape($ip); ?>" /></label></p>

    <p><label for="<?php echo $this->get_field_id('port'); ?>">port: <input class="widefat" id="<?php echo $this->get_field_id('port'); ?>" name="<?php echo $this->get_field_name('port'); ?>" type="text" value="<?php echo attribute_escape($port); ?>" /></label></p>
<?php
  }

  function update($new_instance, $old_instance)
  {
    $instance = $old_instance;
    $instance['title'] = $new_instance['title'];
    $instance['ip'] = $new_instance['ip'];
    $instance['port'] = $new_instance['port'];
    return $instance;
  }

  function widget($args, $instance)
  {
    extract($args, EXTR_SKIP);

    echo $before_widget;
    $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
    $ip = empty($instance['ip']) ? ' ' : apply_filters('ip', $instance['ip']);
    $port = empty($instance['port']) ? ' ' : apply_filters('port', $instance['port']);

    if (!empty($title))
      echo $before_title . $title . $after_title;;

    // WIDGET CODE GOES HERE
?><div id="Server_status">
<?php $online = @fsockopen($ip,$Port, $errno, $errstr, 200);
if($online >= 200) { 
echo '<a href="#" class="MPServer_Online">Online</a>'; 
}
else {
echo '<a href="#" class="MPServer_Offline">Offline</a>'; 
} 
?>
<p>
<?php
Print "Our IP is: ";
Print $ip;
?>
</div>

 <?php
    echo $after_widget;
  }

}
add_action( 'widgets_init', create_function('', 'return register_widget("ServerStatus");') );?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.