EXP8 Web Foundation 20155113 Xu Buchao

Source: Internet
Author: User
Tags php basics

EXP8 Web Foundation 1. Experimental requirements
    • Web front-end HTML

Can install normally, start and stop Apache. Understand the HTML, understand the form, understand the get and post methods, and write an HTML containing the form.

    • Web Front End Javascipt

Understand the basic JavaScript functionality and understand the DOM. Write JavaScript to verify the user name, password rules.

    • Web backend: MySQL Foundation: normal installation, start MySQL, build library, create user, change password, build table

    • Web backend: Writing PHP Web pages, connecting databases, authenticating users

    • The simplest SQL injection, XSS attack test

2. Experimental principle 1.1 front end
    • Content: The text of a Web page.
    • Properties: The format of the text.
    • CSS: Displays the "shape" of the text.
    • JavaScript: script that manipulates the contents of the current page.
    • Forms: Labels for special functions, such as Windows, buttons, and so on.
1.2 Backstage
    • PHP: Executable file, you can dynamically generate HTML files.
    • Apache: Apache is responsible for transferring files in the background to the browser via HTTP protocol.
3. Experimental process 3.1 front end
    • First open the Apache service, enter the/etc/init.d/apache2 Start command to open. and enter NETSTAT-APTN to view the occupancy.

    • Open the browser, enter localhost:8080 in the URL, open the test page, the effect is as follows.

    • Create a new HTML document under the/var/www/html directory, named 5113.html. In the editor, enter:

    • Open a browser to view the page:

    • Display is normal.
3.2 JavaScript
    • New 5113_2.html files are still created under the/var/www/html directory. Enter the following code:

    • The code in JavaScript is as follows:

{

function check(Form){    var Username=Form.user.value;    var pwd=Form.pw.value;    if((Username == "")||(pwd == ""))    {    alert("you have to fill in the username and password")    return false;    }if(pwd.length > 16 || pwd.length < 6){    alert("the length of password should between 6 and 16 byte!");    return false;}    For.submit();}

}

    • Explained below
      • In the pageInvokes the check (Form) function in JavaScript when the mouse is clicked.
      • if ((Username = = "") | | (pwd = = "")) If the judgment is empty, a warning is issued.
      • if (Pwd.length > | | pwd.length < 6) Determine if the string is greater than 16 bytes or less than 5 bytes, a warning is issued.

    • Verify that there is a problem with the script.

    • Everything is fine.
3.3 MySQL Basics
    • First turn on the MySQL service and enter/etc/init.d/mysql start.

    • Turn on normal and use the default password to log in to the root user. And then I found out ... emmmlinux in SQL and win under the same, directly enter the mysql+ username + password is wrong. or mysql-u + user name-P bar.

    • Login successful, look at the user table, the results are as follows:

    • Enter the following instructions to change the password

      Update user set Password=password ("New password") where user= ' root ';

Flush privileges;

    • Exit login again. Login OK.

    • Create database name;--Creates a new database.
    • show databases; --Displays all databases.

    • Use + database name;--Using the database.

    • CREATE TABLE table name (field set list);--Creates a new table.

    • Show tables;--shows all the tables.

    • Insert into table name values (' Value 1 ', ' Value 2 ', ' Value 3 ' ...); --Insert new data into the table.
    • SELECT * from table name;--Query the data entry in the table.

    • Grant Select,insert,update,delete on database. * To User name @ login host identified by "password";--authorize new user.

    • Log on with the new user after exiting. Login OK.

3.4 PHP Basics
    • First do a simple test, the code is as follows:

    • Open in the browser will have two different results, one open in the file is this, and the other in the browser input localhost/test.php?a=/etc/passwd, the folder will be all the files are output.

    • Create a new PHP file in/var/html/www/as a bridge between the database and the front end, with the following code:

    • Make a change to the original code, and then I found that the button was wrong, no wonder it looks strange = =.

    • Run the results in the browser as follows:

    • PS, the following code hints may appear when the machine restarts or hangs:

Can ' t connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock ' (2 "No such file or

    • The following workarounds can be used:

      Cd/etc/init.d

      sudo service MySQL stop

      sudo service MySQL start

    • That is, restarting MySQL once can be solved.

    • PPS, I have also had a situation, that is, after clicking the login button to open the New tab, this may be because the form of post and PHP post does not correspond well ... I changed it and suddenly changed it.

3.5 SQL Injection
    • Enter the following string in the user name to log in.

' Or 1=1#

    • The reason for this is that select * from users where username= ' or 1=1# ' and password= ' is a constant judgment condition ———— the first single quote entered is closed with the preceding single quotation mark, and the user name is directly empty. and the additional "or" makes the judgment condition become or the relation, as long as has a condition to be established will judge the landing success. And 1=1 is an identity.
3.6 XSS Attack
    • Put a picture in the/var/www/html directory first. In the Username input box, enter < img src= "1.png"/>xubuqiao read the picture in the/var/www/html directory

    • Click Login to read pictures

    • As explained below, there is an echo uname in login.php. And Uname is received from the front end of the usename, when we enter the user name in the above sentence will be said that this sentence intact to the background, and then executed in the Echo statement. Displays the pictures in the current folder.
4. Experimental Impressions 4.1 questions answered
    • What is a form

      • Forms are primarily responsible for data collection functions in Web pages. There are three basic components of a form: form labels,
        Table fields (contains text box, Password box, hidden field, multiline text box, check box, Radio box, drop-down selection box, file upload box, etc.),
        form buttons, including the Submit button, reset button, and General button. Form buttons can be used to transfer data to CGI scripts on the server or to cancel input, and you can use form buttons to control other processing tasks that define the processing script.
    • The browser can parse what language to run.

      • Supports HTML (Hypertext Markup Language), XML (Extensible Markup Language), and many scripting languages such as Python, PHP, JavaScript, ASP, and more
    • What dynamic languages are supported by webserver

      • JavaScript, ASP, PHP, Ruby and other scripting languages.
    • What is the difference between get and post?

      • Get Back button/Refresh harmless, post data will be resubmitted.
      • Get bookmarks can be collected, post bookmark is not collectible. Get can be cached, post cannot be cached.
      • Get has a limit on the length of data, and when data is sent, the Get method adds data to the URL, and the length of the URL is limited (the maximum length of the URL is 2048 characters). Post is unrestricted.
      • Get only allows ASCII characters. There is no limit to post. Binary data is also allowed.
      • GET is less secure than POST because the data being sent is part of the URL. Never use GET when sending passwords or other sensitive information! POST is more secure than GET because parameters are not saved in the browser history or Web server logs. Get data is visible to everyone in the URL. Post data is not displayed in the URL.
4.2 Experimental Experience
    • In general, this experiment is not very difficult, because I have learned some of the basics of website programming, but because there is no Java, so many things are actually indefinitely. Learning needs to be further strengthened.

EXP8 Web Foundation 20155113 Xu Buchao

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.