PHP

  • PHP is a back-end language

  • Why learn a back-end language?

    • There is a need in the market today for front-end people to have a back-end language
    • Easy interaction with back-end developers

Basic Organizational structure

  • Before getting into the back-end language, let’s take a quick look at our basic organizational structure

  • We are a front-end development engineer

  • There is also a job called backend development engineer

  • The organizational structure of one of our websites is basically completed by the following steps

    • Users => Front-end => Back-end => Database
  • The whole process

    • The user asks for a web page from the front end
    • The front end prepares a web page for the user, but the data in the web page is requested by the back end
    • After receiving the data from the front-end staff, the back-end staff will find the corresponding data in the database and give it to the front-end staff
    • The front end takes the data and renders it on the page
    • Finally, show the page to the user
  • For example: We browse a news website

    • The user enters the url
    • The front-end staff will give the corresponding page to the user, in the process of opening the page, to the back-end staff to ask for news information
    • After receiving the news information requested by the front-end staff, the back-end staff will find the corresponding news information data in the database and give it to the front-end staff
    • After receiving the news information from the back-end staff, the front-end staff uses our method to render the news information data on the page
    • The page opens and the user is presented with a news site
  • For example, a user logs in to a website

    • When the user clicks the submit button after writing the form content
    • The front end takes the user’s input, assembles the data and sends it to the back end
    • After receiving the data, the back-end personnel go to the database for comparison to see if there is corresponding data
    • Then tell the front end if you gave me the correct username and password
  • The front end provides feedback to the customer

    • If correct, jump page
    • If the user name or password is incorrect

Simple understanding of servers

  • We can’t just drop the database on the user’s computer
  • One is too big, the other is unsafe
  • So we’re going to put the database on the other side of the network (remote)
  • So the network is needed when the front end person requests data from the back end
  • We can’t put pages on users’ computers
  • So users also need the network to bring all the pages to the front end

Server Knowledge

  • We now have some common servers on the market that can host content
  • The one we use a lot at the momentApacheTomcat
  • That’s what we’re going to learn todayApacheThe server
  • Is a andphpA server with close language cooperation

What exactly is a server

  • In fact, the server is a computer, when he runs some programs, it becomes a server

  • They just run special programs that require special environments

  • In other words, our own computer can also be used as a small server for special programs

    • It’s just that the computing power/storage power/transfer capacity is not as great as that of a professional server computer

How does the server access it

  • It’s about usurlSome content in the address
  • Like our frequent visitorswww.baidu.com
  • There’s a lot of content in this, and what we see here is just an omitted content
  • It was the browser that left out some of the content
  • The full address should behttps://www.baidu.com:443
  • I found two more thingsAnd https:// : 443
  • It’s actually a simple oneurlThe address is made up of three parts
    • Transfer protocol
    • The domain name
    • The port number

Transfer protocol

  • Our common transport protocol ishttphttps
  • They are rules and rules that limit the way users and servers communicate and transfer data
  • It’s also the way our front – and back-end people interact
  • The rules
    • Establishing a connection channel
    • Communicate with each other
    • Close the connection channel
  • onlyhttpIt’s a common protocol. It’s not very secure
  • httpsIt’s an encrypted transport protocol

The domain name

  • As we said earlier, a server is a computer at the other end of a network
  • Before, there was no concept of domain name, everyone used itIPAddress to access
  • That isThe other side of the netOf the computerIP
  • It’s a bunch of numbers. It’s hard to remember
  • Then came the World Wide Web, and he gave each IP address an English name
  • Easy to remember
  • So a domain name represents the IP address of the computer at the other end of the network
  • It’s basically which server we want to access

The port number

  • Somebody else’s server computer also has a lot of folder
  • Different folders store different contents
  • There might be an A folder where the home page is stored
  • So, you can’t just find the server computer, you have to find the right folder
  • Everyone numbered the folders and stored them0 ~ 255A total of 256
  • Each folder has its own smaller folder0 ~ 255A 256
  • So there’s a total of256 * 256A folder, which is from0 ~ 65535
  • So our port number is65536Theta corresponds to theta0 ~ 65535
  • Everyone put80Port number as the default port number for a web site
  • The default HTTP port number is 80
  • The HTTPS protocol uses port 443 by default

baidu

  • So far, we are looking at the full URL of Baidu
  • https://www.baidu.com:443
    • To communicate using an encrypted transport protocol
    • It’s on the networkIPThe value of119.75.217.109The computer
    • Access is number one443The folder
  • Inside this folder is stored a Baidu page
  • We can see this page

PHP Basic syntax

  • It’s important to remember that PHP is another language, not ours anymorehtml / javascript
  • Every other language has its own rules

PHP file

  • We are writingjavascriptWhen, is a.jsfile
  • We are writinghtmlWhen, is a.htmlfile
  • The PHP code is written in a file with the suffix.php

PHP file writing

  • All PHP code should be written in a PHP scope
  • Asked to<? phpAt the beginning
  • Asked to? >At the end
<? PHP # PHP code is written here, okay? >Copy the code

A simple understanding of PHP syntax

  • Every language has its own syntax
  • Let’s take a quick look at the syntax of PHP
  • phpThere’s a point that you have to pay attention toAfter each statement ;

Define variables

  • Not in PHPvarThe keyword defines variables for us
  • Direct use of$To determine a variable

      
 Define a variable and assign it to 100
 $num = $num
 $num = 100;
 $boo = true;
 # Below is a string
 $str = "Hello PHP";
? >
Copy the code

Conditional statements

  • Using conditional statements in PHP is basically the same as using JS

      
  
$boo = true;

if ($boo) {
  echo 'Hello, welcome to watching! ';
} else {
  echo 'You haven't logged in yet';
}  
  
? >
Copy the code

Looping statements

  • In PHP, loop statements are basically the same as JS

      

$num = 5;
  
for ($i = 0; $i < $num; $i{+ +)echo 'hello php';
}
  
? >
Copy the code

String splicing

  • In PHP, string concatenation is no longer used+I’m going to splice it, but I’m going to use.For Mosaic
$str = 'hello ';
$str2 = 'world';
$str3 = $str . $str2;
echo $str3;
# get hello world
Copy the code

An array of

  • Arrays in PHP are particularly different from arrays in JS

      Create an array
 $arr = array(1.2.3);
​
 print_r($arr);
 # Array ( [0] => 1 [1] => 2 [2] => 3 )
 # this is similar to our js array, by indexCreate an associative array
 $arr2 = array('name'= >'Jack'.'age'= >18.'gender'= >'male')
 print_r($arr2)
 # Array ([name] => Jack [age] => 18 [gender] => male)
 # this is similar to our js object, key-value pair form
 
? >
Copy the code

More recommended

  • JavaScript Learning Notes (22) — Prototypes and prototype chains
  • JavaScript Learning Notes (21) — constructors
  • DOM animation effects
  • JavaScript Learning Notes (19) — ES6