< Buzzing or vibrating the login form using jquery Posted On May 15, 2012 : 0 comments << >> Simple div slideshow using jquery Posted On May 9, 2012 : 0 comments << >> Copy mysql column in varchar to type date Posted On May 3, 2012 : 0 comments << >> Enter only numbers inside a input field of a form using javascript Posted On May 1, 2012 : 0 comments << >> Slide in and out animate div vertically using jquery Posted On April 25, 2012 : 1 comment << >> Tag cloud using php, mysql and ajax with filter Posted On April 24, 2012 : 0 comments << >> Change webpage font color or background color from the user side using javascript Posted On April 19, 2012 : 0 comments << >> A single link that cycles through several webpage background color using javascript Posted On April 17, 2012 : 0 comments << >> Simple webpage redirection using perl script Posted On April 10, 2012 : 0 comments << >> Get ipaddress using perl script Posted On April 4, 2012 : 0 comments << >>

Using PHP_SELF best practices

This Tutorial Has Been Viewed 1,331 Times.
VN:F [1.9.17_1161]
Rating: 0.0/10 (0 votes cast)


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

A common use of PHP_SELF variable is in the action field of the <form> tagThe action field of the FORM instructs where to submit the form data when the user presses the “submit” button. It is common to have the same PHP page as the handler for the form as well.

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']; ?>" >
VN:F [1.9.17_1161]
Rating: 0.0/10 (0 votes cast)

Incoming search terms:





You will also be interested in ,

Tags:

Leave a Reply

Proudly designed by Mistonline.in.
Affordable Seo PackagesSeo BlogEdu Backlinks