<form method=post action=cookies_redirect.php><font face='Verdana' size='2'>
Enter Your Name<input type=text name=name > <br>
Enter Your City Name<input type=text name=city><br>
Enter Your State Name<input type=text name=state><br>
Enter Your Zip Code<input type=text name=zip>
<input type=submit value=Next>
</font>
</form>
DEMO: Setting data array Cookies $name=$_POST['name'];
$city=$_POST['city'];
$state=$_POST['state'];
$zip=$_POST['zip'];
if(isset($name) and strlen($name) > 1){
setcookie ("Plus2netCookie[name]", $name);
setcookie ("Plus2netCookie[city]", $city);
setcookie ("Plus2netCookie[state]", $state);
setcookie ("Plus2netCookie[zip]", $zip);
header ("Location: cookies_t2.php");
}else{
echo " Error in redirection ";
}
To read the array cookie we will use print_r command of PHP array
if(isset($_COOKIE['Plus2netCookie'])){
print_r($_COOKIE[Plus2netCookie]);
echo "<br><br><font face='Verdana' size='2'>Your name should appear after the welcome message above if cookie is available. </font>";
}else{
echo " No Cookie is set ";
}
We can delete the cookies like this.
setcookie ("Plus2netCookie", "", time() - 3600);
setcookie ("Plus2netCookie[zip]", "", time() - 3600);
setcookie ("Plus2netCookie[city]", "", time() - 3600);
setcookie ("Plus2netCookie[state]", "", time() - 3600);
setcookie ("Plus2netCookie[name]", "", time() - 3600);
DEMO: Setting data array Cookies Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.