php不会调用$server等

php不会调用$server等,php,html,string,wordpress,Php,Html,String,Wordpress,让我的插件开始慢慢工作,但是当我想改进它并使用我自己的代码时,它决定停止工作 网站:英国minepress公司 问题:它将php显示为文本,而不是从includes文件/function.php调用 function.php <?php class MCServerStatus { public $server; public $online, $max_players; public $error = "OK"; function __cons

让我的插件开始慢慢工作,但是当我想改进它并使用我自己的代码时,它决定停止工作

网站:英国minepress公司

问题:它将php显示为文本,而不是从includes文件/function.php调用

function.php

<?php

class MCServerStatus {


    public $server;
    public $online, $max_players;
    public $error = "OK";



    function __construct($url, $port = '25565') {

        $this->server = array(
            "url" => $url,
            "port" => $port
        );

        if ( $sock = @stream_socket_client('tcp://'.$url.':'.$port, $errno, $errstr, 1) ) {

            $this->online = true;

            fwrite($sock, "\xfe");
            $h = fread($sock, 2048);
            $h = str_replace("\x00", '', $h);
            $h = substr($h, 2);
            $data = explode("\xa7", $h);
            unset($h);
            fclose($sock);

            if (sizeof($data) == 2) {
                $this->motd = $data[0];
                $this->max_players = (int) $data[1];
            }
            else {
                $this->error = "Cannot retrieve server info.";
            }

        }
        else {
            $this->online = false;
            $this->error = "Cannot connect to server.";
        }

    }



}


//$var = $server->online; //$server->online returns true if the server is online, and false otherwise
//echo $server->motd; //Outputs the Message of the Day
//echo $server->online_players; //Outputs the number of players online
//echo $server->max_players; //Outputs the maximum number of players the server allows
//print_r($server); //Shows an overview of the object and its contents. (For debugging.)
?>
<?php
/*
Plugin Name: Server Status
Plugin URI: http://minepress.co.uk
Description: Server Status Plugin   
Author: Bradly spicer
Version: 1
Author URI: http://minepress.co.uk
*/

include "function.php";

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('Port'); ?>">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
    echo "<h3>Server Status:</h3>"; 
    //<?php echo $this->get_field_id('ip'); ?><?php echo $this->get_field_id('port');?>
    echo $server = new MCServerStatus("s.nerd.nu", 25565);  
    ?>//The second argument is optional in this case



 <?php
    echo $after_widget;
  }

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

Server\u Status.php

<?php

class MCServerStatus {


    public $server;
    public $online, $max_players;
    public $error = "OK";



    function __construct($url, $port = '25565') {

        $this->server = array(
            "url" => $url,
            "port" => $port
        );

        if ( $sock = @stream_socket_client('tcp://'.$url.':'.$port, $errno, $errstr, 1) ) {

            $this->online = true;

            fwrite($sock, "\xfe");
            $h = fread($sock, 2048);
            $h = str_replace("\x00", '', $h);
            $h = substr($h, 2);
            $data = explode("\xa7", $h);
            unset($h);
            fclose($sock);

            if (sizeof($data) == 2) {
                $this->motd = $data[0];
                $this->max_players = (int) $data[1];
            }
            else {
                $this->error = "Cannot retrieve server info.";
            }

        }
        else {
            $this->online = false;
            $this->error = "Cannot connect to server.";
        }

    }



}


//$var = $server->online; //$server->online returns true if the server is online, and false otherwise
//echo $server->motd; //Outputs the Message of the Day
//echo $server->online_players; //Outputs the number of players online
//echo $server->max_players; //Outputs the maximum number of players the server allows
//print_r($server); //Shows an overview of the object and its contents. (For debugging.)
?>
<?php
/*
Plugin Name: Server Status
Plugin URI: http://minepress.co.uk
Description: Server Status Plugin   
Author: Bradly spicer
Version: 1
Author URI: http://minepress.co.uk
*/

include "function.php";

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('Port'); ?>">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
    echo "<h3>Server Status:</h3>"; 
    //<?php echo $this->get_field_id('ip'); ?><?php echo $this->get_field_id('port');?>
    echo $server = new MCServerStatus("s.nerd.nu", 25565);  
    ?>//The second argument is optional in this case



 <?php
    echo $after_widget;
  }

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


echo$server=new MCServerStatus(“s.nerd.nu”,25565);
?>//在这种情况下,第二个参数是可选的

Server\u Status.php
文件被解析了吗?老实说,我不太确定,这是我所有的文件。我使用Wordpress作为基础。我以前确实让Server_Status.php工作过。然而,我使用了一个非常糟糕的html脚本来运行它。这就是为什么我要重做它。我真的很感谢您的时间和精力您是否将
Server_Status.php
function.php
的内容都视为纯文本?我只看到下面的内容//小部件代码在echo$after_小部件之前一直在这里。正如您从我刚刚发布的页面中看到的,在侧栏中有一些应该是php的代码