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
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.
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.
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