alexku Posted January 16, 2007 Share Posted January 16, 2007 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 More sharing options...
michaellunsford Posted January 17, 2007 Share Posted January 17, 2007 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] Link to comment https://forums.phpfreaks.com/topic/34473-urluri-verifier-w-delicious-support/#findComment-162549 Share on other sites More sharing options...
alexku Posted January 18, 2007 Author Share Posted January 18, 2007 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 Link to comment https://forums.phpfreaks.com/topic/34473-urluri-verifier-w-delicious-support/#findComment-163952 Share on other sites More sharing options...
michaellunsford Posted January 18, 2007 Share Posted January 18, 2007 You just forgot the preceding slash. That way you'll actually be requesting something. ;)[code=php:0]$page = "/"; //the part after the URL. [/code]Answer; the page variable would be something like "/index.html" Link to comment https://forums.phpfreaks.com/topic/34473-urluri-verifier-w-delicious-support/#findComment-163960 Share on other sites More sharing options...
ShogunWarrior Posted January 18, 2007 Share Posted January 18, 2007 CURLOPT_CUSTOMREQUEST only takes the request method(GET/PUT/DELETE) not the whole request header. Link to comment https://forums.phpfreaks.com/topic/34473-urluri-verifier-w-delicious-support/#findComment-163965 Share on other sites More sharing options...
alexku Posted January 18, 2007 Author Share Posted January 18, 2007 Thanks for your help.Works great now.-Alex Link to comment https://forums.phpfreaks.com/topic/34473-urluri-verifier-w-delicious-support/#findComment-164004 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.