![]() |
Web Conference 2005Writing PHP for ITS/ASET Web servicesPassing data back via Parameters |
![]() |
| <- Back - Saving Data on the Client | | | Up | | | Using Cookies - Next -> |
Applications such as search engines and catalogs may work well with
navigation and/or state data embedded inside the URL. Any CGI request
using the GET method embeds the parameter=value
data at the end of a URL, which can easily be stored as
bookmarks/favorites, linked from a plain HTML page, or used as the
target of an HTTP redirect (or HTML meta refresh).
Keep in mind GET method data is much more visible than POST method data. It is useful when you want the data accessible in more locations, but not useful for sensitive or large amounts of data.
The following example uses a link to embed data in a URL:
<html>
<head>
<style type="text/css">
<?php
$pageself = basename($_SERVER['PHP_SELF']);
if(isset($_REQUEST['textsize']) and $_REQUEST['textsize'] === "large"){
echo "body { font-family: sans-serif; font-size: 125% }\n";
}elseif(isset($_REQUEST['textsize']) and $_REQUEST['textsize'] === "small"){
echo "body { font-family: sans-serif; font-size: 75% }\n";
}else{
echo "body { font-family: sans-serif; font-size: 100% }\n";
}
?>
</style>
</head>
<body>
<p>You can see how the text size may
<a href="<? echo "$pageself?textsize=large"; ?>">grow</a>,
<a href="<? echo "$pageself?textsize=small"; ?>">shrink</a> or return to
<a href="<? echo "$pageself?textsize=normal"; ?>">normal</a> in a CSS capable
browser. </p>
</body>
</html>
For some applications, you may want to give the user some data that is returned to the server on the submission of a form. When putting values into a form that is expected to be submitted, you may opt to use the GET method to make the values visible in a URL, or you may hide them from the URL using the POST method.
<html>
<body>
<?php $pageself = basename($_SERVER['PHP_SELF']); ?>
<form method=GET action="<?=$pageself?>">
<input type="hidden" name="frompage" value="welcome">
<input type="hidden" name="user" value="mike">
<input type="submit" value="Menu">
</form>
</body>
</html>
Try the above example with method=POST.
| <- Back - Saving Data on the Client | | | Up | | | Using Cookies - Next -> |
|
If you have any questions, feel free to ask me. Content by: Jeff D'Angelo <jcd@psu.edu> © 2005 Last update on: Mon Jun 13, 2005, 1:10:46 AM |
|