I am creating a series of QR codes with serial numbers with a URL; https://example.com/qr/qr.php?c=00000000000000001
I would like the various ranges of serial numbers to go to the appropriate page.
I had the idea to create a PHP page to handle the redirection, but I am struggling to get the numbers in the range.
Open to suggestions for alternative ways to do this.
<!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>
Any help is appreciated. Many thanks.
I believe the issue comes from the way you wrote the if statement?
Make sure $code
is of type integer:
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
}
See https://www.php.net/manual/en/language.operators.logical.php
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments