Jump to content

Get The Currently Executing Filename Only


JustinK101

Recommended Posts

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.

<?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();
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.