php - 根据 URL 参数重定向,如果 URL 参数在表行中可用 - PHP MySQL

标签 php mysql redirect mysqli url-parameters

我有一个表,其中一个属性是版本。

表名是版本。

如果 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/

相关文章:

mysql - MYSQL中用SUM连接表的问题

php - 使用 DB::raw 和 Eloquent 使用相同查询的不同结果

PHP: get_headers 设置临时 stream_context

php - 连接错误。数据库未连接

php - file_get_contents 无法打开流 : HTTP request failed! HTTP/1.1 500 内部服务器错误

java - com.mysql.jdbc.exceptions.jdbc4.CommunicationsException : Communications link failure

java - 使用自定义 AuthenticationFailureHandler 时为 302 而不是 200

linux - AWS : How to duplicate UDP traffic from PRD to TEST environment?

javascript - 将 Internet Explorer 8 及更低版本重定向到不同的网站

php - 通过 PHP 连接到 MySql 数据库句柄