Link to home
Start Free TrialLog in
Avatar of Teshket
Teshket

asked on

PHP redirect othern than Header Location

Hi,

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?

ASKER CERTIFIED SOLUTION
Avatar of themrrobert
themrrobert
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.