注意:未定义的索引:REMOTE_ADDR

问题描述 投票:-4回答:1

我一直在努力关注this教程,我做了一切。我点击了下载按钮,安装了XAMPP,复制了我发现的唯一server.php文件的目录,并将其放在以下行中,然后像它所说的那样在shell中运行它。

php -q c:\ xampp1 \ php \ pear \ adodb \ server.php

但是我得到了一些关于文件没有被包含的警告和其他东西,我不明白,因为我下载了它说的所有内容并遵循了教程。这是我所有错误的截图(我无法在xampp shell中复制粘贴):

enter image description here

编辑:这是server.php文件代码:

<?php

/** 
 * @version V4.93 10 Oct 2006 (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved.
 * Released under both BSD license and Lesser GPL library license. 
  Whenever there is any discrepancy between the two licenses, 
  the BSD license will take precedence. 
 */

/* Documentation on usage is at http://php.weblogs.com/adodb_csv
 *
 * Legal query string parameters:
 * 
 * sql = holds sql string
 * nrows = number of rows to return 
 * offset = skip offset rows of data
 * fetch = $ADODB_FETCH_MODE
 * 
 * example:
 *
 * http://localhost/php/server.php?select+*+from+table&nrows=10&offset=2
 */


/* 
 * Define the IP address you want to accept requests from 
 * as a security measure. If blank we accept anyone promisciously!
 */
$ACCEPTIP = '127.0.0.1';

/*
 * Connection parameters
 */
$driver = 'mysql';
$host = 'localhost'; // DSN for odbc
$uid = 'root';
$pwd = 'garbase-it-is';
$database = 'test';

/*============================ DO NOT MODIFY BELOW HERE =================================*/
// $sep must match csv2rs() in adodb.inc.php
$sep = ' :::: ';

include('./adodb.inc.php');
include_once(ADODB_DIR.'/adodb-csvlib.inc.php');

function err($s)
{
    die('**** '.$s.' ');
}

// undo stupid magic quotes
function undomq(&$m) 
{
    if (get_magic_quotes_gpc()) {
        // undo the damage
        $m = str_replace('\\\\','\\',$m);
        $m = str_replace('\"','"',$m);
        $m = str_replace('\\\'','\'',$m);

    }
    return $m;
}

///////////////////////////////////////// DEFINITIONS


$remote = $_SERVER["REMOTE_ADDR"]; 


if (!empty($ACCEPTIP))
 if ($remote != '127.0.0.1' && $remote != $ACCEPTIP) 
    err("Unauthorised client: '$remote'");


if (empty($_REQUEST['sql'])) err('No SQL');


$conn = ADONewConnection($driver);

if (!$conn->Connect($host,$uid,$pwd,$database)) err($conn->ErrorNo(). $sep . $conn->ErrorMsg());
$sql = undomq($_REQUEST['sql']);

if (isset($_REQUEST['fetch']))
    $ADODB_FETCH_MODE = $_REQUEST['fetch'];

if (isset($_REQUEST['nrows'])) {
    $nrows = $_REQUEST['nrows'];
    $offset = isset($_REQUEST['offset']) ? $_REQUEST['offset'] : -1;
    $rs = $conn->SelectLimit($sql,$nrows,$offset);
} else 
    $rs = $conn->Execute($sql);
if ($rs){ 
    //$rs->timeToLive = 1;
    echo _rs2serialize($rs,$conn,$sql);
    $rs->Close();
} else
    err($conn->ErrorNo(). $sep .$conn->ErrorMsg());

?>

我打算谷歌错误,但我认为他们是自我解释,我只是不知道为什么这个代码会给我包括他们不在那里,以及为什么它会给我参数未定义为在最后屏幕下方的通知。我猜我必须在某处放置一个IP地址,但我不知道在哪里,如果这就是全部。 BTW我有一个我可以登录的mysql数据库,我只是不知道如何将它与此结合起来。

如何继续学习本教程并使正在运行的聊天工作?

(编辑:我更新了screencap以反映在行中添加1到xampp,但它大致相同)

php sockets xampp
1个回答
2
投票

因为您从命令行运行PHP,所以$_SERVER["REMOTE_ADDR"]中没有值。您应该将该行更改为:

$remote = isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : '127.0.0.1';

或者如果您使用的是PHP7

$remote = $_SERVER["REMOTE_ADDR"] ?? '127.0.0.1';
© www.soinside.com 2019 - 2024. All rights reserved.