I've tried
$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>
You can use array_key_exists for this purpose as follows:
$cookie = array_key_exists('cookie', $_COOKIE) ? $_COOKIE['cookie'] : null;