Home > Article > Backend Development > How to write an interface in PHP
The virtual host in the host house supports the PHP environment, so we can directly throw the PHP file to the virtual host and access it. In this way, we can write an interface ourselves and call it to the client. Verify now.
New php file
First, we create a new php file, no php development For the environment, use EditPlus to create a new document, and then directly enter a piece of content you want to return, then save, rename, and change the suffix to .php. Finally, throw it on the virtual host, as shown below: (Recommended learning: PHP video tutorial)
Put it on it and use the browser to You can directly access and open it. Enter the address: http://49.4.144.xxx/test.php
Because it is in the Web directory, you can directly add the name of the file after the IP address or domain name. Open.
get request
When we use get request, the link is usually followed by ?key=value to pass the parameters, Then, check After studying the PHP syntax, I found that this operation is enough:
<?php $x = 5; $y = $_GET['id']; $z = $x + $y;echo "变量z为: $z"; ?>
The above code is to get the value of the id on the link, then add it to the value of x, and then return. Then verify:
ok, just as we thought, the content was returned successfully. In this way, A simple get request interface is completed.
The above is the detailed content of How to write an interface in PHP. For more information, please follow other related articles on the PHP Chinese website!