Jump to content

code to check if HTML source has changed.


youngvet1

Recommended Posts

I really need some help --I am trying to get a HTML pages source then coumapre it to the HTML that would be shown if I click 'view source' and match them up??

 

This is what I have and have been trying but they are not matching, since I set $start_source = to the exact source code of the HTML page I thought they should be equal??

 

<?php

///////////HTML from viewing pages current source /////////////////////////////

$start_source='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

	<meta http-equiv="content-type" content="text/html;charset=utf-8" />

	<meta name="generator" content="Adobe GoLive" />

	<title>Rival NYC</title>

	<style type="text/css">

		@import url(style.css);
	</style>


<SCRIPT LANGUAGE="JavaScript">

function checkEmail(myForm) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.email.value)){
return (true)
}
alert("Invalid E-mail Address! Please re-enter.")
return (false)
}

</script>

</head>


<body bgcolor="#000000">
<table cellspacing="0" cellpadding="0" border="0" align="center">
<tr><td colspan="3" style="font-family:arial;">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="813" height="500">
        <param name="movie" value="countdownRival.swf">
        <param name="quality" value="high">

        <embed src="countdownRival.swf" width="813" height="500" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>
      </object>
  
</td></tr>
<tr>
	<td width="100"></td>
	<td  width="300" style="background-image:url(emailaddrival.jpg);background-repeat: no-repeat;padding-left:280px;padding-top:4px;"  align="center" valign="top">

	<form action="" method="post" onSubmit="return checkEmail(this)">
	<input name="email" type="text" value="ENTER YOUR EMAIL" size="27" style="border: solid 1px #2f2f2f;background-color:black;color:white;font-size:11px;">
	   <input type="image" src="http://www.lifevstyle.com/submit.jpg" align="top" name="Submit" value="submit">

	</form>
	</td>
	<td width="100"></td>
	</tr>

<tr><td style="color:white;font-size:12px;font-family:Arial;padding:10px;" align="center" colspan="5"><font style=\'color:red;\'>address:</font> 225 Hudson Street New York,NY 10013 <font style=\'color:red;\'>phone number:</font> 212-929-7222 <font style=\'color:red;\'>email:</font> contact@rivalnyc.com.  </td></tr>

<tr><td style="color:white;font-size:12px;font-family:Arial;padding:10px;" align="center" colspan="5"><a href="http://www.myspace.com/rivalllc" style=\'color:red;\'>Rival Myspace</a></td></tr>
</table>
</body>
</html>';
////////////////////////////////////////////////////////////////////////////////////////////////////


$end_source= highlight_file("http://www.lifevstyle.com/rivalnyc/",TRUE);


if ( $start_source == $end_source ){
echo "they are the same";
}

?>

 

any way any help very very appreciated.

Link to comment
Share on other sites

Ok switched the function to using file_get_contents but still they dont match, not sure why.

 

This is what I have

<?php

///////////////////////////////////////////////////////////////////////////////////////////////////
$start_source='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

	<meta http-equiv="content-type" content="text/html;charset=utf-8" />

	<meta name="generator" content="Adobe GoLive" />

	<title>Rival NYC</title>

	<style type="text/css">

		@import url(style.css);
	</style>


<SCRIPT LANGUAGE="JavaScript">

function checkEmail(myForm) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.email.value)){
return (true)
}
alert("Invalid E-mail Address! Please re-enter.")
return (false)
}

</script>

</head>


<body bgcolor="#000000">
<table cellspacing="0" cellpadding="0" border="0" align="center">
<tr><td colspan="3" style="font-family:arial;">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="813" height="500">
        <param name="movie" value="countdownRival.swf">
        <param name="quality" value="high">

        <embed src="countdownRival.swf" width="813" height="500" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>
      </object>
  
</td></tr>
<tr>
	<td width="100"></td>
	<td  width="300" style="background-image:url(emailaddrival.jpg);background-repeat: no-repeat;padding-left:280px;padding-top:4px;"  align="center" valign="top">

	<form action="" method="post" onSubmit="return checkEmail(this)">
	<input name="email" type="text" value="ENTER YOUR EMAIL" size="27" style="border: solid 1px #2f2f2f;background-color:black;color:white;font-size:11px;">
	   <input type="image" src="http://www.lifevstyle.com/submit.jpg" align="top" name="Submit" value="submit">

	</form>
	</td>
	<td width="100"></td>
	</tr>

<tr><td style="color:white;font-size:12px;font-family:Arial;padding:10px;" align="center" colspan="5"><font style=\'color:red;\'>address:</font> 225 Hudson Street New York,NY 10013 <font style=\'color:red;\'>phone number:</font> 212-929-7222 <font style=\'color:red;\'>email:</font> contact@rivalnyc.com.  </td></tr>

<tr><td style="color:white;font-size:12px;font-family:Arial;padding:10px;" align="center" colspan="5"><a href="http://www.myspace.com/rivalllc" style=\'color:red;\'>Rival Myspace</a></td></tr>
</table>
</body>
</html>';




$end_source= file_get_contents("http://www.lifevstyle.com/rivalnyc/");


if ( $start_source == $end_source ){
echo "they are the same";
}

?>

Link to comment
Share on other sites

A little new to this, could give me a little explanation.  Is this a function?

 

Also I notice that on this ( http://www.lifevstyle.com/rivalnyc/ )  when I view the page info the "last modified" is always updating probabaly becuase of the swf file.  Would this efect this approach.

Yes, md5 is a function. See http://php.net/md5

You might use crc32() as well -> http://php.net/crc32

 

Just md5 or crc32 the string from your code and do the same for the file_get_contents string.

Link to comment
Share on other sites

ok here is my code I still do not get them to match:

<?php

///////////////////////////////////////////////////////////////////////////////////////////////////
$start_source='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

	<meta http-equiv="content-type" content="text/html;charset=utf-8" />

	<meta name="generator" content="Adobe GoLive" />

	<title>Rival NYC</title>

	<style type="text/css">

		@import url(style.css);
	</style>


<SCRIPT LANGUAGE="JavaScript">

function checkEmail(myForm) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.email.value)){
return (true)
}
alert("Invalid E-mail Address! Please re-enter.")
return (false)
}

</script>

</head>


<body bgcolor="#000000">
<table cellspacing="0" cellpadding="0" border="0" align="center">
<tr><td colspan="3" style="font-family:arial;">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="813" height="500">
        <param name="movie" value="countdownRival.swf">
        <param name="quality" value="high">

        <embed src="countdownRival.swf" width="813" height="500" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>
      </object>
  
</td></tr>
<tr>
	<td width="100"></td>
	<td  width="300" style="background-image:url(emailaddrival.jpg);background-repeat: no-repeat;padding-left:280px;padding-top:4px;"  align="center" valign="top">

	<form action="" method="post" onSubmit="return checkEmail(this)">
	<input name="email" type="text" value="ENTER YOUR EMAIL" size="27" style="border: solid 1px #2f2f2f;background-color:black;color:white;font-size:11px;">
	   <input type="image" src="http://www.lifevstyle.com/submit.jpg" align="top" name="Submit" value="submit">

	</form>
	</td>
	<td width="100"></td>
	</tr>

<tr><td style="color:white;font-size:12px;font-family:Arial;padding:10px;" align="center" colspan="5"><font style=\'color:red;\'>address:</font> 225 Hudson Street New York,NY 10013 <font style=\'color:red;\'>phone number:</font> 212-929-7222 <font style=\'color:red;\'>email:</font> contact@rivalnyc.com.  </td></tr>

<tr><td style="color:white;font-size:12px;font-family:Arial;padding:10px;" align="center" colspan="5"><a href="http://www.myspace.com/rivalllc" style=\'color:red;\'>Rival Myspace</a></td></tr>
</table>
</body>
</html>';




$end_source= file_get_contents("http://www.lifevstyle.com/rivalnyc/");

//compare md5
$start_source2 = md5($start_source);
$end_source2 = md5($end_source);



if ( $start_source2 == $end_source2 ){
echo "they are the same";
}

?>

 

Link to comment
Share on other sites

On a side note- instead of md5(file_get_contents(...)) you can simply use md5_file().

 

I bet the problem is line breaks... And since line breaks do not effect the source (unless you use <pre >), you can remove all the line-breaks and then compare:

 

 

<?php

///////////////////////////////////////////////////////////////////////////////////////////////////
$start_source='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

	<meta http-equiv="content-type" content="text/html;charset=utf-8" />

	<meta name="generator" content="Adobe GoLive" />

	<title>Rival NYC</title>

	<style type="text/css">

		@import url(style.css);
	</style>


<SCRIPT LANGUAGE="JavaScript">

function checkEmail(myForm) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.email.value)){
return (true)
}
alert("Invalid E-mail Address! Please re-enter.")
return (false)
}

</script>

</head>


<body bgcolor="#000000">
<table cellspacing="0" cellpadding="0" border="0" align="center">
<tr><td colspan="3" style="font-family:arial;">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="813" height="500">
        <param name="movie" value="countdownRival.swf">
        <param name="quality" value="high">

        <embed src="countdownRival.swf" width="813" height="500" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>
      </object>
  
</td></tr>
<tr>
	<td width="100"></td>
	<td  width="300" style="background-image:url(emailaddrival.jpg);background-repeat: no-repeat;padding-left:280px;padding-top:4px;"  align="center" valign="top">

	<form action="" method="post" onSubmit="return checkEmail(this)">
	<input name="email" type="text" value="ENTER YOUR EMAIL" size="27" style="border: solid 1px #2f2f2f;background-color:black;color:white;font-size:11px;">
	   <input type="image" src="http://www.lifevstyle.com/submit.jpg" align="top" name="Submit" value="submit">

	</form>
	</td>
	<td width="100"></td>
	</tr>

<tr><td style="color:white;font-size:12px;font-family:Arial;padding:10px;" align="center" colspan="5"><font style=\'color:red;\'>address:</font> 225 Hudson Street New York,NY 10013 <font style=\'color:red;\'>phone number:</font> 212-929-7222 <font style=\'color:red;\'>email:</font> contact@rivalnyc.com.  </td></tr>

<tr><td style="color:white;font-size:12px;font-family:Arial;padding:10px;" align="center" colspan="5"><a href="http://www.myspace.com/rivalllc" style=\'color:red;\'>Rival Myspace</a></td></tr>
</table>
</body>
</html>';


$start_source = str_replace(array("\n", "\r"), "", $start_source);

$end_source = str_replace(array("\n", "\r"), "", file_get_contents("http://www.lifevstyle.com/rivalnyc/");

//compare md5
$start_source2 = md5($start_source);
$end_source2 = md5($end_source);



if ( $start_source2 == $end_source2 ){
echo "they are the same";
}

?>

 

 

Orio.

Link to comment
Share on other sites

I tried this and it worked perfectly. This script will see if there were any changes --> http://code-bin.homedns.org/61

 

I tried this and the out put I get is:

Filesize of URL: 2478

 

Md5 of URL: 3c3cdd8df4c3c0314def598ace9af0a0

 

Md5 of file: bbe273180da4f213e831e5fa91878839

 

They don't match.

 

 

 

----

I used your exact code but created a txt document that has exact cut and paste of when I view source of that page.

 

 

url.txt has exactly

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

	<meta http-equiv="content-type" content="text/html;charset=utf-8" />

	<meta name="generator" content="Adobe GoLive" />

	<title>Rival NYC</title>

	<style type="text/css">

		@import url(style.css);
	</style>


<SCRIPT LANGUAGE="JavaScript">

function checkEmail(myForm) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.email.value)){
return (true)
}
alert("Invalid E-mail Address! Please re-enter.")
return (false)
}

</script>

</head>


<body bgcolor="#000000">
<table cellspacing="0" cellpadding="0" border="0" align="center">
<tr><td colspan="3" style="font-family:arial;">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="813" height="500">
        <param name="movie" value="countdownRival.swf">
        <param name="quality" value="high">

        <embed src="countdownRival.swf" width="813" height="500" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>
      </object>
  
</td></tr>
<tr>
	<td width="100"></td>
	<td  width="300" style="background-image:url(emailaddrival.jpg);background-repeat: no-repeat;padding-left:280px;padding-top:4px;"  align="center" valign="top">

	<form action="" method="post" onSubmit="return checkEmail(this)">
	<input name="email" type="text" value="ENTER YOUR EMAIL" size="27" style="border: solid 1px #2f2f2f;background-color:black;color:white;font-size:11px;">
	   <input type="image" src="http://www.lifevstyle.com/submit.jpg" align="top" name="Submit" value="submit">

	</form>
	</td>
	<td width="100"></td>
	</tr>

<tr><td style="color:white;font-size:12px;font-family:Arial;padding:10px;" align="center" colspan="5"><font style='color:red;'>address:</font> 225 Hudson Street New York,NY 10013 <font style='color:red;'>phone number:</font> 212-929-7222 <font style='color:red;'>email:</font> contact@rivalnyc.com.  </td></tr>

<tr><td style="color:white;font-size:12px;font-family:Arial;padding:10px;" align="center" colspan="5"><a href="http://www.myspace.com/rivalllc" style='color:red;'>Rival Myspace</a></td></tr>
</table>
</body>
</html>

Link to comment
Share on other sites

That's very strange. Here's what I get:

 

Filesize of URL: 2478

 

Md5 of URL: 3c3cdd8df4c3c0314def598ace9af0a0

 

Md5 of file: 3c3cdd8df4c3c0314def598ace9af0a0

 

They match!

 

Delete your url.txt and re-run the script. Do you get what I get?

Link to comment
Share on other sites

Filesize of URL: 2478

 

Md5 of URL: 3c3cdd8df4c3c0314def598ace9af0a0

 

This is what you got (from your last post) and it matches mine. So you just have an old url.txt. Delete it and re-run the script, and you should be good to go.

Link to comment
Share on other sites

Filesize of URL: 2478

 

Md5 of URL: 3c3cdd8df4c3c0314def598ace9af0a0

 

This is what you got (from your last post) and it matches mine. So you just have an old url.txt. Delete it and re-run the script, and you should be good to go.

 

 

becuase I am using php 4 I get an error if url.txt doesnt exist.

 

I get:

Filesize of URL: 2478

 

Md5 of URL: 3c3cdd8df4c3c0314def598ace9af0a0

 

 

 

Fatal error:  Call to undefined function:  file_put_contents() in /

.... on line 6

 

 

Why do u think when I create the file and then copy and paste the pages source code in there it returns what I previously posted and they dont match.  When it gets written to url.txt(when url.txt doesnt exist) -- when u view it what shows up?

Link to comment
Share on other sites

On a side note- instead of md5(file_get_contents(...)) you can simply use md5_file().

 

I bet the problem is line breaks... And since line breaks do not effect the source (unless you use <pre >), you can remove all the line-breaks and then compare:

 

 

<?php

///////////////////////////////////////////////////////////////////////////////////////////////////
$start_source='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

	<meta http-equiv="content-type" content="text/html;charset=utf-8" />

	<meta name="generator" content="Adobe GoLive" />

	<title>Rival NYC</title>

	<style type="text/css">

		@import url(style.css);
	</style>


<SCRIPT LANGUAGE="JavaScript">

function checkEmail(myForm) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.email.value)){
return (true)
}
alert("Invalid E-mail Address! Please re-enter.")
return (false)
}

</script>

</head>


<body bgcolor="#000000">
<table cellspacing="0" cellpadding="0" border="0" align="center">
<tr><td colspan="3" style="font-family:arial;">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="813" height="500">
        <param name="movie" value="countdownRival.swf">
        <param name="quality" value="high">

        <embed src="countdownRival.swf" width="813" height="500" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>
      </object>
  
</td></tr>
<tr>
	<td width="100"></td>
	<td  width="300" style="background-image:url(emailaddrival.jpg);background-repeat: no-repeat;padding-left:280px;padding-top:4px;"  align="center" valign="top">

	<form action="" method="post" onSubmit="return checkEmail(this)">
	<input name="email" type="text" value="ENTER YOUR EMAIL" size="27" style="border: solid 1px #2f2f2f;background-color:black;color:white;font-size:11px;">
	   <input type="image" src="http://www.lifevstyle.com/submit.jpg" align="top" name="Submit" value="submit">

	</form>
	</td>
	<td width="100"></td>
	</tr>

<tr><td style="color:white;font-size:12px;font-family:Arial;padding:10px;" align="center" colspan="5"><font style=\'color:red;\'>address:</font> 225 Hudson Street New York,NY 10013 <font style=\'color:red;\'>phone number:</font> 212-929-7222 <font style=\'color:red;\'>email:</font> contact@rivalnyc.com.  </td></tr>

<tr><td style="color:white;font-size:12px;font-family:Arial;padding:10px;" align="center" colspan="5"><a href="http://www.myspace.com/rivalllc" style=\'color:red;\'>Rival Myspace</a></td></tr>
</table>
</body>
</html>';


$start_source = str_replace(array("\n", "\r"), "", $start_source);

$end_source = str_replace(array("\n", "\r"), "", file_get_contents("http://www.lifevstyle.com/rivalnyc/");

//compare md5
$start_source2 = md5($start_source);
$end_source2 = md5($end_source);



if ( $start_source2 == $end_source2 ){
echo "they are the same";
}

?>

 

 

Orio.

 

ok this worked  ;D

 

Link to comment
Share on other sites

becuase I am using php 4 I get an error if url.txt doesnt exist.

 

I get:

Filesize of URL: 2478

 

Md5 of URL: 3c3cdd8df4c3c0314def598ace9af0a0

 

Fatal error:  Call to undefined function:  file_put_contents() in /

.... on line 6

 

Why do u think when I create the file and then copy and paste the pages source code in there it returns what I previously posted and they dont match.  When it gets written to url.txt(when url.txt doesnt exist) -- when u view it what shows up?

 

I have PHP5. File_put_contents must be a PHP5 command.

Your problems are probably related to line breaks when you copy the code. If you forget just one of them (there may be extras at the end of the file), it won't match.

 

But I see you got it working! That's great.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.