How can PHP be used to check if a link is still valid based on a timestamp in a database?

To check if a link is still valid based on a timestamp in a database, you can retrieve the timestamp from the database and compare it with the current time. If the timestamp is within a certain timeframe (e.g., 24 hours), then the link is considered valid. You can use PHP's date functions to handle timestamps and calculate the time difference.

// Assuming $timestamp is the timestamp retrieved from the database
$validityPeriod = 24 * 60 * 60; // 24 hours in seconds
$currentTimestamp = time();

if (($currentTimestamp - $timestamp) <= $validityPeriod) {
    echo "Link is still valid";
} else {
    echo "Link has expired";
}