How to redirect to another page?
Moderator: General Moderators
-
Phoenixheart
- Forum Contributor
- Posts: 123
- Joined: Tue Nov 16, 2004 7:46 am
- Contact:
How to redirect to another page?
Yes maybe I'm silly but can anyone tell me how to redirect the browser to another page. We have a response.redirect "anotherpage.asp" in ASP, but in php what is it?
-
Phoenixheart
- Forum Contributor
- Posts: 123
- Joined: Tue Nov 16, 2004 7:46 am
- Contact:
I tried it too! Say I have an insert_execute.php that will retreive values from a form in insert_products.htm, and after executing the query, it will then be redirected back to insert_products.htm. I'd rather use php than javascript (history.go(-1) etc.) and I tried to use header("Location:insert_products.htm"); And... it showed an error:
Cannot modify header information - headers already sent by (output started at D:\Saigonartframe Website\insertproducts.php:18)
So what's the problem?
Cannot modify header information - headers already sent by (output started at D:\Saigonartframe Website\insertproducts.php:18)
So what's the problem?
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
Can also use javascript - it's browser portable and less prone to errors than header(). Also you can use it even after output has been sent without resorting to caching...
Code: Select all
<?php
echo "<script>self.location='http://foo.com/bar.php';</script>";
// Optional notice to user they should enable javascript to use this - it's
//possible to detect javascript enabled option and use header() if required
echo "<noscript>Javascript is disabled in your browser - click <a href="http://foo.com/bar.php">Here</a> to continue.</noscript>";
?>- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact: