php - 查找序列号并重定向到适当的 url

标签 php html

我正在创建一系列带有 URL 序列号的 QR 码; https://example.com/qr/qr.php?c=00000000000000001

我希望各种范围的序列号转到相应的页面。

我想创建一个 PHP 页面来处理重定向,但我很难获得范围内的数字。

接受有关替代方法的建议。

<!DOCTYPE html>
<html>
<head>
<title>Finding your code ... </title>
</head>
<body>

<?php
// directs the user to page based on code

$code = $_GET['c'] ;
$page1 = 'https://example.com/dogs';
$page2 = 'https://example.com/cats';
$page3 = 'https://example.com/frogs';
$page4 = 'https://example.com/cows';



if( $code >= 1 || $code <= 10  or
    $code >= 100 || $code <= 150 )
 {
   //echo $page1 ; 
header('Location: .$page1') ;
    die() ;
}

if($code >= 11 || $code <= 20) {

 //      echo $page2 ; 
header('Location: .$page2') ;
    die() ;
}

if($code >= 21 || $code <= 30) {
    //        echo $page3 ; 
header('Location: .$page3') ;
    die() ;
}

if($code >= 31 || $code <= 40) {
    //    echo $page4 ; 
header('Location: .$page4') ;
    die() ;
}

?>
</body>
</html> 

感谢任何帮助。非常感谢。

最佳答案

我认为问题出在您编写 if 语句的方式上?

确保 $code 是整数类型:

var_dump($code);
if ( $code >= 1 && $code <= 10 || $code >= 100 && $code <= 150 ){
   // Do something when $code is between 1 and 10, or 100 and 150
}

参见 https://www.php.net/manual/en/language.operators.logical.php

关于php - 查找序列号并重定向到适当的 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64509879/

相关文章:

未收到 PHP 发布数据

javascript - .click() 函数被忽略

php - preg_replace 删除样式文本/css 标签

php - 如何提供我自己的 iOS ipa(ipad 安装)文件?

php - 用户设置的架构设计

php - 月度合计月份返回NULL,只输出运行合计

javascript - 如何在 HTML 中嵌入 XML 文件?

html - 如何将多个 css 径向渐变应用于单个元素

html - 无法在div中居中图像

php - Json到mysql数据库转换