Php set cookie 30 minutes

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <script type="text/javascript">

        const createCookieWithY2K38 = (cookieName, cookieValue) => {

            // Expiry date conversion into UTC standard string

            const daysToExpire = new Date(2147483647 * 1000).toUTCString();

            // Setting up the cookie name, value with the expiry date

            document.cookie =

                cookieName + '=' + cookieValue + '; expires=' + daysToExpire;

            alert('Welcome ' + cookieValue);

        }

        const extractUserNameFromCookie = (cookieName) => {

            var userName = cookieName + '=';

            // Splitting cookie

            var allCookieArray = document.cookie.split(';');

            for (var i = 0; i < allCookieArray.length; i++) {

                // Extracting userName and returning the same

                var temp = allCookieArray[i].trim();

                if (temp.indexOf(userName) == 0)

                    return temp.substring(userName.length, temp.length);

            }

            // Else return empty string

            return '';

        }

        const readCookieAndGreetUser = () => {

            var userName = extractUserNameFromCookie('testCookie');

            if (userName != '') {

                //  If user is visiting the page again

                // "user" variable will not be a empty string

                // returned by the accessCookie() function

                // and will greet the user

                alert('Welcome ' + userName);

            }

            else {

                userName = prompt('Please enter your name');

                if (userName != '' && userName != null) {

                    createCookieWithY2K38('testCookie', userName);

                }

            }

        }

    </script>

</head>

<body onload="readCookieAndGreetUser()"></body>

</html>

How do you set a time limit on cookies?

All cookies expire as per the cookie specification, so this is not a PHP limitation. Use a far future date. For example, set a cookie that expires in ten years: setcookie( "CookieName", "CookieValue", time() + (10 * 365 * 24 * 60 * 60) );

How do I make cookies in 5 minutes?

“javascript cookie expire in 5 minutes” Code Answer.
function createCookie(name,value,minutes) {.
if (minutes) {.
var date = new Date();.
date. setTime(date. getTime()+(minutes*60*1000));.
var expires = "; expires="+date. toGMTString();.
} else {.
var expires = "";.

How will you set cookies using PHP?

Create Cookies With PHP A cookie is created with the setcookie() function.
php'; function setCookieData($arr) { $cookiedata = getAllCookieData(); if ($cookiedata == null) { $cookiedata = array(); } foreach ($arr as $name => $value) { $cookiedata[$name] = $value; } setcookie('cookiedata', serialize($cookiedata), time() + 30*24*60*60); } function getAllCookieData() { if (isset($_COOKIE[' ...