Forum Moderators: coopster
I want to write PHP script which will use fsockopen to connect to a webpage. and it will check whether the content is changed. If the content is changed it will send a notification to an email address.
Now the first part.
opening a socket connection to a webpage and then returning the file pointer.
and last sending the notification email using the mail function is much clear to me.
But How can I can I check the content. Where the page is changed. And What is the change. There I am stuck. I am weak in the regular expression part.
Wish some guru here can help me out on this case.
Thanks in advance.
Suman Haldar
try this page, the user comments have exactly what you are looking for
[php.net...]
<?phpfunction filemtime_remote($uri)
{
$uri = parse_url($uri);
$handle = @fsockopen($uri['host'],80);
if(!$handle)
return 0;
fputs($handle,"GET $uri[path] HTTP/1.1\r\nHost: $uri[host]\r\n\r\n");
$result = 0;
while(!feof($handle))
{
$line = fgets($handle,1024);
if(!trim($line))
break;
$col = strpos($line,':');
if($col!== false)
{
$header = trim(substr($line,0,$col));
$value = trim(substr($line,$col+1));
if(strtolower($header) == 'last-modified')
{
$result = strtotime($value);
break;
}
}
}
fclose($handle);
return $result;
}
echo filemtime_remote('http://example.example.com/index.php');
?>
They said the function will return the last modification date of a JPG file. But in my case it is always returning a 0. Do you have any idea why?