Tuesday, December 28, 2010

php redirecting

I was searching for a way to redirect in php scripts to other pages.
Having used Javascript before, the obvious answer in front of me was using js inside php as follows:

<?php echo '<script>window.location = "page.html";</script>'; ?>

It works completely fine. But it isn't php exactly. So I looked on.
Another option I came upon was the php function header(), which also works fine and has the following format:

<?php header("location: page.html"); ?>

I had a little doubt though. If I am using the header function in the middle if a php script, then it works fine. But in the php manual of this function http://php.net/manual/en/function.header.php, they clearly state that this function should only be used before any html tag or any php print command. Will look for answers. If the reader knows, he is requested to comment.

No comments:

Post a Comment

Recent Articles