如何将值传递给header()函数?

Vis*_*er7 0 php parsing header

我必须将用户重定向到不同的页面.所以这就是我现在所拥有的.

header('Location: http://www.example.com/$confirmpage')
Run Code Online (Sandbox Code Playgroud)

但它不起作用.它将它们重定向到http://www.example.com/ $ confirmpage(未检索到值.)并给出404错误.

我用的时候

echo "<script>document.location='http://www.example.com/$confirmpage';</script>";
Run Code Online (Sandbox Code Playgroud)

有用.

但由于某些原因,我必须使用header()函数.

19g*_*g96 5

header("Location: http://www.example.com/$confirmpage")
Run Code Online (Sandbox Code Playgroud)

如果你想在php字符串中引用变量,你必须使用"而不是'

http://php.net/manual/en/language.types.string.php