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'] ;
?>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.