Redirecting from own module to an URL with unordered params

Author Message

Piotrek Karaś

Friday 07 December 2007 3:14:24 am

I've got an extension with its own module/view combination. Based on POST variables sent to it, the view PHP script has to assemble an URL that may contain unordered parameters, to which the view should be redirected.

Example: /myextension/modules/mymodule/myview.php:

<?php (...)
$myURL = 'content/view/full/999';
if( $http->hasPostVariable( 'xParam' ) )
{
  $myURL .= '/(xparam)/'.$http->postVariable( 'xParam' );
}
(...)
$Module->redirectTo( $myURL );
(...) ?>

If I use the above, the URL after redirection will be:
/content/view/full/999/<b>%28xparam%29</b>/value
and the template will not be able to the value of xparam.

Can anyone suggest a solution or other direction? I did look at http and uri ezutils, but didn't find anything that would suggest what's wrong or at what layer. I also suspect there a method that would prepare my URL based on a parameter array, but couldn't find one, either.

I thought this may be eZ independent, but made a quick test:

<?php
header('Location: http://172.30.0.95/tmp_redirect/target.php/(param)/value');
exit();
?>

The URL after redirection looks fine...

Thanks for any suggestions!

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

Piotrek Karaś

Friday 07 December 2007 5:10:08 am

Not for the first time further digging brings effects ;)

I followed all the path that script takes after redirection declaration, through /index.php and back to the eZHTTPTool, and then it became clear: eZHTTPTool::redirect is to be blame for what goes wrong with the brackets. So I took from it what I felt would be essential (almost everything) and here's my solution:

I secure unknown parts of the URL myself:

if( $http->hasPostVariable( 'xParam' ) )
{
 $myURL .= '/(xparam)/'.eZURI::encodeURL( $http->postVariable( 'xParam' ) );
}

Then, instead of using traditional redirection, I use this:

$url = eZHTTPTool::createRedirectUrl( $path, array() );

if ( strlen( $Module->RedirectStatus ) > 0 )
{
	header( $_SERVER['SERVER_PROTOCOL'] .  " " . $status );
	eZHTTPTool::headerVariable( "Status", $status );
}

// I REMOVE THIS LINE!
// $url = eZURI::encodeURL( $url );
eZHTTPTool::headerVariable( 'Location', $url );

echo '<HTML><HEAD>';
echo '<META HTTP-EQUIV="Refresh" Content="0;URL='. htmlspecialchars( $url ) .'">';
echo '<META HTTP-EQUIV="Location" Content="'. htmlspecialchars( $url ) .'">';
echo '</HEAD><BODY></BODY></HTML>';

What do you think? Any other way?

<b>By the way, since brackets are used by the system, shouldn't they be left alone by the eZURI::encodeURL? Isn't that a little inconsistency?</b>

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.