1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

code to check if HTML source has changed.

Discussion in 'PHP' started by m93rd, Nov 4, 2007.

  1. #1
    What is the simplest way to go about checking whether a certain URL's HTML source code has changed since a cetain date. Another wards as soon as it changes I need to a function or variable would to be set to false.


    Or do I have to go about it by:
    keeping a variable set equal to the HTML source code (as the base /starting point) then run an infinite loop that keeps checking if the current source equals the variable(base line).


    How I tried just to see if the starting source equal the source I get from the function and it doesnt seem to be working -- this is what I have:

    <?php

    $start_source='<html>

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>New Website Coming Soon</title>
    </head>

    <body>
    <p align="center">&nbsp;</p>
    <p align="center"><font face="Courier New" color="#B1B1B1">New Website Coming
    Soon ...</font></p>
    <p align="center">
    <img border="0" src="Kelly_Osbourne_Project_Catwalk_Small.jpg" width="295" height="354"></p>
    </body>

    </html>';

    //highlight_file("http://rivalnyc.com/");

    $end_new= highlight_file("http://www.kellyosbourne.com/",TRUE);



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

    ?>

    could use some help.
     
    m93rd, Nov 4, 2007 IP
  2. Galen

    Galen Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    if you're using php5 you could use file_get_contents(URL) and compare it to the old source.
     
    Galen, Nov 4, 2007 IP
  3. m93rd

    m93rd Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    ok chnaged it to use this function-- but still same problem, I am not geting any output

    start source is just a copy and paste of pages source code.
    end source is using the function to get current source code of page
    since nothing has changed if condition should be true.

    Heres the code

    <?php

    $start_source='<html>

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>New Website Coming Soon</title>
    </head>

    <body>
    <p align="center">&nbsp;</p>
    <p align="center"><font face="Courier New" color="#B1B1B1">New Website Coming
    Soon ...</font></p>
    <p align="center">
    <img border="0" src="Kelly_Osbourne_Project_Catwalk_Small.jpg" width="295" height="354"></p>
    </body>

    </html>

    ';

    //highlight_file("http://rivalnyc.com/");

    $end_new= file_get_contents("http://www.kellyosbourne.com/");



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

    ?>



    thanks in advance for any help
     
    m93rd, Nov 4, 2007 IP
  4. bobb1589

    bobb1589 Peon

    Messages:
    289
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    they arent going to be the same... you need to put in line breaks... matching the page... by the way... linebreaks are \n
     
    bobb1589, Nov 4, 2007 IP
  5. m93rd

    m93rd Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    sorry a bit new could you explain abit more
     
    m93rd, Nov 4, 2007 IP
  6. phper

    phper Active Member

    Messages:
    247
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #6
    phper, Nov 4, 2007 IP
  7. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #7
    ^^ This header is optional though, and usually not sent when opening pages with a .php extension. (Since PHP is supposed to be a dynamic language, where the actual FILE remains the same while the content can change).

    I'd store an md5 hash of the source, and compare just these instead of the whole source. Takes way less space too.
     
    nico_swd, Nov 5, 2007 IP
  8. m93rd

    m93rd Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    when I tried the get_headers function I got an error saying call to an undefined function.
    heres what I tried.

    $url = "http://www.kellyosbourne.com/";

    print_r(get_headers($url));
     
    m93rd, Nov 5, 2007 IP
  9. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #9
    nico_swd, Nov 5, 2007 IP
  10. m93rd

    m93rd Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    ok did the work around(function posted) in the user comments in the documentation. It worked fine for that other URL i posted.

    But then tried on a similar landing .HTML page/ URL it gave me
    "
    Array ( [0] => HTTP/1.1 302 Moved Temporarily [1] => Content-Length: 0 [2] => Location: /?e7547fa0 )
    "
     
    m93rd, Nov 5, 2007 IP
  11. m93rd

    m93rd Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    any other ways to get the headers.

    When I view the page info it shows the headers, so I dont why this is happening
     
    m93rd, Nov 5, 2007 IP
  12. bobb1589

    bobb1589 Peon

    Messages:
    289
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #12
    ok.... let me quote you and try and explain

    i think this could be a solution... i could be wrong... what i was trying to say is you need to add \n to wherever there would be a new line because php will get rid of the whitespace i believe... ... let me test my theory real qiuck and i will update you
     
    bobb1589, Nov 5, 2007 IP
  13. m93rd

    m93rd Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    I dont think solution will work any longer as-

    I wanted to know as soon as a certain picture on a particular page has changed.

    However now that picture is in flash.
     
    m93rd, Nov 5, 2007 IP
  14. bobb1589

    bobb1589 Peon

    Messages:
    289
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #14
    oh... darn
     
    bobb1589, Nov 5, 2007 IP
  15. m93rd

    m93rd Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Actually any help on getting this original method(psted in my first response) to work appreciated.
     
    m93rd, Nov 5, 2007 IP
  16. m93rd

    m93rd Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    anyone have any thiought how 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??
     
    m93rd, Nov 10, 2007 IP
  17. m93rd

    m93rd Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #17
    anyone help appreciated??
     
    m93rd, Nov 11, 2007 IP