Please answer and show your work. Thumbs up guaranteed. Please add comments so I
ID: 3705266 • Letter: P
Question
Please answer and show your work. Thumbs up guaranteed.
Please add comments so I can understand how you wrote the code. Please keep the code fairly simple as well for these are introductory questions with the basics of PHP taught only.
Thank you!
The following set of short questions will focus on getting you familiar with how to write PHP functions as well as how to make use of the pre-existing PHP functions. All your PHP functions must be declared in the document body section and each functions name must be as specified below. To demonstrate the functionality of each method, you must make function calls in the document body. Include a heading (hl.. h6) that indicates which function is being tested before each function demonstration. The use of Global Variables is forbidden! Test all your functions with some relevant input parameter values.Explanation / Answer
Please find the below code with all the explanation in the commented section
<html>
<head>
<title>Tracking Visitor Access</title>
</head>
<body>
<?php
if (!isset($_COOKIE['count']))
{
?>
Welcome! This is the first time you have viewed this page.
<?php
$cookie = 1; //initialize the initial counter value to 1
setcookie("count", $cookie); //set the cookie for the first timevisit
}
else
{
$cookie = ++$_COOKIE['count']; //If the person had already visited we preincrement the cookie counter
setcookie("count", $cookie); //then we set the updated counter value
?>
You have viewed this page <?= $_COOKIE['count'] ?> times.
<?php }// end else ?>
</body>
</html>