PHP Exercises : Get the name of the owner of the current PHP script
24. Get Script Owner Name
Write a PHP script to get the name of the owner of the current PHP script.
Sample Solution:
PHP Code:
Explanation:
- Get Current Script Owner:
- The get_current_user() function retrieves the username of the owner of the current PHP script. This is typically the user account under which the web server is running.
- Output the Owner's Username:
- The echo statement concatenates the string 'Current script owner: ' with the result of get_current_user().
- It outputs the full message, followed by a newline (\n), displaying the current script owner's username.
Output:
Current script owner: students
Flowchart:

Note: get_current_user - Gets the name of the owner of the current PHP script.
For more Practice: Solve these Related Problems:
- Write a PHP script to retrieve the file owner’s user name using file owner functions and display it.
- Write a PHP script to compare the current script’s owner with an authorized user list and alert if mismatched.
- Write a PHP script to display both the owner’s name and group information for the current file.
- Write a PHP script to log the current script owner’s name along with the access time for auditing purposes.
Go to:
PREV : Write a PHP script to compare the PHP version.
NEXT : Get Document Root Directory.
PHP Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.