在一个PHP文件中或单独处理多个POST请求 [英] Handling Multiple POST Requests in one PHP file or Separate
问题描述
我是PHP的新手,您也许可以从问题中看出答案.
我所拥有的是一个iOS应用程序,该应用程序使用php前端通过apache服务器访问数据库.我设法通过使用名为NewUser.php
I am new to PHP as you may be able to tell from the question.
What I have is an iOS application that accesses a database via an apache server using a php front end. I have managed to get a user inserted into the database using a POST on a php script called NewUser.php
我正在努力解决的问题是如何组织文件以及是否要为要在数据库上运行的每个查询需要多个php脚本,或者我能够在同一脚本中处理每个不同的POST请求?
The thing I am struggling with is how to organize the files and whether or not I need multiple php scripts for each query I want to run on the database or I am able to handle each different POST request in the same script?
正如我所说的,我是PHP概念的新手.如果有人能为我指明正确的方向,也许是一本教程,或者在这里给我一些指示,那将是很棒的!
As I said I am new to the concept of PHP. If anyone could point me in the right direction to maybe a tutorial or give me some pointers on here that would be great!
迪斯科
推荐答案
是的,您可以在一个脚本中处理更多类型的POST请求.
yes, you can handle more type of POST requests in one script.
例如,脚本名称为action.php,内部代码为:
For example script name is action.php and inside is code:
switch ($_POST['action']) {
case 'insert_user':
// code for inserting new user
break;
case 'delete_user':
// code for deleteing user
break;
// and so on ...
}
在执行POST请求时,您将必须添加参数action
,该参数可以表示正确的操作.
and when are you doing POST request you will have to add parameter action
which one will indetify the correct action.
POST /action.php HTTP/1.1
Some headers
action=insert_user&name=John&surname=Doe....
这篇关于在一个PHP文件中或单独处理多个POST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!