PHP post 方法是浏览器客户端向网络服务器发送所需信息的方法之一。基本上,当我们必须登录网站或与邮件交互时,这意味着我们正在处理表单。表单用于获取用户信息并将其提交到网络服务器。它们基本上是 HTML 标签,具有图形用户界面项目,如输入框、单选按钮、复选框等。
开始您的免费软件开发课程
网络开发、编程语言、软件测试及其他
表单是使用
输出:
说明: 在此示例中,我们将看到一个简单的 HTML 表单提交,其中表单由 3 个属性组成:名字、姓氏和邮件 ID。当用户填写所有信息然后单击提交按钮时,输入的数据将使用 HTTP POST 方法发送。
示例#2
代码:
<?php if (!empty($_POST)) { // Defining an array for the list of post values for all the // different forms on the page $pNameArray = array('Form1', 'Form2', 'Form3'); // To search all post identifiers that fall within $_POST $postIdArr = array(); foreach ($pNameArray as $pName) { if (array_key_exists($pName, $_POST)) { $postIdArr[] = $pName; } } // There should be only one post identifier at a time and hence // only an individual form should be used for submitting at a time // A warning statement can be used instead of the die statement as used here if (count($postIdArr) != 1) { count($postIdArr) < 1 or // validation of count die("\Validating count here: " . implode(" ", $postIdArr)); // The above condition is not satisfied hence there is only one post identifier die("\Presence of unknown post"); } // Using switch statement to execute the codes for respective forms switch ($postIdArr[0]) { case 'Form1': echo "Execute actual code for Form1."; break; case 'Modifyform': echo "Execute actual code for Form2."; break; case 'Deleteform': echo "Execute actual code for Form3."; break; } } else // $_POST is empty. { // displaying that POST is not executed echo "POST is empty"; } ?>
输出:
说明: 在此示例中,我们将了解 POST 方法如何适用于多种表单。因此,我们使用 switch 语句来处理不同的表单,并且所有表单都应该是不同的,以便处理时不会出现任何错误。如果我们需要添加更多表单,只需要在数组和 switch 语句中添加一个条目即可。
示例#3
代码:
<?php if( POST["fullname"] || POST["weight"] || POST["height"] ) { if (preg_match("/[^A-Za-z'-]/",$_POST['fullname'] )) { die ("The name given is invalid and should be alpha"); } echo "Welcome ". $_POST['fullname']. "<br />"; echo "Welcome ". $_POST['height']. "<br>"; echo "You are ". $_POST['weight']. "weight in kgs"; exit(); } ?>
输出:
说明: 本例中的查询字符串发送到 POST 方法请求的 HTTP 消息正文。这里我们指定了 3 个属性,即全名、身高和体重。
PHP 中 POST 方法相对于 GET 方法的优点
- 与 GET 相比,POST 方法更安全,因为用户输入的信息不会显示在 URL 查询字符串或服务器日志中。
- POST 方法可以传递的数据范围比 GET 方法更大,因为它既可以发送文本数据,也可以发送二进制数据,例如使用 POST 方法上传文件。它支持许多此类高级功能。
- 它支持各种不同的数据类型,如数字、字符串、二进制类型。
结论
如上所示,基本上PHP的Post方法是用来收集表单数据的。因此使用 HTTP Post 方法通过 Web 服务器发送信息。由于此信息在地址栏中永远不可见,因此通常用于通过服务器发送敏感数据。它们在性能方面也有一些缺点,POST 方法请求不会被缓存,因此不会保留在浏览器历史记录中。
以上是PHP POST 方法的详细内容。更多信息请关注PHP中文网其他相关文章!

tomakephpapplicationsfaster,关注台词:1)useopcodeCachingLikeLikeLikeLikeLikePachetoStorePreciledScompiledScriptbyTecode.2)MinimimiedAtabaseSqueriSegrieSqueriSegeriSybysequeryCachingandeffeftExting.3)Leveragephp7 leveragephp7 leveragephp7 leveragephpphp7功能forbettercodeefficy.4)

到ImprovephPapplicationspeed,关注台词:1)启用opcodeCachingwithapCutoredUcescriptexecutiontime.2)实现databasequerycachingusingpdotominiminimizedatabasehits.3)usehttp/2tomultiplexrequlexrequestsandredececonnection.4 limitsclection.4.4

依赖注入(DI)通过显式传递依赖关系,显着提升了PHP代码的可测试性。 1)DI解耦类与具体实现,使测试和维护更灵活。 2)三种类型中,构造函数注入明确表达依赖,保持状态一致。 3)使用DI容器管理复杂依赖,提升代码质量和开发效率。

databasequeryOptimizationinphpinvolVolVOLVESEVERSEVERSTRATEMIESOENHANCEPERANCE.1)SELECTONLYNLYNESSERSAYCOLUMNSTORMONTOUMTOUNSOUDSATATATATATATATATATATRANSFER.3)

phpisusedforsenderemailsduetoitsbuilt-inmail()函数andsupportiveLibrariesLikePhpMailerandSwiftMailer.1)usethemail()functionforbasicemails,butithasimails.2)butithasimimitations.2)

PHP性能瓶颈可以通过以下步骤解决:1)使用Xdebug或Blackfire进行性能分析,找出问题所在;2)优化数据库查询并使用缓存,如APCu;3)使用array_filter等高效函数优化数组操作;4)配置OPcache进行字节码缓存;5)优化前端,如减少HTTP请求和优化图片;6)持续监控和优化性能。通过这些方法,可以显着提升PHP应用的性能。

依赖性注射(DI)InphpisadesignPatternthatManages和ReducesClassDeptions,增强量产生性,可验证性和Maintainability.itallowspasspassingDepentenciesLikEdenceSeconnectionSeconnectionStoclasseconnectionStoclasseSasasasasareTers,interitationApertatingAeseritatingEaseTestingEasingEaseTeStingEasingAndScalability。

cachingimprovesphpermenceByStorcyResultSofComputationsorqucrouctationsorquctationsorquickretrieval,reducingServerLoadAndenHancingResponsetimes.feftectivestrategiesinclude:1)opcodecaching,whereStoresCompiledSinmememorytssinmemorytoskipcompliation; 2)datacaching datacachingsingMemccachingmcachingmcachings


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。