currentFile (function)

Last updated: Sat, Apr 15, 2023 7:02 pm
Return to Knowledgebase


The function is used to determine the current page URL, which can be useful for generating links or performing other operations that are specific to the current page.




This function does not take any arguments


Data Type Description of Returned Data
string Returns the name of the current file being executed.

Further Documentation:

The currentFile function first declares two global variables, $abs_us_root and $us_url_root, which are used to determine the server and URL roots of the UserSpice application. The function then uses the explode function to split the $_SERVER['PHP_SELF'] variable (which contains the current file path) into an array of directory names. The function then iterates over this array to determine the current file being executed.

The function checks if the z_us_root.php file exists in the $abs_us_root.$us_url_root directory. If the file is found, the function breaks out of the loop and returns the name of the current file. If the file is not found, the function continues to iterate over the directory names until it finds the file or reaches the end of the array.

Finally, the function uses the substr function to extract the current file name from the $_SERVER['PHP_SELF'] variable.

Here is an example of how the currentFile function can be used:

// Get the name of the current file
$currentFile = currentFile();

// Use the current file name to generate a link
echo '$us_url_root . $currentFile . '">Link';

In this example, the currentFile function is called to retrieve the name of the current file. The name of the current file is then used to generate a link to the same page. The $us_url_root variable is used to determine the root URL of the UserSpice application.