doucheyi1347 2012-01-23 11:22
浏览 23
已采纳

更多cookie问题,php [关闭]

I'm sorry to keep asking stupid questions, but I have tried to research this and couldn't find it.

This time, I want to be able to check a _POST against an array, before deciding it's ok to set the cookie. Here's my snippet.

<?php
header( 'Location: http://www.site.com/ler.php' ) ;
?>
<?php
setcookie("choice1","true",time()+20);
?>


<?php

$match_id = strtoupper($_POST["arr"]);


//var_dump(implode($_POST));


$bArray = array(
"A"=>"1",
"B"=>"2",
"C"=>"3",
"D"=>"4",
"ETC"=>"5");

I need the array and variable to be set before the cookie, because I want to use array_key_exists conditional. I tried switching the order but that didn't do anything. I know it's not the header because the other code with cookies and headers works fine. Any ideas??

  • 写回答

2条回答 默认 最新

  • douyan3478 2012-01-23 11:31
    关注

    Not sure what you're asking here, but its clear that the code you've presented is probably not going to work as you expect.

    You're outputting body content before the call to setcookie(). So unless you've got output buffering enabled it's going to fail. Setting an expiry time of 20 seconds is a dumb idea too - client side clock is unlikely to be synchronised.

    Also there are several browsers which ignore all subsequent headers after a redirect. Further, depending on the timing of processing, some browsers will drop the connection after a redirect - in the absence of an ignore_user_abort() this may cause premature termination of the code.

    Further, presumably there's a reason for parsing the data / setting a cookie - how can you be sure this has completed before the redirect request from the browser is procesed?

    I want to be able to check a _POST against an array, before deciding it's ok to set the cookie

    Its apparent that the code you've provided does not check anything before setting the cookie - why have you included it in your question?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏