Jump to content

url/uri verifier (w/ del.icio.us support)


alexku

Recommended Posts

I am trying to develop an online link verifier that will connect into del.icio.us and help identify bookmarks that point to no existent pages. I am wondering what the best way to verify a links validity is? I don't need to load the entire page. I just need to see the status code (404 or 200 are the most important). Does anyone have an idea on how best to do this?
Thank you.

-Alex Unger
Link to comment
https://forums.phpfreaks.com/topic/34473-urluri-verifier-w-delicious-support/
Share on other sites

you can do a custom HEAD request using CURL.

[code]<?php
$ch = curl_init();
$page = $filename; //the part after the URL. It will need a preceding slash.
$url = "http://example.com";
$header  = "HEAD ".$page." HTTP/1.0 \r\n";
$header .= "Connection: close \r\n";
$header .= "Accept-Encoding: gzip\r\n";
$header .= "Accept: */*\r\n";
$header .= "Accept-Language: en\r\n";
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
$retval=curl_exec($ch);
curl_close($ch);
if(strpos($retval,"200 OK")) $link_is_good=true;
?>[/code]
michaellunsford,

I tried the code, but can't seem to get it to work. Here is an example of the variables being passed.
[code]<?php
        $ch = curl_init();
        $page = ""; //the part after the URL. It will need a preceding slash.
        $url = "http://www.google.com";
        $header  = "HEAD ".$page." HTTP/1.0 \r\n";
        $header .= "Connection: close \r\n";
        $header .= "Accept-Encoding: gzip\r\n";
        $header .= "Accept: */*\r\n";
        $header .= "Accept-Language: en\r\n";
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, true);
        $retval=curl_exec($ch);
        curl_close($ch);
        if(strpos($retval,"200 OK")) $link_is_good=true;
?>[/code]
Is there something that I am doing wrong? What should go in the $page variable?
Thank you.

-Alex

Archived

This topic is now archived and is closed to further replies.

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