简体   繁体   中英

How do I pass a value into a header() function?

I have to redirect users to different pages. So here is what I have now.

header('Location: http://www.example.com/$confirmpage')

But it doesn't work. It redirects them to http://www.example.com/ $confirmpage (value not retrieved.) and gives 404 error.

When I use

echo "<script>document.location='http://www.example.com/$confirmpage';</script>";

It works.

But I have to use header() function for some reasons.

header("Location: http://www.example.com/$confirmpage")

If you want to refference variables in php strings, you have to use " instead of '

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM