unset cookie php code example

Example 1: remove last letter php

<?php
echo substr('abcdef',0, -1);     // abcde
?>

Example 2: remove cookies php

unset($_COOKIE['hello']);

Example 3: php cookies

//Cookies
//Cookies are stored on the client side. cookies are not as secure as sessions
//and it is recommended that you use sessions as much as possible.

<?php
if(isset($_POST['submit'])){
    $username = htmlentities($_POST['username']);

    setcookie('nameofcookie', $username, time()+3600); 
    //1hour time limit

    header('Location: page2.php');
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>PHP Cookies</title>
</head>
<body>
        <form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
                <input type="text" name="username" placeholder="Enter Username">
                <br>
                <input type="submit" name="submit" value="Submit">
            </form>
        </div>
</body>
</html>

Example 4: cookies php syntax

setcookie("cookie_name", "type_on_cookie", expiry_time(), "/");

Tags:

Php Example