过去5个小时,我一直在研究为什么如果被触发...
让我向您展示代码并向您解释:
<?php
require_once "ConnectDB.php";
$link2 = $link;
$key = $posthwid = "";
$err = "";
if($_SERVER["REQUEST_METHOD"] == "POST"){
if(empty($_POST["key"])){
$err = "Thanks for the ip (" .$_SERVER['REMOTE_ADDR']. "), have a good day! (1)";
}
else{
$key = trim($_POST["key"]);
}
$hwid = $_POST["hwid"];
if(empty($err)){
$sql = "SELECT hwid, idkey, length, created_at FROM money WHERE idkey = '" .$key. "'";
$row = mysqli_query($link, $sql);
if(mysqli_num_rows($row) < 2){
while($result = mysqli_fetch_assoc($row)) {
if($result["idkey"] == $key)
{
$err = "key";
if($result["hwid"] == "")
{
$err = "nohwid";
$sql2 = "UPDATE IceCold SET hwid = '" .$hwid. "' WHERE idkey = '" .$key. "'";
if(mysqli_query($link2, $sql2)){
$hwid = $result["hwid"];
mysqli_close($link2);
echo "debug";
}
else {
$err = "Oops! Something went wrong. Contact the support.";
}
}
if ($hwid !== $result["hwid"]) {
$err = "Contact the support";
}
elseif($_SESSION["admin"] == true) {
//Do special stuff
}
else {
///do other checks
if($created_at > $date){
$err = $hwid;
} else {
$err = "The key date is too old, buy a new one.";
}
}
}
else{
$err = "The key you entered was not valid.";
}
} mysqli_close($link);
} else {
$err = "multiple entry, contact support";
}
}
} else {
$err = "Thanks for the ip (" .$_SERVER['REMOTE_ADDR']. "), have a good day! (3)";
}
echo $err;
?>
因此,基本上,我有一个名为$link
的带有mysqli_connect的Connect数据库文件,并且正在为我的程序设计一个Liscence API。我的程序将发送带有“ idkey”和“ hwid”的请求,并且正在等待该wid返回。我在sql数据库中有一个仅注册了密钥的条目,并且试图通过生成带有id和随机hwid的POST请求来使程序wotk出现,但未成功。如果怪异地移动变量,那是因为调试。
现在,在我当前的设置下,我得到了“联系”支持回复,但我不明白为什么?!?如果我能够获得此遮篷,则请求和键是正确的。 这可能是一个愚蠢的错误,但我无法理解...
预先感谢您的帮助
编辑:我指的是if
语句:
if($hwid !== $result["hwid"])
我修复的代码中有错别字,但这不是问题, 至于elseif,这将破坏代码的执行顺序并破坏其背后的逻辑(如果这样的话)。
奇怪的是,经过一些测试,我发现我发送的第二个SQL请求不想执行($ sql2),并且httpd日志中没有错误...您可以执行两个请求吗?我尝试创建$ link2,但它没有任何改变
EDIT :找到的解决方案
if($result["hwid"] == "")
{
$sql2 = "UPDATE money SET hwid = '" .$_POST["hwid"]. "' WHERE idkey = '" .$key. "'";
if(mysqli_query($link2, $sql2)) {
$newhwid = $_POST["hwid"];
mysqli_close($link2);
}
else {
$err = "Oops! Something went wrong. Contact the support.";
}
}
elseif ($_POST["hwid"] != $result["hwid"]) {
$err = "Contact the support";
}
if($_POST["hwid"] == $newhwid || $_POST["hwid"] == $result["hwid"] ) {
/// do other checks
}
答案 0 :(得分:-1)
if($row['hwid'] = "")
之前的条件是一项分配。此代码将$row['hwid']
的值更改为空字符串,导致其后的条件为true。我假设您打算在==
为空时将$row['hwid']
写入 test ;否则,将其写为if
语句就没有意义。
顺便说一下,尚不清楚此if
语句是否不应该是else if
。这里的其余分支是else if
(或elseif
,在PHP中是相同的),因此您应该考虑是否也错过了else
。 >