Hey Everyone, I want to set a cookie that expires in an hour that users URL vars to set it for example www.example.com/?a=whatever how can I get 'a' var from the URL and set it as a cookie and then on another page print the cookie? Thanks!
You will need to get the value of the variable with $_GET['a']. After doing this you can simply use the php function setcookie() to set the cookie along with a name, value, and expiration. Here is the link to to documentation for that function: http://php.net/manual/en/function.setcookie.php.
As described above it's pretty simple : To set the cookie: if($_GET['a']){ //then the URL var exists so set the cookie //The URL param values could contain malicious values so remove html entities before storing/printing the value $var = htmlentities($_GET['a']); //set the cookie with 1 hr expiration setcookie("cookee",$var,time()+3600); } //Print cookie value echo $_COOKIE['cookee']; PHP: Is htmlentities good enough on its own for sanitizing the GET values? I'm not sure hopefully somebody could provide more info on this.