Redirect issues

japanitrat - November 25, 2008 - 21:53
Project:Redirect 403 to User Login
Version:6.x-1.2
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs work
Description

I just peeked over this module, since i am currently developing something similar. Now that i solved it, i want to share some.

As i can see for 6.x, this module utilizes its own redirect header statement. I suggest to use drupal_goto('path', drupal_get_destination()), since it will shutdown drupal's flow correctly. Also drupal_get_destination() includes other query-variables, not only the internal drupal-path, as well as messages that has been set before.

The mentioned recursive redirect loop can be avoided by checking the path against 'user' in arg(0).

AttachmentSize
r4032login-6--1.patch1 KB

#1

Bevan - January 6, 2009 - 02:10
Status:needs review» needs work

Redirect gets in infinite loop as anonymous user hitting node/add with i18n path prefixes.

#2

Bevan - January 6, 2009 - 02:40
Status:needs work» needs review

This version of the patch employs drupal_get_destination(), but not drupal_goto() or the check for arg(0) == 'user'. This enables the module to work with i18n language prefixes, and doesn't infinitely redirect.

Without using drupal_get_destination() while i18n path prefixes are enabled, the module redirects to, for example en/en/node/add. Note the double-occurrence of the language prefix en. This results in a 404 Page not found error.

AttachmentSize
339120.patch 595 bytes

#3

deekayen - July 13, 2009 - 16:02
Status:needs review» fixed

committed to DRUPAL-6--1 and HEAD

@Bevan, your patch didn't conform to http://drupal.org/patch/create, but I used it anyway since it was so small.

#4

deekayen - July 14, 2009 - 05:06
Category:feature request» bug report
Status:fixed» needs work

From Bevan:

Upon going to /admin as an anonymous user, the browser is redirected to /user/login?destination=r4032login instead of /user/login?destination=admin.

@Bevan: it's your patch... roll it back?

#5

deekayen - July 14, 2009 - 05:09

@Bevan: I added you to CVS so you can just fix it instead of having to roll patch. I ended up committing it to DRUPAL-5, DRUPAL-6--1, DRUPAL-7--1, and HEAD, so this makes quite a mess.

#6

deekayen - July 14, 2009 - 14:50
Status:needs work» postponed (maintainer needs more info)

Nevermind, I rolled it back. Is there still some underlying problem from the original issue submission that needs to be resolved?

#7

Bevan - July 14, 2009 - 20:00
Status:postponed (maintainer needs more info)» needs work

(#518534: Redirects to /r4032login instead of old path was marked duplicate.)

I haven't tested whether #518534: Redirects to /r4032login instead of old path is a result of this (#339120: Redirect issues) change or not. I'm merely wondering. I would expect that I would have noticed a bug as significant as this in developing the patch. Perhaps there are other or more obscure causes? Have you tested?

I don't have time to work on it this week, but will probalby get around to it sooner or later...

#8

Bevan - July 14, 2009 - 21:02

It turns out drupal_get_destination() is indeed the cuprit here. This needs rerolling. Possibly we should state on the project page that this module is not compatible with i18n path prefixes, in the meanwhile?

#9

ianchan - July 16, 2009 - 21:16

subscribe

#10

Bevan - July 28, 2009 - 06:49

I think the cleanest way to fix this is to check for language prefixes in $_GET['q']. But this would require quite a bit of fairly ugly code, and I couldn't find the code that does this already in Drupal to see if there is something re-usable.

#11

Breakerandi - September 2, 2009 - 14:24
Version:6.x-1.x-dev» 6.x-1.2

i18n redirect still not working on 6.12, will it be fixed soon?

#12

Bevan - September 14, 2009 - 18:36

Breakerandi; Patches welcome

#13

Breakerandi - September 14, 2009 - 19:18

My profession is to report bugs, I can't do anymore for the community because I know nothing about php.. sorry..

#14

geraldito - September 28, 2009 - 22:29

I don' t get what's the point of #4 as for me patch from #2 fixed the redirection problem with i18n.
@#1: anonymous user hitting node/add with i18n path prefixes doesn't effect an infinite loop on my site (maybe because there is content creation allowed for anonymous users?)
@#1: anonymous user hitting /admin gets redirected to user/login?destination=admin so for me everything seems to be fixed with this patch.

#15

mike-l - October 10, 2009 - 09:14

I find this bug too... and I see only 1 way how to fix this issue.
idea is:
remove laguage prefix.

in the
r4032login.module

$destination = drupal_urlencode($_REQUEST['q']);

i suggest to rewrite like this:
$destination = removeLanguagePrefixFromDestination(drupal_urlencode($_REQUEST['q']));

and add new function:

function removeLanguagePrefixFromDestination($destination)
{
$elements = explode('/', $destination);
$prefix = $elements[0];
$languages = language_list();
foreach ($languages as $lang)
if(strcasecmp($prefix, $lang->language)==0)
return substr($destination, strlen($prefix)+1); // remove prefix with slash
return $destination;
}

and everything works fine

any thoughts about this solution are welcome )
-----------------------------------------------------------------------------------
patch #2 doesn't work in my case

AttachmentSize
patch.patch 599 bytes

#16

mike-l - October 10, 2009 - 09:16

i'm sorry but in my previous message patch.patch was not correctly generated .I recommited it in this message.

AttachmentSize
patch.patch 806 bytes

#17

Bevan - October 19, 2009 - 03:46

mike-l, Please see the Drupal coding standards. Among other things removeLanguagePrefixFromDestination() should be r4032login_remove_language_prefix_from_destination().

However I think there is a Drupal core API function for this – I think it's arg() with no parameters, or drupal_get_normal_path().

 
 

Drupal is a registered trademark of Dries Buytaert.