Accessing $_COOKIE immediately after setcookie()

前端 未结 9 1051
轻奢々
轻奢々 2020-11-22 05:43

I\'m trying to access a cookie\'s value (using $_COOKIE) immediately after calling the setcookie() function in PHP. When I do so, $_COOKIE[\

9条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 06:18

    Using ob_start() and ob_flush() you can send the cookie to client and retrieve it in the same run time. Try this:

    ob_start();
    setcookie('uname', $uname, time() + 60 * 30);
    ob_flush();
    echo "Cookie value: " . $_COOKIE['uname'];
    

提交回复
热议问题