PHP Help

From CLONWiki
Revision as of 09:16, 14 August 2012 by 129.57.81.115 (talk) (Created page with "The $_GET variable is a superglobal Array that contains data from a form sent with method="get" or from URL. Information sent from a form with the GET method will be displayed in...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The $_GET variable is a superglobal Array that contains data from a form sent with method="get" or from URL. Information sent from a form with the GET method will be displayed in the browser's address bar (so, is visible to everyone) and has limits on the amount of data to send (about 2,048 characters).

The $_POST variable is a superglobal Array that contains data from a form sent with method="post". Information sent from a form with the POST method is invisible to the user and hasn't a specified limit on the amount of information to send. By default, PHP permits up to 8MB of POST data (can be changed from the post_max_size in the php.ini file).

The PHP $_REQUEST variable is a superglobal Array that contains the contents of both $_GET, $_POST, and $_COOKIE arrays. It can be used to collect data sent with both the GET and POST methods. Example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<body>
<form action="script.php?id=789" method="post">
Name: <input type="text" name="user" />
<input type="submit" value="Send" />
</form>
</body>
</html>

This code submits a form via the POST method, and when the form is posted, the code sends some values along the URL via the GET method ( "id=789", defined in the address from "action" attribute). The URL will look like this: http://www.coursesweb.net/script.php?id=789 The sent data are loaded in the superglobal $_REQUEST variable /array, and can be used to collect both GET and POST data. For example:

<?php
if (isset($_REQUEST['id']) && isset($_REQUEST['user'])) {
 $id = $_REQUEST['id'];
 $user = $_REQUEST['user'];
 echo 'Welcome '. $user. ' - ID: '. $id;
}
else {
 echo 'Welcome visitor';
}
?>