【问题标题】:Get info from the ip&port inserted on url从 url 上插入的 ip&port 获取信息
【发布时间】:2015-10-18 02:24:45
【问题描述】:

我正在尝试制作脚本,我想显示从 URL 插入的游戏服务器 ip 的信息。

在当前配置中我有:

<?php
define( 'SQ_TIMEOUT',     1 );
define( 'SQ_ENGINE',      SourceQuery :: SOURCE );  
define( 'SQ_SERVER_ADDR', '123.45.67.890' ); 
define( 'SQ_SERVER_PORT', 12345); 
?>

我试过这样:

<?php

define( 'SQ_TIMEOUT',     1 );
define( 'SQ_ENGINE',      SourceQuery :: SOURCE );  

    if (isset($_GET['ip'])){
        $ip = $_GET['ip'];
    }
    if (isset($_GET['port'])){
        $port = $_GET['port'];
    }

define( 'SQ_SERVER_ADDR', $ip ); 
define( 'SQ_SERVER_PORT', $port );     
?>

变得像

http://localhost/".$ip.":".$port.

而不是固定的ip。插入“定义”

【问题讨论】:

    标签: php get ip info


    【解决方案1】:

    你不能把你的网址设为localhost/$ip:$port

    您将需要它为localhost/addr=$IP:$PORT,因为您使用的是$_GET

    使用以下代码修改您的代码:

    <?php
    
    define( 'SQ_TIMEOUT',     1 );
    define( 'SQ_ENGINE',      SourceQuery :: SOURCE );  
    
        if (isset($_GET['addr'])){
            $addr = $_GET['addr'];
            $addrarray = explode(':', $myString);
            $ip = $addrarray[0];
            $port = $addrarray[1];
        }
    
    define( 'SQ_SERVER_ADDR', $ip ); 
    define( 'SQ_SERVER_PORT', $port ); 
    
    ?>
    

    现在你的地址是这样的:

    我正在使用一个示例 ip:192.168.0.0 和一个示例端口:1234

    localhost/addr=192.168.0.0:1234
    

    希望对你有帮助:)

    【讨论】:

    • 所以它会像:DIR 。 '/SourceQuery/SourceQuery.class.php';定义('SQ_TIMEOUT',1);定义('SQ_ENGINE',SourceQuery :: SOURCE); if (isset($_GET['addr'])){ $addr = $_GET['addr']; $addrarray = explode(':', $myString); $ip = $addrarray[0]; $port = $addrarray[1]; } 定义('SQ_SERVER_ADDR',$ip);定义('SQ_SERVER_PORT',$port); $Query = new SourceQuery();尝试 { $Query->Connect(SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_TIMEOUT, SQ_ENGINE); $players_online = $Query->GetInfo()['Players'];
    猜你喜欢
    • 1970-01-01
    • 2021-07-01
    • 2021-11-30
    • 1970-01-01
    • 2022-06-13
    • 2014-07-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-06
    相关资源
    最近更新 更多