Forums / Developer / Redirecting from own module to an URL with unordered params

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

eZ debug

Timing: Jan 18 2025 15:15:27
Script start
Timing: Jan 18 2025 15:15:27
Module start 'content'
Timing: Jan 18 2025 15:15:28
Module end 'content'
Timing: Jan 18 2025 15:15:28
Script end

Main resources:

Total runtime0.8986 sec
Peak memory usage4,096.0000 KB
Database Queries189

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0064 587.9688180.7969
Module start 'content' 0.00640.7605 768.7656507.5156
Module end 'content' 0.76690.1316 1,276.2813337.3359
Script end 0.8985  1,613.6172 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00400.4404210.0002
Check MTime0.00150.1638210.0001
Mysql Total
Database connection0.00080.088510.0008
Mysqli_queries0.830692.43201890.0044
Looping result0.00190.21221870.0000
Template Total0.869596.820.4347
Template load0.00200.224820.0010
Template processing0.867496.531120.4337
Template load and register function0.00010.010110.0001
states
state_id_array0.00100.109810.0010
state_identifier_array0.00100.112420.0005
Override
Cache load0.00170.1908250.0001
Sytem overhead
Fetch class attribute can translate value0.00140.161220.0007
Fetch class attribute name0.00180.195730.0006
XML
Image XML parsing0.00070.076320.0003
class_abstraction
Instantiating content class attribute0.00000.001540.0000
General
dbfile0.00220.2478280.0001
String conversion0.00000.000830.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
6content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 17
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs