开发者

Passing on multiple GET variables with the "next" parameter in the URL

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

I'm redirecting users to the login page:

login?next=initial_page?email=john_doe@gmail.com&activate_key=1421sdxz开发者_高级运维cxz213xz

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!


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

echo '<a href="login?next=' . urlencode('initial_page?email=john_doe@gmail.com&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.


You can URL-encode the & as %26.


login?next=initial_page?email=john_doe@gmail.com&amp;activate_key&amp;1421sdxzcxz213xz


Try this:

header('Location: login?next='.rawurlencode('initial_page?email=john_doe@gmail.com&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('initial_page?email=john_doe@gmail.com&activate_key=1421sdxzcxz213xz'));
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜