scarhand Posted December 8, 2008 Share Posted December 8, 2008 i want to figure out the index file basename from an URL so say i enter www.google.com, i want to find out what index file they are using (i.e. index.html) how can i do this? pathinfo doesn't work Quote Link to comment Share on other sites More sharing options...
ratcateme Posted December 8, 2008 Share Posted December 8, 2008 i think really the only way is to compile a list say index.html index.htm index.php index.pl default.asp default.aspx and so on and just try everyone until you get a 200 response code. if you go do http://domain.com/ and get a 302(redirect) then you will be getting redirected to there index page and you should use that. Scott. Quote Link to comment Share on other sites More sharing options...
scarhand Posted December 8, 2008 Author Share Posted December 8, 2008 i think really the only way is to compile a list say index.html index.htm index.php index.pl default.asp default.aspx and so on and just try everyone until you get a 200 response code. if you go do http://domain.com/ and get a 302(redirect) then you will be getting redirected to there index page and you should use that. Scott. thats what i have originally done but i was wondering if there is a better way. Quote Link to comment Share on other sites More sharing options...
scarhand Posted December 8, 2008 Author Share Posted December 8, 2008 heres my current code: $url is a validated URL (with regex) file_extension is a command to get the file extension from the URL url_exists is a command to validate the URL <?php $CONFIG['extensions'] = Array(); $CONFIG['extensions'][] = 'htm'; $CONFIG['extensions'][] = 'html'; $CONFIG['extensions'][] = 'shtm'; $CONFIG['extensions'][] = 'shtml'; $CONFIG['extensions'][] = 'css'; $CONFIG['extensions'][] = 'js'; $CONFIG['extensions'][] = 'vbs'; $CONFIG['extensions'][] = 'php'; $CONFIG['extensions'][] = 'php3'; $CONFIG['extensions'][] = 'php4'; $CONFIG['extensions'][] = 'php5'; $CONFIG['indexfile'] = Array(); $CONFIG['indexfile'][] = 'index.htm'; $CONFIG['indexfile'][] = 'index.html'; $CONFIG['indexfile'][] = 'index.shtm'; $CONFIG['indexfile'][] = 'index.shtml'; $CONFIG['indexfile'][] = 'index.php'; $CONFIG['indexfile'][] = 'index.php3'; $CONFIG['indexfile'][] = 'index.php4'; $CONFIG['indexfile'][] = 'index.php5'; $ext = file_extension($url); if (!in_array($ext, $CONFIG['extensions'])) { if (substr($url, -1) != '/') $url = "$url/"; foreach ($CONFIG['indexfile'] as $ind) { if (url_exists($url.$ind)) $url = $url.$ind; } } ?> Quote Link to comment Share on other sites More sharing options...
ratcateme Posted December 8, 2008 Share Posted December 8, 2008 i don't think so if you go to www.google.com and test aroun dyou will find it is index.html but there is no way to tell from http://www.google.com/ Scott. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.