Current location: Hot Scripts Forums » Programming Languages » PHP » PHP/MySQL PAGE LAST UPDATED script problem


PHP/MySQL PAGE LAST UPDATED script problem

Reply
  #1 (permalink)  
Old 01-05-04, 02:08 AM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
PHP/MySQL PAGE LAST UPDATED script problem

Hi,

This script is for a PAGE LAST UPDATED script that checks a list of websites to find out when each was last updated. Can someone tell me why the following code doesn't work?


// -------------------------- Code for Creating MySQL Database Table ---------------------
Code:
CREATE TABLE urls (
 
id tinyint(3) unsigned NOT NULL auto_increment,
 
url text NOT NULL,
 
dsc varchar(255) NOT NULL default '',
 
date datetime default NULL,
 
email varchar(255) NOT NULL default '',
 
PRIMARY KEY (id)
 
);
 

// -------------------------- Code for Checking Last Updated Date -------------------------


PHP Code:

[b][font=Tahoma][size=2]<?php
 
// DB connection parameters
 
$db_host="localhost";
 
$db_user="user";
 
$db_pass="pass";
 
$db_name="dbname";
 
// open database connection
 
$connection mysql_connect($db_host$db_user$db_pass) or die ("Unable to connect!"); mysql_select_db($db_name);
 
// generate and execute query
 
$query1 "SELECT id, url, date, dsc, email FROM urls"
 
$result1 mysql_query($query1$connection) or die ("Error in query: $query1 . " .mysql_error());
 
// if rows exist
 
if (mysql_num_rows($result1) > 0)
 
{
 
// iterate through resultset
 
while(list($id$url$date$desc$email) = mysql_fetch_row($result1))
 
{
 
$response "";
 
 
 
// parse URL into component parts 
 
$arr parse_url($url);
 
// open a client connection
 
$fp fsockopen ($arr['host'], 80);
 
 
 
// send HEAD request and read response
 
$request "HEAD /" $arr['path'] . "HTTP/1.0\r\n\r\n";
 
fputs ($fp$request);
 
while (!
feof($fp)) 
 
{
 
$response .= fgets ($fp500);
 
}
 
fclose ($fp);
 
// split response into lines
 
$lines explode("\r\n"$response);
 
 
 
// scan lines for "Last-Modified" header
 
foreach($lines as $l)
 
{
 
if (
ereg("^Last-Modified:"$l)) 
 
{
 
// split into variable-value component
 
$arr2 explode(": "$l);
 
$newDate gmdate("Y-m-d H:i:s"strtotime($arr2[1]));
 
 
 
// if date has changed from last-recorded date
 
if ($date != $newDate)
 
{
 
// send mail to owner 
 
mail($email"$desc has
 
changed!"
"This is an automated message to inform you that the URL
 
\r\n\r\n 
$url \r\n\r\nhas changed since it was last checked. Please
 
visit the URL to view the changes."
"From: DigiOz Multimedia
 
[email="
webmaster@digioz.com"]webmaster@digioz.com[/email]") or die ("Could not send mail!");
 
 
// update table with new date
$query2 "UPDATE urls SET date = '" $newDate "' WHERE id = '" $id "'";
 
$result2 mysql_query($query2$connection) or die ("Error in query: $query2 . " mysql_error());
 

 

 
}
 

 
}
 
// close database connection
 
mysql_close($connection);
 
?>
 
[/size][/font][/b][font=Tahoma][size=2][/size][/font]
__________________

Last edited by digioz; 01-05-04 at 02:11 AM.
Reply With Quote
  #2 (permalink)  
Old 01-05-04, 06:22 AM
YourPHPPro's Avatar
YourPHPPro YourPHPPro is offline
Community VIP
 
Join Date: Aug 2003
Posts: 430
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by digioz
Can someone tell me why the following code doesn't work?
System specs, php version, and error message would greatly help someone assist you...
Reply With Quote
  #3 (permalink)  
Old 01-05-04, 09:38 AM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
There were no error messages, it just won't update the date in the database. I tried it on both a Windows 2000 runnning Apache/2.0.46 (Win32) PHP/4.3.2 and also a Redhat Linux Server.




Quote:
Originally Posted by YourPHPPro
System specs, php version, and error message would greatly help someone assist you...
__________________
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Classified Ads skipper23 Perl 3 11-22-05 02:22 AM
Is there any integrity of script rankings? webmaster@atmanager.com Hot Scripts Forum Questions, Suggestions and Feedback 17 08-06-04 12:12 AM
Classified Ads skipper23 Perl 2 12-30-03 03:43 AM
Member page script john102749 Script Requests 0 12-05-03 04:47 PM
"10 most requested pages" script to include in page avx Script Requests 5 08-06-03 03:26 AM


All times are GMT -5. The time now is 08:20 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.