Hello, How can I do an If-Modified-Since request with PHP to see if a webpage has been recently changed or not?
<?php // file to check (with path) $filename = "filename.php"; // what date you want to check against (ie July 1, 2007): $date_check = mktime(0, 0, 0, 7, 1, 2007); $mod_date = date("Y-m-d h:i",filemtime($filename)); $date_since = date("Y-m-d h:i",$date_check); if ($mod_date > $date_since) { //whatever you wanna do here, e.g. echo $filename . " has been modified since: " . $date_since; } else { echo $filename . " has not been modified since: " . $date_since; } ?> PHP:
Just to clarify, do you want to get the date of a local or remote file? If you want to get the remote date, have a look at this thread. http://forums.digitalpoint.com/showthread.php?t=326547 And james_r, there is no need to convert the timestamps into a date format. You can directly compare the timestamps.
good catch nico, i had done the conversion to easily display in the echo statement.. but it really wasn't necessary, could have done it just once in the echo.