From phpBB Development Wiki
redirect –– Redirects the user to another page
mixed redirect ( $url [, $return [, $disable_cd_check ]] )
Redirects the user to another page then exits the script nicely. This function is intended for urls within the board. It's not meant to redirect to cross-domains.
|url (string)||Yes||The url to redirect to.|
|return (bool)||No (false)||If true, do not redirect but return the sanitized URL. Default is no return.|
|disable_cd_check (bool)||No (false)||If true, redirect() will redirect to an external domain. If false, the redirect point to the boards url if it does not match the current domain. Default is false.|
If the $return parameter is set to true, redirect returns a URL string. Otherwise, it will exit the script upon redirecting the user to the redirect URL.
Example #1 from viewtopic.php
This example shows the redirect function usage within the viewtopic.php page, which is redirecting the user to the topic if the post_id was incorrect but the topic_id was found.
// If post_id was submitted, we try at least to display the topic as a last resort...
if ($post_id && $forum_id && $topic_id)
Example #2 from viewforum.php
This example is from viewforum.php and takes the forum_link and redirects it to the URL you specified for that link forum.
// We redirect to the url. The third parameter indicates that external redirects are allowed.
redirect($forum_data['forum_link'], false, true);
Example #3 Redirect Bots/Spiders
In this example, we will ensure a user is logged in, if not, we display a login box. If they are a bot or spider, we will redirect them to the Board Index.
// is the user logged in?
// the user is a bot, send them back to home plate...
// the user is not logged in, give them a chance to login here...
- The third parameter disable_cd_check must be set to true to allow for external URL redirects, this is a security measure.
- To redirect other users to other pages, for instance after a performed action, use the meta_refresh function, this will display the current page for a specified number of seconds before redirecting the user to the redirect page