aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMeik Sievertsen <acydburn@phpbb.com>2006-03-14 13:29:12 +0000
committerMeik Sievertsen <acydburn@phpbb.com>2006-03-14 13:29:12 +0000
commit0572b6efbf9843957638ae7d4b1d4640a400c8ad (patch)
tree24fa5f112c7af35e9595caba61be15ad29ab9faa
parent148f259bde6e377571cf592e0bfd508d948639b5 (diff)
downloadforums-0572b6efbf9843957638ae7d4b1d4640a400c8ad.tar
forums-0572b6efbf9843957638ae7d4b1d4640a400c8ad.tar.gz
forums-0572b6efbf9843957638ae7d4b1d4640a400c8ad.tar.bz2
forums-0572b6efbf9843957638ae7d4b1d4640a400c8ad.tar.xz
forums-0572b6efbf9843957638ae7d4b1d4640a400c8ad.zip
slightly different redirect function (now hopefully able to handle all sorts of uris)
git-svn-id: file:///svn/phpbb/trunk@5626 89ea8834-ac86-4346-8a33-228a782c2dd0
-rw-r--r--phpBB/includes/functions.php66
1 files changed, 54 insertions, 12 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index a646cfcd7c..01b6591488 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -1095,8 +1095,9 @@ function on_page($num_items, $per_page, $start)
/**
* Generate board url (example: http://www.foo.bar/phpBB)
+* @param bool $without_script_path if set to true the script path gets not appended (example: http://www.foo.bar)
*/
-function generate_board_url()
+function generate_board_url($without_script_path = false)
{
global $config, $user;
@@ -1119,16 +1120,17 @@ function generate_board_url()
{
$url .= ':' . $server_port;
}
-
- $url .= $user->page['root_script_path'];
- return $url;
+ if ($without_script_path)
+ {
+ return $url;
+ }
+
+ return $url . $user->page['root_script_path'];
}
/**
* Redirects the user to another page then exits the script nicely
-* Do not prepend url with $phpbb_root_path
-* If not prefixed by / or full url given the board url will be prefixed
*/
function redirect($url)
{
@@ -1147,18 +1149,58 @@ function redirect($url)
// Make sure no &amp;'s are in, this will break the redirect
$url = str_replace('&amp;', '&', $url);
- // If relative path, prepend board url
- if (strpos($url, '://') === false && $url{0} != '/')
- {
- $url = generate_board_url() . '/' . $url;
- }
-
// Make sure no linebreaks are there... to prevent http response splitting for PHP < 4.4.2
if (strpos(urldecode($url), "\n") !== false || strpos(urldecode($url), "\r") !== false)
{
trigger_error('Tried to redirect to potentially insecure url.', E_USER_ERROR);
}
+ // Determine which type of redirect we need to handle...
+ $url_parts = parse_url($url);
+
+ if ($url_parts === false)
+ {
+ // Malformed url, redirect to current page...
+ $url = generate_board_url() . '/' . $user->page['page'];
+ }
+ else if (!empty($url_parts['scheme']) && !empty($url_parts['host']))
+ {
+ // Full URL
+ }
+ else if ($url{0} == '/')
+ {
+ // Absolute uri, prepend direct url...
+ $url = generate_board_url_2(true) . $url;
+ }
+ else
+ {
+ // Relative uri
+ $pathinfo = pathinfo($url);
+
+ // Is the uri pointing to the current directory?
+ if ($pathinfo['dirname'] == '.')
+ {
+ $url = generate_board_url() . '/' . $user->page['page_dir'] . '/' . str_replace('./', '', $url);
+ }
+ else
+ {
+ $url = str_replace($pathinfo['dirname'] . '/', '', $url);
+
+ // Make sure we point to the correct directory, we transform the relative uri to an absolute uri...
+ $substract_path = str_replace(realpath($pathinfo['dirname']), '', realpath('./'));
+ $dir = str_replace($substract_path, '', $user->page['script_path']);
+
+ if (!$dir)
+ {
+ $url = '/' . $url;
+ }
+ else
+ {
+ $url = (strpos($dir, '/') !== 0) ? '/' . $dir . '/' . $url : $dir . '/' . $url;
+ }
+ }
+ }
+
// Redirect via an HTML form for PITA webservers
if (@preg_match('#Microsoft|WebSTAR|Xitami#', getenv('SERVER_SOFTWARE')))
{