PHP curl simulates post request to submit data_PHP tutorial
Recently I am working on a collection program for campus library book information. Since it is a collection of library books, there must be a page for submitting searches. It is nothing more than post submission, which reminds me of curl simulation submission. First of all Capture packets through firebug and query. The format after submission of the post is as follows:
txtWxlx=CN&hidWxlx=spanCNLx&txtPY=HZ&txtTm=%D2%F4%C0%D6&txtLx=%25&txtSearchType=1&nMaxCount=100&nSetPageSize
=10&cSortFld=%D5%FD%CC%E2%C3%FB&B1=%BC%EC+%CB%F7;
搜索的关键字name=txtTm,随后代码如下:
<br>
<?<span>php </span><span>$keyword</span>="音乐"<span>;</span><span>$post</span>="txtWxlx=CN&hidWxlx=spanCNLx&txtPY=HZ&txtTm={<span>$keyword</span>}&txtLx=%25&txtSearchType=1&nMaxCount=100&nSetPageSize=20&cSortFld=%D5%FD%CC%E2%C3%FB&B1=%BC%EC+%CB%F7"<span>; </span><span>$url</span> = "http://210.30.68.130/wxjs/tmjs.asp"<span>; </span><span>//</span><span>查询地址</span> <span>$ch</span> =<span> curl_init(); curl_setopt (</span><span>$ch</span>, CURLOPT_REFERER, "http://210.30.68.130/wxjs/tmjs_form.asp/ "); <span>//</span><span>模拟来源 </span> curl_setopt(<span>$ch</span>, CURLOPT_URL, <span>$url</span>);<span>//</span><span>URL </span> curl_setopt(<span>$ch</span>,CURLOPT_FOLLOWLOCATION,1<span>); curl_setopt(</span><span>$ch</span>, CURLOPT_HEADER, <span>false</span><span>); curl_setopt(</span><span>$ch</span>, CURLOPT_POST, 1); <span>//</span><span>模拟POST </span> curl_setopt(<span>$ch</span>, CURLOPT_POSTFIELDS, <span>$post</span>);<span>//</span><span>POST内容 </span> curl_exec(<span>$ch</span><span>); </span><span>$output</span> = curl_close(<span>$ch</span><span>); </span><span>echo</span> <span>$output</span><span>; </span>?>
But the page returned always shows that there is no relevant content. If you change the keywords to English or numbers, it can be displayed normally, so I thought this should be an encoding problem, and then you can see txtTm=%D2%F4 on the post. %C0%D6 found out through query that this is url encoding, and Chinese characters will be converted. If it is English, no changes will occur, so some content was added to the header information as follows:
<span>$header</span> = <span>array</span><span>(); </span><span>$header</span>[] = 'User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:30.0) Gecko/20100101 Firefox/30.0'<span>; </span><span>$header</span>[] = 'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'<span>; </span><span>$header</span>[] = 'Connection: keep-alive'<span>; </span><span>$header</span>[] = 'Content-Type:application/x-www-form-urlencoded'<span>; curl_setopt ( </span><span>$ch</span>, CURLOPT_HTTPHEADER, <span>$header</span> );
Actually, the main reason is $header[] = 'Content-Type:application/x-www-form-urlencoded'; after loading the page again, if the Chinese characters are displayed, there is still no relevant content. Then I thought of a very simple problem. , the PHP program is utf8, but the library website is gb2312, okay, let me add another sentence, $keyword = iconv('UTF-8', 'GB2312', $keyword); loaded again successfully, this should be The key to the problem is, then I delete the header information and add $keyword = urlencode($keyword); and load it again, which is the following code:
<?<span>php </span><span>$keyword</span>="世界"<span>; </span><span>$keyword</span> = <span>iconv</span>('UTF-8', 'GB2312', <span>$keyword</span><span>); </span><span>$keyword</span> = <span>urlencode</span>(<span>$keyword</span><span>); </span><span>$post</span>="txtWxlx=CN&hidWxlx=spanCNLx&txtPY=HZ&txtTm={<span>$keyword</span>}&txtLx=%25&txtSearchType=1&nMaxCount=100&nSetPageSize=20&cSortFld=%D5%FD%CC%E2%C3%FB&B1=%BC%EC+%CB%F7"<span>; </span><span>$url</span> = "http://210.30.68.130/wxjs/tmjs.asp"<span>; </span><span>//</span><span>查询地址</span> <span>$ch</span> =<span> curl_init(); curl_setopt (</span><span>$ch</span>, CURLOPT_REFERER, "http://210.30.68.130/wxjs/tmjs_form.asp/ "); <span>//</span><span>模拟来源 </span> curl_setopt(<span>$ch</span>, CURLOPT_URL, <span>$url</span>);<span>//</span><span>URL </span> curl_setopt(<span>$ch</span>,CURLOPT_FOLLOWLOCATION,1<span>); curl_setopt(</span><span>$ch</span>, CURLOPT_HEADER, <span>false</span><span>); curl_setopt(</span><span>$ch</span>, CURLOPT_POST, 1); <span>//</span><span>模拟POST </span> curl_setopt(<span>$ch</span>, CURLOPT_POSTFIELDS, <span>$post</span>);<span>//</span><span>POST内容 </span> curl_exec(<span>$ch</span><span>); </span><span>$output</span> = curl_close(<span>$ch</span><span>); </span><span>echo</span> <span>$output</span><span>; </span>?>
As expected, it was displayed normally, and then there was the problem of collecting and formatting the page content. It’s nothing more than regular. (Because it is a campus network and can only be accessed by our intranet)

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version
Chinese version, very easy to use

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
