Finding out which file is retrieved over HTTP

From: Date: Sun, 23 Mar 2003 20:21:39 +0000
Subject: Finding out which file is retrieved over HTTP
Groups: php.general 
Request: Send a blank email to php-general+get-140773@lists.php.net to get a copy of this message
The following short script retrieves a file over HTTP: $url = 'http://www.example.com/'; implode('',file($url)); // or file_get_contents() Now I'd like to find out which file was really retrieved, for instance http://www.example.com/index.html. Is this possible and how? Background: I need to write a small link-checker (Intranet), which reads in all links within a file and then looks if they're broken and collects some information. Unfortunately I didn't find a simple, free link-checker that's why I write my own. It would be good to find out the "complete" url, because I want to collect the file-endings (.php,.html, ...). Another thing is that my script is recursive, so I need a function absolute_link() which takes a (possibly relative) path and an url to find out which page to go next. Example: $url = http://www.example.com/foo/bar/ Somewhere in the source code: ... <a href="../articles/page.html" /> ... My script reads in $path='../articles/page.html'. The function absolute_link($url, $path) should return 'http://www.example.com/foo/articles/page.html'. However $url could be http://www.example.com/foo/bar (bar can be file or dir here imho) or http://www.example.com/foo/bar/index.php and in any case absolute_link() should return the same. Of course this function is easier to implement if I always have something like http://www.example.com/foo/bar/index.php. Maybe there's already a useful function besides parse-url() I can use here. Jens

« previous php.general (#140773) next »