I want to make include file with a function, which among other things creates a link to the page itself, with an querystring variable added, how can i get the name of the current php file thus avoiding to have it as a string constant that has to be changed for each different page the include file is included in ?

Regards

Martin Bratbo

I want to make include file with a function, which among other things creates a link to the page itself, with an querystring variable added, how can i get the name of the current php file thus avoiding to have it as a string constant that has to be changed for each different page the include file is included in ?

Regards

Martin Bratbo

$PHP_SELF :cheesy:

Or, if you (very wisely) do not have auto_globals enabled, then $_SERVER.

Get the name of the current php file

Reply:

hope so it works for you.thank you.

<?php
    $currentFile = $_SERVER["PHP_SELF"];
    $parts = Explode('/', $currentFile);
    echo $parts[count($parts) - 1];
?>

You can try this one.hope so it works.

<?php
        $currentFile = $_SERVER["PHP_SELF"];
        $parts = Explode('/', $currentFile);
        echo $parts[count($parts) - 2];   OR echo $parts[count($parts) - 3];
     ?>

Please check and reply me about it.

d'ya think any of the ops are going to read this crap after 7 years

I appreciated it.

too long!

basename($_SERVER['PHP_SELF'], ".php");

Keep it simple.

basename($_SERVER['PHP_SELF'], ".php") is best answer. thanks