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. Quote Link to comment 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. Quote Link to comment 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(); ?> Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
keeB Posted June 8, 2008 Share Posted June 8, 2008 echo $__FILE__ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.