开发者

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

$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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜