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 Link to comment https://forums.phpfreaks.com/topic/136035-getting-index-basename-from-an-url/ 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. Link to comment https://forums.phpfreaks.com/topic/136035-getting-index-basename-from-an-url/#findComment-709275 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. Link to comment https://forums.phpfreaks.com/topic/136035-getting-index-basename-from-an-url/#findComment-709282 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; } } ?> Link to comment https://forums.phpfreaks.com/topic/136035-getting-index-basename-from-an-url/#findComment-709286 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. Link to comment https://forums.phpfreaks.com/topic/136035-getting-index-basename-from-an-url/#findComment-709963 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.