Link Check

Discussion in 'PHP' started by casperz, May 30, 2009.

  1. #1
    Hello,

    I have a mp3 search engine and users can add songs links.

    Is there away to make some kind of script to check if the url is working

    Also another script that when i run it it check all the urls and delete the ones that doesn´t work?

    Thank you,
    Casper
     
    casperz, May 30, 2009 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    There's a few options you can use. My recommendation would be to use something like fsocketopen or curl and see if an error is returned when you try to connect to the url. If there is a 404, 500, redirect, or other non 200 header status code, the link is bad, or needs to be manually reviewed. Some servers are pretty good at recognizing automated checking, which would make some errors incorrect even though the link actually works.
     
    jestep, May 30, 2009 IP
  3. casperz

    casperz Guest

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks can you give me some more details?
     
    casperz, May 30, 2009 IP
  4. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #4
    Try something like this:

    
    
    $server = "www.somesite.com"
    $fp=fsockopen($server,80,$errno,$errstr,30);
    
    $page = "somefile.mp3";
    
    $out="GET /$page HTTP/1.1\r\n"; 
    $out.="Host: $server\r\n"; 
    $out.="Connection: Close\r\n\r\n";
    fwrite($fp,$out);
    
    $content = fgets($fp);
    
    
    PHP:
    If $content is anything but "HTTP/1.1 200 Ok" or another 200 code, the link should be manually checked. This may take some testing to get working properly. I haven't tested this.
     
    jestep, May 30, 2009 IP
  5. casperz

    casperz Guest

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thank you :) i will try
     
    casperz, May 30, 2009 IP
  6. johnkramlich

    johnkramlich Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Check out phpclasses.org. Search for HTTP Status. There should be a class that takes a url as a parameter and gives you an array that lists all of the headers that the server sends back. You can then check the status code and manually review or delete anything not in the 200s
     
    johnkramlich, May 31, 2009 IP