Explain: php_self or $_SERVER[‘PHP_SELF’] Usage

Can you explain usage of predefined variables called $_SERVER[‘PHP_SELF’]?

PHP programming language provides a lots of predefined variables. Your php script can access a large number of such predefined variables.

$_SERVER array

$_SERVER is an array defined in PHP and it stores information about your server and execution environment information.

$_SERVER[‘PHP_SELF’] variable

This array element points out the filename of the currently executing script. For example, if you run sxi.io/index.php, $_SERVER[‘PHP_SELF’] would be /index.php. This is relative to the document root. This is useful to referring HTML forms and other element.

....
<div class="forumform">
<form action="' . $_SERVER[PHP_SELF]. '" method="post" onSubmit="return checkForm()" name="pforum">
....

….
<div class="forumform">
<form action="’ . $_SERVER[PHP_SELF]. ‘" method="post" onSubmit="return checkForm()" name="pforum">
….

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.