Php $ _ get [] usage

Source: Internet
Author: User

In the php tutorial, $ _ get must get method = get to obtain the data of the Form. Otherwise, the value cannot be obtained normally,

The $ _ GET variable is an array with the variable name and value sent by the http get method.

The $ _ GET variable is used to collect the values in the form from method = "get. The information sent from a form with the GET method is visible to anyone (displayed in the address bar of the browser), and the amount of information sent is limited (up to 100 characters ).


View an instance for obtaining form data

<Input type = "image" NAME = "submit_one" SRC = "B .gif">
<Input type = "image" NAME = "submit_two" SRC = "b2.gif">


// Properly determining which submission button was clicked in PHP:

<? Php
If (isset ($ _ GET ['submit _ one_x ']) {

} Elseif (isset ($ _ GET ['submit _ two_x ']) {
} Else {

}
?>

Instance 2

<?
<Form action = "index. php" METHOD = GET>
<Input type = "hidden" NAME = "time" VALUE = "<? Php echo time () ;?> ">
Enter your message (5 minute time limit): <input type = "text" NAME = "mytext" VALUE = "">
<Input type = "submit" Value = "Send Data">
</FORM>

If ($ _ GET ['time'] + 300> = time ()){
Echo "You took too long! <BR> ";
Exit;
}
?>

Operation select Value

<Select name = "myselect []" multiple size = 3>
<Option value = "value1"> A </OPTION>
<Option value = "value2"> B </OPTION>
<Option value = "value3"> C </OPTION>
<Option value = "value4"> D </OPTION>
</SELECT>


// The PHP code to access which value (s) were selected:

<? Php
Foreach ($ _ GET ['myselect'] as $ val ){
Echo "You selected: $ val <BR> ";
}
Echo "You selected". count ($ _ GET ['myselect']). "Values .";
?>

Obtain the data submitted by the form and then output it. This is also a complete instance.

<Html>
<Head>
<Title> A Simple HTML Form </title>
</Head>
<Body>
<Div>
<Form action = "index. php" method = "get">
<P> <input type = "text" name = "user"/> </p>
<P> <textarea name = "address" rows = "5" cols = "40">
</Textarea> </p>
<P> <input type = "submit" value = "hit! "/> </P>
</Form>
</Div>
</Body>
</Html>


// Index. php
<Html>
<Body>
<Div>
<? Php
Print "Welcome <B>". $ _ GET ['user']. "</B> <br/> nn ";
Print "Your address is: <br/> <B>". $ _ GET ['address']. "</B> ";
?>
</Div>
</Body>
</Html>

Note: When $ _ GET is used, all variable names and values are displayed in the URL. Therefore, this method should not be used when sending passwords or other sensitive information. However, because the variables are displayed in the URL, you can add the page to favorites. In some cases, this is useful.

Note: The http get method is not suitable for large variable values. The value cannot exceed 100 characters.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.