我将如何测试是否使用php设置了cookie,如果未设置,则什么也不做 [英] How would I test if a cookie is set using php and if it's not set do nothing

查看:45
本文介绍了我将如何测试是否使用php设置了cookie,如果未设置,则什么也不做的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试过

 $cookie = $_COOKIE['cookie'];

如果未设置cookie,则会给我一个错误

if the cookie is not set it will give me an error

PHP ERROR
Undefined index: cookie

如何防止它给我一个空变量>

How would I prevent it from giving me an empty variable>

推荐答案

使用 isset 来查看Cookie是否存在。

Use isset to see if the cookie exists.

if(isset($_COOKIE['cookie'])){
    $cookie = $_COOKIE['cookie'];
}
else{
    // Cookie is not set
}

这篇关于我将如何测试是否使用php设置了cookie,如果未设置,则什么也不做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆