我有一个表,其中一个属性是版本。
表名是版本。
如果 URL 参数(也称为版本)为 NULL 或不存在,并且版本值不在我的表中,我想将用户重定向到默认页面。
到目前为止,我有这个。它不起作用。
$stonevar = isset($_GET['version']) ? $_GET['version'] : NULL;
if (empty($stonevar)) {
header("Location: index.php?version=default");
}
$id = $_GET['version'];
$result = $db->query("SELECT * FROM `versions` WHERE version='$id'");
while ($row = $result->fetch_assoc()) {
$varex = $row['version'];
}
if ($varex == NULL) {
header("Location: index.php?default");
}
最佳答案
你必须添加 exit();在头函数之后。
尝试这样的事情:
<?php
$stonevar = isset($_GET['version']) ? $_GET['version'] : NULL;
if (empty($stonevar)) {
header("Location: index.php?version=default");
exit();
}
$result = $db->query("SELECT * FROM `versions` WHERE version='$stonevar'");
while ($row = $result->fetch_assoc()) {
header("Location: index.php?".$row['version']);
exit();
/*
* or something you want to do if version exist
*/
}
header("Location: index.php?default");
exit();
?>
关于php - 根据 URL 参数重定向,如果 URL 参数在表行中可用 - PHP MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36090127/