Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 351
  • Last Modified:

PHP redirect othern than Header Location


in my PHP scripts I need to send people to different pages depending on the results of my script, I've been using

header('Location: /yougohere.php');

but I was wondering if there was a better / cleaner solution to sending people to different pages?

  • 2
1 Solution
That solution is usually best, so long as your code is clean and any exceptions are handled, you won't run into any issues.

The other way to redirect is with HTML meta tags, and I would NOT recommend using those.

Unless you want to dynamically load content into your main window (different content for each user), you are using the cleanest way.

If you have a specific concern, post a new question and I will try to address it.

So ya, simple answer is: you found the correct key :)

Although the code you are using to determine placement may need improvement, I can't see it from here.
I would probably use  a SQL database of user urls tied to user names, so psuedo code would be: (using PEAR::DB)
$sql = "SELECT `url` FROM `users` WHERE `username` = '$username';";


header('Location: ' . $result['url']);

Open in new window

Instead od redirecting you could use the FrontController-Pattern http://en.wikipedia.org/wiki/Front_controller so there is no need for a redirect
In addition to previous answers/solutions you can use following ways (i will note previous posts,too):
+ using header (which you said in your question), and clear header before using it for clear errors or set error_responding to zero.
+ using javascript code which should echo and use die(); in next line.
+ using redirect html tag which should echo and use die(); in next line.
+ using Front Controller Pattern (as hernst42 said in post #36984127)
+ using apache mod_rewriting and in_line editing.

if you need additional information on each ways let me know.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now