JustinK101 Posted June 8, 2008 Share Posted June 8, 2008 I only want the currently executing filename, so for example: http://www.mydomain.com/folder1/folder2/login.php I only want login.php. I have tried the following: $_SERVER['PHP_SELF'], $_SERVER['SCRIPT_FILENAME'], $_SERVER['REQUEST_URI'] but they all return folder1/folder2/login.php. Thanks. Link to comment https://forums.phpfreaks.com/topic/109209-get-the-currently-executing-filename-only/ Share on other sites More sharing options...
pocobueno1388 Posted June 8, 2008 Share Posted June 8, 2008 echo '<pre>',print_r($_SERVER),'</pre>'; Execute that code and look through the output for what your looking for. Link to comment https://forums.phpfreaks.com/topic/109209-get-the-currently-executing-filename-only/#findComment-560234 Share on other sites More sharing options...
jonsjava Posted June 8, 2008 Share Posted June 8, 2008 <?php function filename(){ $url = $_SERVER['PHP_SELF']; preg_match("/[^\/]+$/",$url,$matches); $file_name = $matches[0]; return $file_name; } ?> Edit: converted it into a function. to run: <?php include("your_include_that_contains_functions.php"); print filename(); ?> Link to comment https://forums.phpfreaks.com/topic/109209-get-the-currently-executing-filename-only/#findComment-560236 Share on other sites More sharing options...
JustinK101 Posted June 8, 2008 Author Share Posted June 8, 2008 $filename = basename($_SERVER['PHP_SELF']); Works like a champ. Very counter-intuitive, but whatever it works. Link to comment https://forums.phpfreaks.com/topic/109209-get-the-currently-executing-filename-only/#findComment-560239 Share on other sites More sharing options...
keeB Posted June 8, 2008 Share Posted June 8, 2008 echo $__FILE__ Link to comment https://forums.phpfreaks.com/topic/109209-get-the-currently-executing-filename-only/#findComment-560244 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.