Skip to content

Instantly share code, notes, and snippets.

@jcefoli
Last active Aug 29, 2015
Embed
What would you like to do?
Simple way to get the document name of the page and file extension and uses a switch statement to do something unique based on which page you're on
<?
//Gets the document name of the page. For example, index.php
$getDocument = explode('/', $_SERVER["PHP_SELF"]);
$currentPage = $getDocument[count($getDocument) - 1];
//Switch statement
switch ($currentPage) {
case "index.php":
//do something unique on index.php
break;
case "switchpages.php":
//Do something unique on switchpages.php
break;
default:
echo "Default action. Page is named something other than what we switched through above.";
break;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment