简体   繁体   中英

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=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!

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.

您可以将&编码为%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'));
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM