PHP头重定向无法使用变量

PHP头重定向无法使用变量,php,html,Php,Html,我已经回显了标题,语法似乎正确,但重定向不起作用 页面根据URL确定代码 if语句可以正确地确定需要哪个页面,但标头没有将用户重定向到指定的URL 谁能看出我做错了什么 <!DOCTYPE html> <html> <head> <title>Finding your code ... </title> </head> <body> <?php // directs the user to page

我已经回显了标题,语法似乎正确,但重定向不起作用

页面根据URL确定代码

if语句可以正确地确定需要哪个页面,但标头没有将用户重定向到指定的URL

谁能看出我做错了什么



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

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

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




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

//echo $page1 ; 
$url = $page1 ; 
header("Location: $url") ;
  die() ;
}

if($code >= 11 && $code <= 20) {
$url = $page2 ; 
echo $url ; 
header("Location: $url") ;
    die() ;
}

if($code >= 21 && $code <= 30) {
$url = $page3 ; 
header("Location: $url") ;
    die() ;
}

if($code >= 31 && $code <= 40) {
$url = $page4 ; 
header("Location: $url") ;
    die() ;
}


else {
$url = $page5 ; 
header("Location: $url") ;
    die() ;
}




?>

</body>
</html>


正在查找您的代码。。。

感谢您在字符串中使用变量时使用“”引号。因此请替换
标题('Location:$url')带有
标题(“位置:$url”)

为什么“不工作”是比重定向url中出现“%24url”更好的问题描述?我不确定您的意思。我在url中找不到%24。如果我打印或回显URL,甚至是带有“`` If”的标题代码($code>=1&&$code=100&&$code添加了更多重复项。谢谢..我已经尝试过了。我已经更新了我的代码。我仍然得到相同的响应。页面没有重定向到页眉。相反,我停留在页面上,屏幕是空白的。模具是否过早地将其杀死?是的,不要在
页眉之后使用
模具
退出
。阅读本文,谢谢。这解决了问题。将标题放在die()中解决了问题。die(标题(“位置:$url”);