But there's a better way that works no matter what
because it doesn't rely on a specific script filename. It's the built-in PHP superglobal variable $_SERVER['PHP_SELF'] , which stores the name of the current script. You can replace the script URL in the form action to $_SERVER['PHP_SELF'] , and not ever have to worry about updating anything if you ever need to rename the script. The only catch is that $_SERVER['PHP_SELF'] is PHP code, which means you have to echo its value so that it is output as part of the HTML code, like this:
because it doesn't rely on a specific script filename. It's the built-in PHP superglobal variable $_SERVER['PHP_SELF'] , which stores the name of the current script. You can replace the script URL in the form action to $_SERVER['PHP_SELF'] , and not ever have to worry about updating anything if you ever need to rename the script. The only catch is that $_SERVER['PHP_SELF'] is PHP code, which means you have to echo its value so that it is output as part of the HTML code, like this:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Instead of hardcoding the name of our script,
we can tell it to reference itself by using the
$_SERVER[‘PHP_SELF'] superglobal.
we can tell it to reference itself by using the
$_SERVER[‘PHP_SELF'] superglobal.
self-referencing
(from: Head First PHP and MySQL, p200/240)
No comments:
Post a Comment