如何使用PHP获取asp cookie的名称和值,以便将其分配给变量? PHP和ASP在同一个域中。
经典Asp创建Cookie
response.cookies("apple")("red")="reddelicious"
response.cookies("apple")("yellow")="gingergold"
response.cookies("apple")("green")="grannysmith"
response.cookies("apple").expires = dateadd("d",2,Now())
经典ASP阅读Cookie
strRed = request.cookies("apple")("red")
strYellow = request.cookies("apple")("yellow")
strGreen = request.cookies("apple")("green")
使用PHP echo
读取ASP cookieecho $_COOKIE["apple"];
在萤火虫中,扩大了苹果'控制台内的cookie,' echo $ _COOKIE [" apple"]'输出:
red=reddelicious&yellow=gingergold&green=grannysmith
尝试:
$strRed = $_COOKIE["apple"]["red"]; //doesn't work
答案 0 :(得分:1)
你可以使用php中的parse_str函数
<?php
parse_str($_COOKIE["apple"], $apple);
echo($apple["red"]);
?>
答案 1 :(得分:0)
要将字符串red=reddelicious&yellow=gingergold&green=grannysmith
设置为多维数组的格式,请尝试:
$itemArray = explode('&', $_COOKIE['apple']); // Split variables at '&'
foreach($itemArray as $item){ // for each variable pair 'key=value'
$itemParts = explode('=', $item); // split string to '[key, value]'
$apple[$itemParts[0]] = $itemParts[1]; // set each item to $apple[key] = value;
}
然后你可以使用这样的变量:
$strRed = $apple["red"]; //should work :)