27 Program to modify cookies in PHP

To modify cookie, just set(again) the cookie using the setcookie() function.

Program:


<?php

    $cookie_name = "Name";

    $cookie_value = "Coding";



    setcookie($cookie_name,$cookie_value,time()+(86400*30),"/");

    // 86400 = 1Day



    if(!isset($_COOKIE[$cookie_name]))

    {

        echo "Cookie Named ".$cookie_name." is not set";

    }

    else

    {

        echo "Cookie Name: ".$cookie_name." is set. <br/>";

        echo "Cookie Value: ".$cookie_value;

    }

?>


Output:

Program to modify cookies in PHP

Previous
Next Post »