PHP $_GET Function

Posted by tutor | Posted in PHP Tutorial | Posted on 14-12-2009-05-2008

0

$_GET is a built-in function in PHP which is used to collect values in a form where the method is “get”.

Get method is rarely used though, as the information sent from a form with the GET method is visible to everyone in the browser’s address bar.

Also it has a limit on the amount of information that can be sent. All the information is concatenated in a single line and this line is printed on the browser’s address bar.

    For eg:

    <form action=”data.php” method=”post”>
    Name: <input type=”text” name=”username” />
    Address: <input type=”text” name=”address” />
    <input type=”submit” />
    </form>

When the user clicks the “Submit” button, the URL sent to the server could look something like this:

    http://www.goweb99.com/data.php?username=Tutor&address=Capital+Federal

The “data.php” file can now use the $_GET function to collect form data (the names of the form fields will automatically be the keys in the $_GET array):

    For eg:

    <html>
    <body>
    Welcome <?php echo $_GET["username"]; ?> ! to the world of PHP<br />
    You live at <?php echo $_GET["address"]; ?> .
    </body>
    </html>

Get method should not be used when sending passwords or other sensitive information.

However, because the variables are displayed in the URL, it is possible to bookmark the page, which may serve some purpose.

Write a comment

Twitter Users
Enter your personal information in the form or sign in with your Twitter account by clicking the button below.