Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In PHP, make a web page that uses a cookie to keep track of how many times a use

ID: 3604938 • Letter: I

Question

In PHP, make a web page that uses a cookie to keep track of how many times a user has viewed the page. The first time a particular user looks at the page, it should print something like “Number of views: 1.” The second time the user looks at the page, it should print “Number of views: 2,” and so on. Now have your code prints out a special message on the 5th, 10th, and 15th times the user looks at the page. On the 20th time the user looks at the page, it deletes the cookie and the page count starts over.

Explanation / Answer

<?php

session_start(); //start the PHP_session function

if(isset($_SESSION['page_count']))
{
if($_SESSION['page_count']<20)
{
$_SESSION['page_count'] += 1;
}
}
else
{
$_SESSION['page_count'] = 1;
}
echo 'Number of views: ' . $_SESSION['page_count'] ;

?>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote