I am suffering from a problem while i take the current url of the page and spliting them into parts and then checking for the index.php phrase.So far i have done this:
<?php
$domain=$_SERVER['REQUEST_URI'];
$values = parse_url($domains);
$path = explode('/',$values['path']);
if(array_search($path[2], "index.php"))
{
echo "hello";
}
?>
but its not working so guys help me out and thank you in advance coz i know i will be satisfied by your answers.
Try this:
$_SERVER['PHP_SELF']is the path to the current file on the local system. Since you don’t care about the domain name or the query string, this is easier.strrpos($pathToFile, '/')gets the index of the last occurrence of/in$pathToFile.substr($pathToFile, strrpos($pathToFile, '/') + 1)get the portion of$pathToFilestarting with the character after the index found bystrrpos()in step 2.$currentFilename, which you can compare with whatever you choose.Note that this will match any
index.phpfile, not just the one at your domain root. For example, if your site is located athttp://example.com,http://example.com/subdir/index.phpwould also be true for$currentFilename == 'index.php'. If that’s not what you want, you’d do it a little differently.