Apr 10, 2012

$_SERVER['SCRIPT_NAME'] in PHP

$_SERVER['SCRIPT_NAME'] Returns the filename that is being used together with the pre-directory path only. It excludes query/variable appended and any post sub directory.



Displays the current filename.

<?php echo $_SERVER['SCRIPT_NAME']; ?>

http://www.yoursite.com/sample/ -- -- -- /sample/index.php
http://www.yoursite.com/sample/index.php -- -- -- /sample/index.php
http://www.yoursite.com/sample/index.php?q=variable -- -- -- /sample/index.php
http://www.yoursite.com/sample/index.php/directory/test -- -- -- /sample/index.php

No comments: