The back end of the Web front end foolishly confused,

Source: Internet
Author: User

1.

The front end of the web is sillyOriginal December 25, 2016 19:50:08
    • 7178
    • 0
    • 2
Objective

?? c Development for nearly six years, basically did not contact the web-related things, the original listening to others said that the web-related things when it is not clear which is the front end which is the background, front-end and the background is how to cooperate with the work? Many similar questions were finally made clear after a search by the parties.
?? Using HTML, JavaScript is written in the Web front-end, it does not have to the server (such as Apache, Nginx, Tomcat, etc.) on the browser end of the execution, such as the use of JavaScript pop up a warning box effect. While PHP, Python, and so on is the background language, when the browser to the server to send access to PHP file requests (such as: http://localhost:63342/php_basic/ helloworld.php), the Web server received the request, found that the PHP code is given to the PHP parser to complete the parsing, and then sent back to the Web server, and finally back to the browser.
?? This article will briefly describe the workflow of the front-end and the background, as well as the use of Get and post methods.

Sample code

?? The following code demonstrates the front-end and background mate workflow.

Get mode
<! DOCTYPE html><Html><Head><Metahttp-equiv="Content-type"Content="Text/html; Charset=utf-8 "/><Title></Title><Metacharset="Utf-8"/><ScriptType="Text/javascript"Src="Process.php" ></Script><Script> functionInputcheck(){var user = document.getElementById ("User");if (user.value=="") {alert ("User name is empty!" ");ReturnFalse }var pwd = document.getElementById ("Password");if (pwd.value=="") {alert ("The password cannot be empty!" ")ReturnFalse } }</Script></Head><Body><FormName="MyForm"Method="Get"action="Process.php" ><LabelFor="User" > Username</Label><InputType="Text"Id="User"Name="User"Value="User" ><br/><LabelFor="Password" > password</Label><InputType="Password"Id="Password"name= "password" value= "password" > <br/> <input type=  "submit" id= "submit" name=" submit "value=  "submit" onclick= "return InputCheck () "> </form></ body></HTML>    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21st
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35

?? The From method defines the commit method as get, the data is passed to the background when the "submit" button is clicked, the JavaScript function is called to InputCheck() Check if the input box is empty, and if it is empty, the message is no longer sent to the server.
?? When the two input boxes have content, click the "Submit" button will send the data to the background, and specifically which PHP is specified by the action in the form, where the process.php,process.php code is specified as shown below.

<?php/** * Created by Phpstorm. * User:sweird * Date: 2016/10/10 * time:22:18 */header ( "Content-type:text/html;charset=utf-8"); //support Chinese  $user =$_get[  "user";  $pwd =$_get[ "password"];echo  "This is a message returned from the Web server that has been processed by PHP!" <br/> "; echo  "The user name you submitted is:",  $user,  "<br/>"; echo  "The password you submitted is:",  $pwd; ?>            
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

?? below to see the effect of the operation, this time using phpstorm development, after the code is written, click on the top right corner of the Firefox browser icon.

?? Now jump to Firefox, press F12 to open the Debug window and switch to the Web interface.

?? Then clear the User name input box content, and then click "Submit", then triggered the JavaScript code out of a warning window, and found in the "Network" Interface debugging window and no data, indicating that at this time did not send data to the server, but at the front end of the JS test.

?? Then enter the data in the User name input box and click Submit.

?? At this point in the address bar found that the process.php has been executed, and display the user name and password, and the data displayed in the browser is the background PHP code printed out, so that the front-end and background operation has been demonstrated.

Post mode

?? Here's another look at how PHP gets the data sent from the front end when using the Post method.
?? From the above using the Get method can be seen, how to submit to the server-like password such sensitive information, then is very non-confidential, because in the URL shows the password, then the best way is to post to the background to submit data, Post does not explicitly output the password, But you can still see the password if you open the Debug window.
?? However, when using post, you need to put the relevant PHP code in the Wamp www directory, otherwise you will receive the following error message:

?? Move PHP to the following directory, and then make sure the server starts normally:

?? Then manually enter it in the browser: http://localhost/post_demon.php

?? Click "Submit" to see the following successful interface:

Related code

The post_demon.php code is as follows

<! DOCTYPE html><Html><Head><Metahttp-equiv="Content-type"Content="Text/html; Charset=utf-8 "/><Title></Title><Metacharset="Utf-8"/><ScriptType="Text/javascript"Src="Process_post_data.php" ></Script></Head><Body><FormName="MyForm"Method="POST"action="Process_post_data.php" ><LabelFor="User" > Username</Label><InputType="Text"Id="User"Name="User"Value="User" ><br/><LabelFor="Password" > password</Label><InputType="Password"Id="Password"name= "password" value= "password" > <br/> <input type=  "submit" id= "submit" name=" submit "value=  "submit" onclick= "return InputCheck () "></form></ body></HTML>    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

The process_post_data.php code is as follows:

<?php/** * Created by PhpStorm. * User:sweird * DATE:2016/10/13 * time:21:30 */header ( "Content-type:text/html;charset=utf-8 ");  $name =$_post[ "user"]; $pwd =$_post[ "password"];echo  "This is a message returned from the Web server that has been processed by PHP!" <br/> "; echo  "The user name you submitted is:",  $name,  "<br/>"; echo  "The password you submitted is:",  $pwd; ?>            
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
Copyright NOTICE: This article for Bo Master original article, can be freely reproduced, reproduced please indicate the source: Http://blog.csdn.net/rosettaReport
    • Label:
    • JavaScript/
    • HTML/
    • PHP/
    • Get and Post/
    • Web Front End/

The back end of the Web front end foolishly confused,

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.