Dave's Brain

Browse - Programming Tips - How can I find the name of the current script?

Date: 2009may22
Language: php

Q.  How can I find the name of the current script?

A.  Use the function below:

// Helper function function get_server($var) { return isset($_SERVER[$var]) ? $_SERVER[$var] : ''; } function get_self() { return basename(get_server('PHP_SELF')); } function example_use() { if (get_self() == 'index.php') { print 'Welcome'; } }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.