Click to See Complete Forum and Search --> : Get default file name of remote site
sitehatchery
12-22-2006, 01:13 PM
I need to get the filename of the default file for remote sites.
For instance, www.somedomain.com might actually point to file index.php, Index.aspx, default.aspx, etc. I want to get that file name.
I can do this for the current page of the script that is executing by basename($_SERVER['SCRIPT_FILENAME']). however, I need to do this for remote sites.
I want to be able to type www.somedomain.com into an input field and dynamically return the default file name.
NightShift58
12-23-2006, 11:32 AM
I've looked everywhere because the question - or better said, the answer - intrigued me.
I think: no luck. Whenever the target server returns a 200, it also only returns the URL as requested. On 3xx, it will give you the name of the page to which it redirected, but on 200, it just passes back what you ordered and doesn't give any clues as to what the page name might be.
I've tried it on a number of servers/providers and using cURL and HTTP functions . I've tried sending bogus GETs to "coax" a more elaborate answer. None of that worked.
I don't know how critical this is for your project but the only option would be brute force. The headers do return the file size. You could try the various standard defaults (index.html, index.php, etc.) and compare the sizes to that of the default returned by the target server. Not very elegant, to be sure...
sitehatchery
12-23-2006, 01:08 PM
Thanks for looking into this, NightShift58.
It's one of the ways to make this program work correctly. I thought about trying to open connections to each of the default file options and then only using the result that resolved to true. However, it takes too long to open and close connections... especially since the program does this for any number of given pages at a time.
I've spent hours searching and testing as well and I just can't seem to work this one out in this way. But, I may have just now thought up a round about way of getting the same result with the program - without having to know the default file name.
When I finish writing the program, I'll post it to see if anyone can break it.