我正在创建一系列带有 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/