|
Search:
Advanced search
|
Browse by category:
|
Contact Us |
Unset HTTP GET Variables in PHP |
|||||
If you haven't learned yet, the PHP unset() command does not work to unset variables already established in the url.
for example. (phpfile.php) --------------------------------------------------------------------------------------------------- <?php echo "<html> <body> <a href=\"$SERVER['PHP_SELF']?passvar=1\">Click here</a> </body></html>"; ?> --------------------------------------------------------------------------------------------------- In the above example, after clicking on the URL, the url will read http://mydomain/path/phpfile.php?passvar=1 I have found the easiest way to clear the GET variable is to 1) capture the GET variable results 2)refresh the page. Example (phpfile.php) --------------------------------------------------------------------------------------------------- <?php if (!empty($_GET['passvar'])) { unset($_GET['passvar']); echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=".$_SERVER['PHP_SELF']."\" >"; } echo "<html> <body> <a href=\"$SERVER['PHP_SELF']?passvar=1\">Click here</a> </body></html>"; ?> --------------------------------------------------------------------------------------------------- The same method works for POST variables. Simply change the unset($_GET['passvar']) to unset($_POST['passvar']) |
|||||
| Others in this Category | |
| Adding a background color for each row of an html select drop down (pull down) menu. | |
Powered by
KBPublisher (Knowledge base software)