/    Sign up×
Community /Pin to ProfileBookmark

Get default file name of remote site

I need to get the filename of the default file for remote sites.

For instance, [url]www.somedomain.com[/url] 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 [url]www.somedomain.com[/url] into an input field and dynamically return the default file name.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NightShift58Dec 23.2006 — 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 [B]as requested[/B]. 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...
Copy linkTweet thisAlerts:
@sitehatcheryauthorDec 23.2006 — 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.
×

Success!

Help @sitehatchery spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...