Get Current Page Name in php

by Jayanthi 2011-09-28 16:58:32

If the page is located in sub-folder, then this variable will return the page name
along with sub-folder name also (e.g test/common/index.php)

If you want to get only the filename (e.g index.php).


<?php

$currentpage=$_SERVER['SCRIPT_NAME'];
echo "scriptname : \$_SERVER['SCRIPT_NAME']";
echo "<br>Current page : ".$currentpage."<br>"; // get subfolder/index.php
$currentpage=basename($_SERVER['SCRIPT_NAME']);
echo "<br>Current page : ".$currentpage; // get index.php

echo "<br><br>php self : \$_SERVER['PHP_SELF']";

$currentpage=$_SERVER['PHP_SELF']; // get subfolder/index.php
echo "<br>Current page : ".$currentpage."<br>";
$currentpage=basename($_SERVER['PHP_SELF']); // get index.php
echo "<br>Current page : ".$currentpage;

?>

Tagged in:

1135
like
0
dislike
0
mail
flag

You must LOGIN to add comments