How can a cookie be set using $_POST['language'] in PHP?
To set a cookie using $_POST['language'] in PHP, you need to first check if the 'language' key is set in the $_POST superglobal array. If it is set, you can then set a cookie with the language value obtained from $_POST['language']. This can be done by using the setcookie() function in PHP.
if(isset($_POST['language'])){
$language = $_POST['language'];
setcookie('language', $language, time() + 3600); // Cookie expires in 1 hour
}
Related questions
-
HTTP headers header() Location
-
PHP templates HTML content PHP logic
-
Loops Conditional statements Performance