开发者

Attempting to send array through GET method, but unable to unserialize

开发者 https://www.devze.com 2023-02-11 03:47 出处:网络
$subprompt = serialize($errors); header(\'Location: landingpage.php?success=false&prompt=\' . $prompt .开发者_JS百科 \'&subprompt=\' . $subprompt);
$subprompt = serialize($errors);
            header('Location: landingpage.php?success=false&prompt=' . $prompt .开发者_JS百科 '&subprompt=' . $subprompt);

then

if(isset($_GET['subprompt'])){

    $subprompt = $_GET['subprompt'];

    $subprompt = unserialize($subprompt);
print_r($subprompt);
}

I get all the data when I echo just the $_GET variable, however when I try to unserialize it I get nothing; a blank variable.


$subprompt = urlencode(serialize($errors));


urlencode is intended for this purpose.

$url_string = urlencode(serialize($errors));


Try this: Besides urlencode, you can try base64 encoding the data. A bit "prettier" url :)

$subprompt = base64_encode(serialize($errors));
            header('Location: landingpage.php?success=false&prompt=' . $prompt . '&subprompt=' . $subprompt);

And

if(isset($_GET['subprompt'])){
    $subprompt = $_GET['subprompt'];
    $subprompt = unserialize(base64_decode($subprompt));
print_r($subprompt);
}


To avoid encoding issues, you should send the value as base64_encode(serialize($subprompt)); instead. The result will be about a 33% longer string, so keep in mind to not exceed the maximum url length.

0

精彩评论

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