Monday, March 12, 2007

Handling form data at the server side

  • PHP
If your form is submitted by 'GET' method, the data is sent via url like this http://mydomain.com/test.php?foo1=val1&foo2=val2 At the server side, you can get the string by global variables _SERVER['QUERY_STRING'].
example: $a = explode('&', $_SERVER['QUERY_STRING']); $i = 0; while ($i < count($a)) { $b = split('=', $a[$i]); echo 'Value for parameter ', htmlspecialchars(urldecode($b[0])), ' is ', htmlspecialchars(urldecode($b[1])), " \n"; $i++; } ?>

1 comment:

stone said...

// the following works with both GET and POST

foreach($_SERVER as $key => $val) echo $key . ' : ' . $val;