Computer Science, asked by singhjyotisingh7254, 1 year ago

Write a php program to store current date-time in a cookie and display the ‘last visited on' date-time on the web page upon reopening of the same page.


b.write a php program to store page views count in session, to increment the count on each refresh, and to show the count on web page.

Answers

Answered by bhatiamona
3

A.

<Html>

<body bgcolor=“87ceeb”>

<center><h2>Last visited time on the web

Page</h2></center>

<br>

<?php

//date_default_timezone_set(‘Asia/Calcutta’);-you can choose any timezone

//Calculate 60 days in the future

//second *minute*hours*days+ current time

$in TwoMonths=60*60*24*60+time();

Setcookie(‘lastvisit’, date(“G:i-m/d/y”),

$in TwoMonths);

If(isset($_COOKIE[lastVisit’]))

{

$visit=$_COOKIE[‘lastvisit’];

Echo “your last visit was- “,$visit;

}

else

echo “you,ve got some stale cookies”;

?>

</body>

</html>


B.

A session in specific to the user and for each user a new session is created to track all the request from that user. Every user has a separate session and separate session variable which is associated with that session.  

<?php

Session_start();

If (isset ($_SESSION[‘count’]))

{

Echo “your session count : “.$_SESSION[ ‘COUNT’ ]. “<br  />;

}

else

{

$_SESSION[ ‘count ‘] = 1;

Echo “Session does not exist”;

}








Similar questions