How to set random cookie value using rand function in PHP

前端 未结 3 825
情深已故
情深已故 2021-01-24 19:16

How to set random cookie value using rand function in PHP

I don\'t want to change the value while page refreshed when it once assigned.. until cookie destroy

My

3条回答
  •  天涯浪人
    2021-01-24 19:34

    if(!isset($_COOKIE['lg'])) {
        setcookie('lg', rand(1,10000), time() + (86400 * 30), "/"); // 86400 = 1 day
    }
    echo $_COOKIE['lg'];
    

    You can check if it is not set then set it.

提交回复
热议问题