Home » Web Services » Services_Pingback » Bug #9506
Use HTTP_Request to know if an URI is valid
Details
| Submitted | 2006-11-30 03:42 UTC |
|---|---|
| From | pfischer at php dot net |
| Assigned | firman |
| Status | Closed |
| Package | Services_Pingback |
| PHP Version | 5.1.6 |
| OS | Linux |
| Roadmaps | (Not assigned) |
Comments
[2006-11-30 03:42 UTC] pfischer at php dot net
Description:
------------
Hi,
First of all, thanks for your package, we are using it @ Jaws Project for supporting pingback.
The reason of this 'bug report' is to let you know a little bug I found. Currently you validate an URI by calling fopen which is *OK*, however fopen has some limitations with some URLs (like those that use query strings or path info: index.php/foo/bar).
And example of this happens when the discover/source/target URIs are very similar to http://www.example.com/index.php/foo/bar (using PATH_INFO). With the current release it will return false which is not correct cause maybe the sourceURI/targetURI uses PATH_INFO (like WP/Jaws/others).
So, the most *reasonable* way to fix this is to do the same that RPC (and some parts of Pingback) does: use fsockopen/HTTP_Request which does:
1. Open a socket (fsockopen)
2. Get headers
3. If responseCode == 200 then the URI is valid.
I'm sending a patch for this (already tested with some WP/Jaws posts).
Thanks for the package!
Test script:
---------------
function isURIExist($uri)
{
$params = array(
'timeout' => 3,
'allowRedirects' => true,
'maxRedirects' => 2,
);
$req = new HTTP_Request($uri, $params);
$req->sendRequest();
if (PEAR::isError($req)) {
return false;
}
if ($req->getResponseCode() == 200) {
return true;
}
return false;
}