


file_get_contents cannot obtain web content, filegetcontents_PHP tutorial
file_get_contents cannot obtain web content. filegetcontents
In the process of signature verification, the server often needs to obtain a user's information from the channel server. There are generally two methods, curl and file_get_contents.
Under normal circumstances, there will be no problem if you use it like this.
<span> 1</span> <span>public</span> <span>function</span> OauthPostExecuteNew(<span>$sign</span>,<span>$requestString</span>,<span>$request_serverUrl</span><span>){ </span><span> 2</span> <span>$opt</span> = <span>array</span>("http"=><span>array</span><span>( </span><span> 3</span> "method"=>"GET", <span> 4</span> "header"=><span>array</span>("param:".<span>$requestString</span>,"oauthsignature:".<span>$sign</span>), <span> 5</span> "request_fulluri"=><span>true</span> <span> 6</span> <span> ) </span><span> 7</span> <span> ); </span><span> 8</span> <span> 9</span> <span>$context</span> = <span>stream_context_create</span>(<span>$opt</span><span>); </span><span>10</span> <span>$res</span>=<span>file_get_contents</span>(<span>$request_serverUrl</span>, <span>false</span>, <span>$context</span><span>); </span><span>11</span> <span>12</span> <span>return</span> <span>$res</span><span>; </span><span>13</span> }
However, since our server connects to the external network through a proxy, you need to bring the proxy parameter when using stream_context_create to access the channel server.
So in the above code, add the "proxy"=>$proxy field to the $opt array. After adding it, I found that file_get_contents still cannot be verified normally.
I was puzzled, so I went to the official website to check file_get_contents and found that there was no explanation about proxy. Then I searched for stream_context_create and found this official explanation
<p><code class="parameter">params</code></p> <p class="para">必须是 <em>$arr['parameter'] = $value</em> 格式的关联数组。 请参考 context parameters 里的标准资源流参数列表。</p>
Then we enter context_parameters to view the parameter configuration. Because we are using HTTP, check the HTTP context
View proxy-related
<p class="para"><code class="parameter">proxy</code> <span class="type">string</span></p> <p class="para">URI 指定的代理服务器的地址。(e.g. <em>tcp://proxy.example.com:5100</em>).</p> <p class="para"><code class="parameter">request_fulluri</code> <span class="type">boolean</span></p> <p class="para">当设置为 <code>TRUE</code> 时,在构建请求时将使用整个 URI 。(i.e. <em>GET http://www.example.com/path/to/file.html HTTP/1.0</em>)。 虽然这是一个非标准的请求格式,但某些代理服务器需要它。</p> <p class="para">默认值是 <code>FALSE</code>.</p>
I found that only proxy was configured, but request_fulluri was not configured, so I added request_fulluri=true and the verification passed.
Note: When using the proxy parameter, you need to change http to tcp. I don’t know the specific reason. I'll update here when I find out.

TooptimizePHPcodeforreducedmemoryusageandexecutiontime,followthesesteps:1)Usereferencesinsteadofcopyinglargedatastructurestoreducememoryconsumption.2)LeveragePHP'sbuilt-infunctionslikearray_mapforfasterexecution.3)Implementcachingmechanisms,suchasAPC

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.


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

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

SublimeText3 Chinese version
Chinese version, very easy to use

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor
