I've been working on a login class recently and one of the methods just checks if the user has cookies enabled or not.
Basically I've looked around online at how to check if cookies are enabled or not in PHP and if they are to set them up to be secure and made a function for it. I could do with someone looking over what I've done to see if it could be improved in anyway and if I've missed anything out.
Thank you in advance,
//Stops the code being run multiple times as cookies should only need to be checked for once
if(ini_get('session.use_only_cookies') !== true || ini_get('session.hash_function') !== $this->hash || !isset($_COOKIE['nnspl_cookie']))
//Starts test to see if cookies are enabled on the client
if(!isset($_GET['tc']) && !isset($_COOKIE['nnspl_cookie']))
setcookie("nnspl_cookie", "test", 0);
//If cookies are not enabled the user is forwarded to another page
if(isset($_GET['tc']) && !isset($_COOKIE['nnspl_cookie']))
//If they are enabled they are set to be secure and true is returned
//Filters to make sure variables are sanitised
$domain = filter_var($_SERVER['HTTP_HOST'], FILTER_VALIDATE_URL);
//Sets session cookies to be stored securely
session_set_cookie_params(0, '/', $domain, isset($_SERVER["HTTPS"]), true);