1

我有一个非常奇怪的问题。下面是我的页面。在第 11 行,当用户通过 if($row_cnt == '1') 存在时,我基本上包括了我的 xajax 库和我的 php 函数。

现在所有代码都可以正常工作(当我删除 if 语句时),但是当它位于 IF 语句中时,它就像不包括我的 xajax.inc.php 文件一样。

当我在声明 $test 并删除 else 语句后关闭我的 IF 语句时,代码 100% 工作,它甚至将 $test 值正确传递给我的函数,所以我知道我的 IF 语句是正确的。

确切的代码在我自己的 3 台服务器上完美运行,但无法在我的客户端服务器上运行。所以我只能认为它一定是某种服务器设置正在这样做,但不知道它可能是什么设置。

<?php
$config = parse_ini_file('config/config.ini'); 
$mysqli = mysqli_connect($config['server'],$config['username'],$config['password'],$config['dbname'],3306);
$_login_password = mysqli_real_escape_string($mysqli, $_POST['login_password']);
$sql = "SELECT 
a.`id`, a.`name`, a.`surname`, `username`, `password`, `user_level`   
FROM `comp_mfm_users` AS a 
WHERE (a.`username`='$_POST[login_username]' AND a.`password`='$_login_password') LIMIT 1";
$result = $mysqli->query($sql);
$row_cnt = $result->num_rows;
if($row_cnt == '1'){
$test = "IN";

include_once("xajax/xajax_core/xajax.inc.php");

$xajax = new xajax();

// Included Functions
require_once("functions/test.php");
// Request
$xajax->processRequest();
}
else{
$test = "OUT";
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<?php $xajax->printJavascript('xajax/'); ?>
</head>

<body>
<script type="text/javascript">
var clicks = 0;
    function onClick() {
        var php = "<?php echo "$test" ?>";
        clicks += 1;
        xajax_test(clicks,php);
    };
</script>
<div id="mainContent"><?php echo "$test" ?></div>
<input type="button" value="click Here" onclick="onClick();">
</body>
</html>

我正在调用的函数:

<?php
$xajax->registerFunction("test");
function test($in,$in2){

$content = <<<EOF_
Teast Page : $in : $in2
EOF_;


$objResponse = new xajaxResponse();
$objResponse->assign("mainContent","innerHTML", $content);
return $objResponse;    
}
?>

好吧,这完全让我失望了。我尝试了一种不同的方法并跳过 IF 语句来加载包含。Xajax 仍然没有执行。php代码正在工作,当用户名和密码正确时它正在加载页面,当它再次不正确时它退出,php代码中没有错误。但是,当我删除时,这是最重要的部分:

if($stmt->num_rows !== 1){
echo "You are logged out";
exit();
}

一切都很好,一切正常,除了没有用户验证。所以我更进一步,移动了:

if($stmt->num_rows !== 1){
echo "You are logged out";
exit();
}

线下/线后:

// Request
$xajax->processRequest();

一切都在 100% 工作。这根本没有意义!我采用确切的代码并在我的测试服务器上运行它,它与下面的代码一样工作 100%,但是当我把它放在客户端服务器上时,我必须将 IF 语句移到上面提到的行工作。问题仍然是我不能使用这段代码,安全性不是很好,页面可以在 exit() 之前停止;命令,所以我需要包含在 IF 语句中。

所以真正的问题是为什么客户端服务器会这样,它必须是 .ini 文件中的 php 设置,但女巫是百万美元的答案。

下面是带有 IF 语句的更改代码仍然在包含它不在客户端服务器上工作但它在我的测试服务器上工作的地方。

<?php
$config = parse_ini_file('config/config.ini'); 
$mysqli = mysqli_connect($config['server'],$config['username'],$config['password'],$config['dbname'],3306);
$_login_password = mysqli_real_escape_string($mysqli, $_POST['login_password']);

$stmt = $mysqli->prepare("
SELECT 
a.`id`, a.`name`, a.`surname`, `user_level`   
FROM `comp_mfm_users` AS a 
WHERE a.`username`=? AND a.`password`=? LIMIT 1
");
$stmt->bind_param('ss', $_POST[login_username], $_login_password);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($myrow[id], $myrow[name], $myrow[surname], $myrow[user_level]);
$stmt->fetch();

if($stmt->num_rows !== 1){
echo "You are logged out";
exit();
}

include_once("xajax/xajax_core/xajax.inc.php");

$xajax = new xajax();

// Included Functions
require_once("functions/test.php");

// Request
$xajax->processRequest();
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<?php $xajax->printJavascript('xajax/'); ?>
</head>

<body>
<script type="text/javascript">
var clicks = 0;
    function onClick() {
        var php = "in";
        clicks += 1;
        xajax_testpp(clicks,php);
    };
</script>
<?php
$dis = <<<EOF_
<div id="mainContent">$myrow[surname]</div>
<input type="button" value="click Here" style="cursor:pointer" onclick="onClick();">
EOF_;
echo"$dis";
?>
</body>
</html>
4

0 回答 0