Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否可以将php代码插入到“header”(“Location:example.php”)”命令中?_Php_Mysql_Sql_Header - Fatal编程技术网

是否可以将php代码插入到“header”(“Location:example.php”)”命令中?

是否可以将php代码插入到“header”(“Location:example.php”)”命令中?,php,mysql,sql,header,Php,Mysql,Sql,Header,我在php代码块中有以下命令: headerLocation:clivesclassiclounge\u blogtest\u single.php?loginsucess 我想修改标题以查询数据库–类似于: headerLocation:clivesclassiclounge\u blogtest\u single.php?post=loginsucess 我的编码程序/文本编辑器检测到一个错误,当我试图设置它时,它也只是感觉马虎。我觉得我在这个问题上走错了方向,我真的很感激任何建议 谢谢 完

我在php代码块中有以下命令: headerLocation:clivesclassiclounge\u blogtest\u single.php?loginsucess

我想修改标题以查询数据库–类似于: headerLocation:clivesclassiclounge\u blogtest\u single.php?post=loginsucess

我的编码程序/文本编辑器检测到一个错误,当我试图设置它时,它也只是感觉马虎。我觉得我在这个问题上走错了方向,我真的很感激任何建议

谢谢

完整代码块:

function getLogin ($conn) {
    if (isset($_POST['loginSubmit'])) {
    $uid= mysqli_real_escape_string($conn, $_POST['uid']);
    $pwd= mysqli_real_escape_string($conn, $_POST['pwd']);

    $sql = "SELECT * FROM user WHERE uid='$uid' AND pwd='$pwd'";
    $result = mysqli_query($conn, $sql);
    if (mysqli_num_rows($result) > 0) {
        if ($row = $result->fetch_assoc()) {
            $_SESSION['id'] = $row['id'];
            $_SESSION['uid'] = $row['uid'];
            header("Location: clivesclassiclounge_blogtest_single.php?loginsuccess");
            exit();
        }
    } else {
        header("Location: clivesclassiclounge_blogtest_single.php?loginfailed");
        exit();
        }
    }
}

您可能希望连接URL字符串而不是回显,例如

if (mysqli_num_rows($result) > 0) {
    if ($row = $result->fetch_assoc()) {
        $_SESSION['id'] = $row['id'];
        $_SESSION['uid'] = $row['uid'];
        header("Location: clivesclassiclounge_blogtest_single.php?" . $row['id'] . "loginsuccess");
        exit();
    }
} else {
    header("Location: clivesclassiclounge_blogtest_single.php?loginfailed");
    exit();
    }
}
PHP字符串运算符

把两根绳子连在一起

我闻到这里潜伏着一个危险的想法。。。请注意,用户可以将URL中的id更改为他们想要的任何内容,这可能会带来严重的安全隐患。没有明显的理由需要它-您已经将它存储在$\u会话中了。