Web服务器(localhost)中的POST如何工作? [英] How does POST in web server (localhost) work exactly?

查看:300
本文介绍了Web服务器(localhost)中的POST如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Web服务器项目的新手,似乎对POST的基本概念有误解,请提供帮助.

I am new to the web server project and I seem to be misunderstanding basic concept of POST, please help.

我认为POST是将数据发布到服务器中的文件上,但是其他人显然不是这样.我怎么了?

I thought of POST as posting data onto file in the server but apparently thats not the case according to other people. What am I getting wrong?

POST数据(例如ajax帖子)到底去了哪里?帖子网址应指向哪个文件? 以及如何保存它,以便您可以关闭浏览器并在下次再次访问它?

Where does the POST data (eg. ajax post) go to exactly? what file should the post url lead to? and how is it saved so that you can close the browser and access it again the next time?

推荐答案

什么是POST?

The POST method does not have any restriction on data size to be sent.

The POST method can be used to send ASCII as well as binary data.

The data sent by POST method goes through HTTP header so security depends on HTTP protocol. By using Secure HTTP you can make sure that your information is secure.

The PHP provides $_POST associative array to access all the sent information using POST method.

从您所在的页面开始,POST用于通过HTTP header

Starting with the page you are on, POST is used to sends data through HTTP header

所以您在home.php page

 <form action ="script.php" method = "POST">
     Name: <input type = "text" name ="name" />
     Age: <input type = "text" name ="age" />
     <input type = "submit" />
  </form>

并且您想对数据进行整洁,这些数据将与表单一起进行POST.单击提交按钮时,将发生这种情况.表单将执行的操作将运行script.php文件.这的确切含义是我们将在php.php页面上放置一个php脚本,因此,在提交表单时,脚本页面将被激活,并且其上的脚本将执行我们想要的任何操作!

And you want to do something neat with the data which will be POST with the form. This will happen when the submit button is clicked. The action the form will take will run the script.php file. What that means exactly is we will put a php script on the script.php page so when our form is submitted the script page will be activated and the script on it will do whatever we want!

在我们的例子中,我们将获取POST数据并将其转换为变量.

In our case we are going to take the POST data and turn them into variables.

 $myName = $_POST['name']; //this is the name ="name" in form
 $myAge = $_POST['age']; //this is the name ="age" in form

现在,如果我们要使用这些数据,我们可以将其回显到屏幕上

now if we want to use this data we can echo it to the screen

echo $myName;
echo $myAge;

现在可以说我们要保存此数据,以便我们可以再次使用它... 我们有选择,一种方法是将其保存到数据库.但是我们会再做一次.

Now lets say we want to save this data so we can use it again... We have options, one way would be to save it to a database. But we will do that another time.

这次,我们可以开始一个会话,然后将数据保存到会话中. 开始会话

This time we can start a session and then save the data to a session. Start session

session_start();

$name = $_POST['name'];

array_push($_SESSION['name'], $name);

print_r($_SESSION['name']);

至此,只要拥有

  session_start();

我们可以调用存储在SESSION中的任何内容.您甚至可以将更多数据推送到SESSION并以相同的方式调用它.

We can call on anything we have stored in our SESSION. you can even push more data to the SESSION and call on it in the same way.

我希望这会有所帮助!

引用

使用PDO的MySql

将表安装在数据库中的示例.

Example with table to install in database.

这篇关于Web服务器(localhost)中的POST如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆