Why use $_SERVER['PHP_SELF'] instead of ""

forms, php

Solution

The `action` attribute will default to the current URL. It is the most reliable and easiest way to say "submit the form to the same place it came from".

There is no reason to use `$_SERVER['PHP_SELF']`, and `#` doesn't submit the form at all (unless there is a `submit` event handler attached that handles the submission).

Problem

In a form on a PHP page, you can use: ``` <form action="<?php echo $_SERVER['PHP_SELF']; ?>" ...> ``` or ``` <form action="#" ...> ``` or ``` <form action="" ...> ``` in the action attribute of the form. Since echo `$_SERVER['PHP_SELF']` does not pass variables for using `GET` and you have to use `""`, why would you use that or `"#"`? I'm asking because it took me some time to figure out that the variables are not passed with `$_SERVER['PHP_SELF']`. Thanks.

Original source

Related problems