下面程序全部显示了
而且重复的不能提前$action=$_GET["action"];
$temp=$_COOKIE["last_product_view"];
if($action==1){
if(is_array($temp)){
$ar=array_keys($temp);
for($i=count($ar)-1;$i>=0;$i--){
echo "<li><a href=\"/website/html/product/show_pro_".$temp["$ar[$i]"].".html\" target=\"_blank\">".str_replace("__"," ",$ar[$i])."</a></li>\n";
}
}else{
echo "Nothing";
}
}elseif($action==0){
if($_GET["name"]!=""&&$_GET["link"]!=""){
if(is_array($temp)){
$ar=array_keys($temp);if(count($temp)==5)setcookie("last_product_view[".$ar[0]."]","",time()-3600);
}
$cookie_names=str_replace(" ","__",js_unescape($_GET["name"]));
setcookie("last_product_view[".$cookie_names."]",$_GET["link"],time()+3600,"/");
}
}
而且重复的不能提前$action=$_GET["action"];
$temp=$_COOKIE["last_product_view"];
if($action==1){
if(is_array($temp)){
$ar=array_keys($temp);
for($i=count($ar)-1;$i>=0;$i--){
echo "<li><a href=\"/website/html/product/show_pro_".$temp["$ar[$i]"].".html\" target=\"_blank\">".str_replace("__"," ",$ar[$i])."</a></li>\n";
}
}else{
echo "Nothing";
}
}elseif($action==0){
if($_GET["name"]!=""&&$_GET["link"]!=""){
if(is_array($temp)){
$ar=array_keys($temp);if(count($temp)==5)setcookie("last_product_view[".$ar[0]."]","",time()-3600);
}
$cookie_names=str_replace(" ","__",js_unescape($_GET["name"]));
setcookie("last_product_view[".$cookie_names."]",$_GET["link"],time()+3600,"/");
}
}
你这个代码看起来全部显示出来是正常的,你是从后向前把数组遍历一便,你说说会不会全部显示呢???把代码改为这个试一下:
$action=$_GET["action"];
$temp=$_COOKIE["last_product_view"];
if($action==1){
if(is_array($temp)){
$ar=array_keys($temp);
for($i=count($ar)-1,$tmp=0;$i>=0 and $tmp<6;$i--,$tmp++){//这里改了一下
echo " <li> <a href=\"/website/html/product/show_pro_".$temp["$ar[$i]"].".html\" target=\"_blank\">".str_replace("__"," ",$ar[$i])." </a> </li>\n";
}
}else{
echo "Nothing";
}
}elseif($action==0){
if($_GET["name"]!=""&&$_GET["link"]!=""){
if(is_array($temp)){
$ar=array_keys($temp);if(count($temp)==5)setcookie("last_product_view[".$ar[0]."]","",time()-3600);
}
$cookie_names=str_replace(" ","__",js_unescape($_GET["name"]));
setcookie("last_product_view[".$cookie_names."]",$_GET["link"],time()+3600,"/");
}
}
搞错了,是最近5条,不是六条:$action=$_GET["action"];
$temp=$_COOKIE["last_product_view"];
if($action==1){
if(is_array($temp)){
$ar=array_keys($temp);
for($i=count($ar)-1,$tmp=0;$i>=0 and $tmp<5;$i--,$tmp++){//这里改了一下,搞个$tmp来判断是否是最后5个就可以了
echo " <li> <a href=\"/website/html/product/show_pro_".$temp["$ar[$i]"].".html\" target=\"_blank\">".str_replace("__"," ",$ar[$i])." </a> </li>\n";
}
}else{
echo "Nothing";
}
}elseif($action==0){
if($_GET["name"]!=""&&$_GET["link"]!=""){
if(is_array($temp)){
$ar=array_keys($temp);if(count($temp)==5)setcookie("last_product_view[".$ar[0]."]","",time()-3600);
}
$cookie_names=str_replace(" ","__",js_unescape($_GET["name"]));
setcookie("last_product_view[".$cookie_names."]",$_GET["link"],time()+3600,"/");
}
}
能不能cookie只取5条记录?