gpt4 book ai didi

php - 是否可以将 php 代码插入 ' header("Location : example. php") ' 命令?

转载 作者:行者123 更新时间:2023-11-29 11:03:41 25 4
gpt4 key购买 nike

我在 php 代码块中有以下命令: header("Location: clivesclassiclounge_blogtest_single.php?loginsuccess");

我想修改 header 来查询数据库 - 例如: header("Location: clivesclassiclounge_blogtest_single.php?post=<?php echo $row['id']?>loginsuccess");

当我尝试进行设置时,我的编码程序/文本编辑器检测到错误(而且感觉很草率)。我觉得我以错误的方式解决这个问题,非常感谢任何建议。

谢谢

完整代码块:

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 字符串而不是 echo 例如

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 字符串运算符 http://php.net/manual/en/language.operators.string.php

将两个字符串连接在一起 How to combine two strings together in PHP?

关于php - 是否可以将 php 代码插入 ' header("Location : example. php") ' 命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41774737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com