views:

25

answers:

4

I'm having issues passing on multiple $_GET variables with "next".

I'm redirecting users to the login page:

[email protected]&activate_key=1421sdxzcxz213xz

The problem is that the activation key is treated as a second $_GET parameter on the login page (along with "next"), instead of being part of the redirected $_GET.

A solution would be to use cookies, is there any way I can still make this work with $_GET though?

Thanks!

+1  A: 

You can URL-encode the & as %26.

Franci Penov
+6  A: 

You need to use urlencode to encode the parameter data--something like this:

echo '<a href="login?next=' . urlencode('[email protected]&activate_key=1421sdxzcxz213xz') . '">link</a>';

This will produce a link like this:

<a href="login?next=initial_page%3Femail%3Djohn_doe%40gmail.com%26activate_key%3D1421sdxzcxz213xz">link</a>

...which will be interpreted correctly.

Jordan
Awesome, thanks a lot, it worked :)
Cat
A: 
[email protected]&amp;activate_key&amp;1421sdxzcxz213xz
Webarto
A: 

Try this:

header('Location: login?next='.rawurlencode('[email protected]&activate_key=1421sdxzcxz213xz'));

which automatically generates a 302 response.

Test code:

<?php
if (isset($_GET['next']))
    print $_GET['next'];
else
    header('Location: '.$_SERVER['REQUEST_URI'].'?next='.rawurlencode('[email protected]&activate_key=1421sdxzcxz213xz'));
?>
Remoun