Skip to content

Commit

Permalink
Feature Issue ID 0000602: Redirect must be done by html or http
Browse files Browse the repository at this point in the history
Redirect it's only done by the html method but must be done too with http method.
Creation of two functions redirect_http and redirect_html.
Function redirect calls one or other functions follow $conf or parameters.

$conf value are true on BSF, in order to check modifications.
Must be set to false on RC.

git-svn-id: http://piwigo.org/svn/trunk@1649 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
rub committed Dec 11, 2006
1 parent 222afe2 commit d54d1a5
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
3 changes: 3 additions & 0 deletions include/config_default.inc.php
Expand Up @@ -240,6 +240,9 @@
// rate_items: available rates for a picture
$conf['rate_items'] = array(0,1,2,3,4,5);

// Define default method to use ('http' or 'html' in order to do redirect)
$conf['default_redirect_method'] = 'http';

// +-----------------------------------------------------------------------+
// | metadata |
// +-----------------------------------------------------------------------+
Expand Down
51 changes: 49 additions & 2 deletions include/functions.inc.php
Expand Up @@ -600,7 +600,28 @@ function pwg_debug( $string )
}

/**
* Redirects to the given URL
* Redirects to the given URL (HTTP method)
*
* Note : once this function called, the execution doesn't go further
* (presence of an exit() instruction.
*
* @param string $url
* @return void
*/
function redirect_http( $url )
{
if (ob_get_length () !== FALSE)
{
ob_clean();
}
header('Request-URI: '.$url);
header('Content-Location: '.$url);
header('Location: '.$url);
exit();
}

/**
* Redirects to the given URL (HTML method)
*
* Note : once this function called, the execution doesn't go further
* (presence of an exit() instruction.
Expand All @@ -610,7 +631,7 @@ function pwg_debug( $string )
* @param integer $refreh_time
* @return void
*/
function redirect( $url , $msg = '', $refresh_time = 0)
function redirect_html( $url , $msg = '', $refresh_time = 0)
{
global $user, $template, $lang_info, $conf, $lang, $t2, $page, $debug;

Expand Down Expand Up @@ -652,6 +673,32 @@ function redirect( $url , $msg = '', $refresh_time = 0)
exit();
}

/**
* Redirects to the given URL (Switch to HTTP method or HTML method)
*
* Note : once this function called, the execution doesn't go further
* (presence of an exit() instruction.
*
* @param string $url
* @param string $title_msg
* @param integer $refreh_time
* @return void
*/
function redirect( $url , $msg = '', $refresh_time = 0)
{
global $conf;

// with RefeshTime <> 0, only html must be used
if (($conf['default_redirect_method'] == 'http') and ($refresh_time == 0))
{
redirect_http($url);
}
else
{
redirect_html($url, $msg, $refresh_time);
}
}

/**
* returns $_SERVER['QUERY_STRING'] whitout keys given in parameters
*
Expand Down
4 changes: 2 additions & 2 deletions include/functions_html.inc.php
Expand Up @@ -609,7 +609,7 @@ function access_denied()
else
{
set_status_header(401);
redirect($login_url);
redirect_html($login_url);
}
}

Expand All @@ -623,7 +623,7 @@ function page_not_found($msg, $alternate_url=null)
set_status_header(404);
if ($alternate_url==null)
$alternate_url = make_index_url();
redirect( $alternate_url,
redirect_html( $alternate_url,
'<div style="text-align:left; margin-left:5em;margin-bottom:5em;">
<h1 style="text-align:left; font-size:36px;">Page not found</h1><br/>'
.$msg.'</div>',
Expand Down

0 comments on commit d54d1a5

Please sign in to comment.