What is PHP_SELF variable?
PHP_SELF is a variable that returns the current script being executed. This variable returns the name and path of the current file (from the root folder). You can use this variable in the action field of the FORM. There are also certain exploits that you need to be aware of. We shall discuss all these points in this article.
We will now see some examples.
echo $_SERVER['PHP_SELF'];
a) Suppose your php file is located at the address:
http://www.yourserver.com/form-submit.php
In this case, PHP_SELF will contain:
"/form-submit.php"
b) Suppose your php file is located at the address:
http://www.yourserver.com/uri/form-submit.php
For this URL, PHP_SELF will be :
"/uri/form-action.php"
Using the PHP_SELF variable in the action field of the form
However, if you provide the name of the file in the action field, in case you happened to rename the file, you need to update the action field as well. Or else your forms will stop working.
Using PHP_SELF variable you can write more generic code which can be used on any page and you do not need to edit the action field.
Consider, you have a file called form-action.php and want to load the same page after the form is submitted. The usual form code will be:
<FORM method="post" action="form-submit.php" >
We can use the PHP_SELF variable instead of “form-submit.php”. The code becomes:
<FORM name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
Incoming search terms:
- php_self tutorial (14)
- Using PHP_SELF in the action field of a form (5)
- using php_self (4)
- php_self (4)
- symfony2 form onchange (4)
- what is $_php_self (4)
- $PHP_SELF tutorial (3)
- symfony2 php_self (2)
- onchange event of dropdown in yii (2)
- symfony2 forms select onchange (2)
- symfony2 form php_self (2)
- le document a expiré firefox post data (2)
- onchange symfony2 (2)
- dropdownlist onchange event yii (2)
- yii vertical and horizontal menu (2)
- php_self form submit (2)
- $PHP_SELF (2)
- php_self submitting form (2)
- $text_block = <form name=form method=post action=$php_self> (2)
- powershell interview questions (2)
- submitt php (1)
- symfony 2 form multiselect select (1)
- submit form to self best practice php (1)
- symfony 2 form onchange (1)
- submit comment using $php_self() (1)
- php_self stop adding when i refresh the page (1)
- submit and display PHP_SELF : php code (1)
- Prevent form submit on refresh using php_Self (1)
- send php self data using jquery (1)
- self php form (1)
- select list symfony2 dynamically (1)
- run ajax background php_self (1)
- require_once and include (1)
- search filters php jquery mysql (1)
- symfony2 javascript onchange (1)
- upload image in php using php_self (1)
- using $php_self (1)
- using php self instead of javascript (1)
- what is php_self (1)
- using php_self as form action (1)
You will also be interested in ,
- Randomly read and display values of an xml file using php
- Get IP address using gethostbyname() function
- Get youtube video screenshot using simple php and javascript
- Create thumbnail using php and gd library
- How to create random passwords using php
- Database Connection And Pagination In PHP Using Symfony Framework
- MD5 Function and Unique ID in php
- Creating random number using php
- Simple Code To Set And Retrieve Cookie Using PHP
- HTML E-mail Using PHP

