Re: AW: HTML_DocumentDependencies / Net_URL problem

From: Date: Wed, 25 Jan 2006 17:47:52 +0000
Subject: Re: AW: HTML_DocumentDependencies / Net_URL problem
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-41087@lists.php.net to get a copy of this message
Christoph Lütjen - webEdition Software GmbH a écrit :
Exactly that's my problem. "http://host2/example/text.html" contains e.g. <a href="./anotherfile.html">text</a> This Link refers to http://host2/example/anotherfile.html and not to something relative to the script that's currently running. It's relative to the opened file (using HTTP_Request($uri) and not to the PHP Script that has opened it. About relative path, i think we could have (security) problem , if we could navigate into remote (host2) directories.
So solve a relative "./anotherfile.html" which should give http://host2/example/anotherfile.html will be impossible. (hope i'm not wrong) But you can set and replace values you expect to have. //host1/parser.php <?php require_once 'Net/URL.php'; require_once 'HTTP/Request.php'; $uri = 'http://host2/example/text.html'; $href_doc1 = new Net_URL($uri); var_dump($href_doc1); $host1_path = dirname($href_doc1->path); var_dump($host1_path); $req = &new HTTP_Request($uri); $req->setMethod(HTTP_REQUEST_METHOD_GET); $req->sendRequest(); $response1 = $req->getResponseBody(); $dom = new DOMDocument(); @$dom->loadHTML($response1); $tags = $dom->getElementsByTagName('a'); foreach ($tags as $tag) { $dest = $tag->getAttribute('href'); $href_doc = new Net_URL($dest); var_dump($href_doc); $host2_dest = $href_doc1->protocol .'://'. $href_doc1->host . $host1_path; if (substr($href_doc->url, 0, 1) !== '/') {
       $host2_dest .= '/';
} $host2_dest .= $href_doc->url; $tag = array(
       'host' => $href_doc1->host,
       'url'  => $host2_dest
); var_dump($tag); // [1] } ?> Sorry for the draft and lack of explains, but i'm pretty sure you can understand what i means. with a //host2/example/text.html doc that have 2 links <a href="/link.html">text 1</a> <a href="./anotherfile.html">text 2</a> In [1] you will have such output : host => host2 url => http://host2/example/link.html then host => host2 url => http://host2/example/./anotherfile.html
Hoping I'm not simply too stupid... ;-) There are no stupid question, but answers may be stupid (hope it will be not my case ;-) )
Laurent

« previous php.pear.dev (#41087) next »