0

我有一个 json 字符串,它被附加到一个 url,然后放入一个 php cookie。

//redirect url with short json string appended
echo "<script type=\"text/javascript\">document.location = \"site/temp_process.php?ui=". urlencode(json_encode($user_information)) ." \";</script>";//$user_information is php assoc. array


$user_information = urldecode($_REQUEST['ui']); //user information

setcookie('isco', $user_information, time()+60*60*24*30);

然后用这个 javascript 函数读取 cookie :

cookie = readCookie("isco");
cookie = decodeURIComponent(cookie);


function readCookie(name) {  
    var cookiename = name + "=";  
    var ca = document.cookie.split(';');  
    for(var i=0;i < ca.length;i++){  
        var c = ca[i];  
        while (c.charAt(0)==' ') c = c.substring(1,c.length);  
        if (c.indexOf(cookiename) == 0) return c.substring(cookiename.length,c.length);  
    }  
    return null;  
}  

但无论我删除 javascriptdecodeURIComponent还是切换 php urlencode/urldecode rawurlencode/rawurldecode,我仍然会得到显示为+标志的空格。我怎样才能避免这种情况?

非常感谢!

4

0 回答 0