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 (11)
- using php_self (4)
- php_self (4)
- what is $_php_self (4)
- Using PHP_SELF in the action field of a form (3)
- onchange symfony2 (2)
- $PHP_SELF (2)
- php_self submitting form (2)
- yii vertical and horizontal menu (2)
- $text_block = <form name=form method=post action=$php_self> (2)
- php_self form submit (2)
- submit comment using $php_self() (1)
- submit and display PHP_SELF : php code (1)
- send php self data using jquery (1)
- self php form (1)
- run ajax background php_self (1)
- require_once and include (1)
- Prevent form submit on refresh using php_Self (1)
- powershell interview questions (1)
- php_self stop adding when i refresh the page (1)
- submit form to self best practice php (1)
- submitt php (1)
- symfony2 dynamic form (1)
- _server \php_self\ tutorial (1)
- yii dropdownlist select part from database (1)
- using several forms and php self (1)
- using PHP_SELF in form (1)
- using php_self as form action (1)
- symfony2 form onchange (1)
- using php self search (1)
- using php self instead of javascript (1)
- upload image in php using php_self (1)
- Tutorials for php_self (1)
- tutorial php_self form (1)
- tutorial php_self action (1)
- symfony2 javascript onchange (1)
- php_self rating (1)
- php_self post email tutorial (1)
- php_self form tutorial (1)
- login in same page using php_self (1)
You will also be interested in ,
- Apache AddHandler application/x-httpd-php not working?
- Adding Handlers Directly In httpd.conf Of Apache
- How to avoid direct access to a file in php
- PHP is not executed and source visible
- working with directories using php
- Total Number Of Rows In MYSQL
- Redirect webpage using php
- Speed up wordpress using .htaccess part 1
- Zip or Archive a directory using php
- Get browser language using php
