Skip to content

Instantly share code, notes, and snippets.

@jcefoli
Last active August 29, 2015 14:03
Show Gist options
  • Save jcefoli/2ed2e0dacf5a85620826 to your computer and use it in GitHub Desktop.
Save jcefoli/2ed2e0dacf5a85620826 to your computer and use it in GitHub Desktop.
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