ianhaney10 Posted December 9 Share Posted December 9 I have some php code that says if index.php or main root then display some code and if not then show other code and it works on index.php but if it's just the domain name without index.php at the end, it don't work. I have the following code at the moment <?php $currentpage = $_SERVER['REQUEST_URI']; if($currentpage=='/' || $currentpage=="/index.php" || $currentpage=="index.php" || $currentpage=="" ) { ?> Can anyone help me out please as I don't know what to amend for the code to work if main root and not have index.php at the end, the code should be the same for the main root / and index.php Quote Link to comment https://forums.phpfreaks.com/topic/326117-php-if-else-not-working-with-main-root-only-working-for-indexphp/ Share on other sites More sharing options...
Barand Posted December 9 Share Posted December 9 Is "index.php" defined as the default document name? Quote Link to comment https://forums.phpfreaks.com/topic/326117-php-if-else-not-working-with-main-root-only-working-for-indexphp/#findComment-1645263 Share on other sites More sharing options...
Strider64 Posted December 10 Share Posted December 10 (edited) How about something like this? <?php $currentpage = $_SERVER['REQUEST_URI']; if ($currentpage == '/' || $currentpage == '/index.php') { // Code for root or index.php page } else { // Code for other pages } ?> Edited December 10 by Strider64 Quote Link to comment https://forums.phpfreaks.com/topic/326117-php-if-else-not-working-with-main-root-only-working-for-indexphp/#findComment-1645272 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.