Answers to frequently asked questions about PHP_PHP Tutorial
In PHP4.2 and later versions, register_global defaults to off
If you want to get the variables submitted from another page:
Method 1: Find it in PHP.ini register_global, and set it to on.
Method 2: Put this extract($_POST);extract($_GET); at the front of the receiving web page (note that there must be Session_Start() before extract($_SESSION)) .
Method 3: Read variables $a=$_GET["a"];$b=$_POST["b"], etc. one by one. Although this method is troublesome, it is safer.
<font color="#000000"><code><font color="#000000"><br><font face="新宋体" color="#0000bb"><?PHP <br>Ob_Start</font><font face="新宋体"><font color="#007700">();<br></font><font color="#0000bb">Session_Start</font></font><font face="新宋体"><font color="#007700">();<br>Echo </font><font color="#dd0000">"<pre class="brush:php;toolbar:false">"</pre></font></font><font face="新宋体"><font color="#007700">;<br>Echo </font><font color="#dd0000">"本页得到的_GET变量有:"</font></font><font face="新宋体"><font color="#007700">;<br></font><font color="#0000bb">Print_R</font><font color="#007700">(</font><font color="#0000bb">$_GET</font></font><font face="新宋体"><font color="#007700">);<br>Echo </font><font color="#dd0000">"本页得到的_POST变量有:"</font></font><font face="新宋体"><font color="#007700">;<br></font><font color="#0000bb">Print_R</font><font color="#007700">(</font><font color="#0000bb">$_POST</font></font><font face="新宋体"><font color="#007700">);<br>Echo </font><font color="#dd0000">"本页得到的_COOKIE变量有:"</font></font><font face="新宋体"><font color="#007700">;<br></font><font color="#0000bb">Print_R</font><font color="#007700">(</font><font color="#0000bb">$_COOKIE</font></font><font face="新宋体"><font color="#007700">);<br>Echo </font><font color="#dd0000">"本页得到的_SESSION变量有:"</font></font><font face="新宋体"><font color="#007700">;<br></font><font color="#0000bb">Print_R</font><font color="#007700">(</font><font color="#0000bb">$_SESSION</font></font><font face="新宋体"><font color="#007700">);<br>Echo </font><font color="#dd0000">""</font></font><font face="新宋体" color="#007700">;<br></font><font face="新宋体" color="#0000bb">?><br></font></font><br>
Ob_Start();Session_Start
EchoPHP代码:();<font color="#000000"><br><font color="#0000bb"><?php <br>$Var</font><font color="#007700">=</font><font color="#dd0000">"hello php"</font><font color="#007700">;</font><font color="#ff8000">//修改为$Var=" hello php";试试得到什么结果<br></font><font color="#0000bb">$post</font><font color="#007700">= </font><font color="#dd0000">"receive.php?Name="</font><font color="#007700">.</font><font color="#0000bb">$Var</font><font color="#007700">;<br></font><font color="#0000bb">header</font><font color="#007700">(</font><font color="#dd0000">"location:$post"</font><font color="#007700">);<br></font><font color="#0000bb">?><br></font></font>
""
;
PHP代码:<font color="#000000"><br><font color="#0000bb"><?PHP <br></font><font color="#007700">Echo </font><font color="#dd0000">"<pre class="brush:php;toolbar:false">"</pre></font><font color="#007700">;<br>Echo </font><font color="#0000bb">$_GET</font><font color="#007700">[</font><font color="#dd0000">"Name"</font><font color="#007700">];<br>Echo </font><font color="#dd0000">"</font></font>
Why when I send variables to another web page, I only get the first half, and all the ones starting with spaces are lost
Contents of receive.php:
"PHP代码:<font color="#000000"><br><font color="#0000bb"><?php <br>$Var</font><font color="#007700">=</font><font color="#dd0000">"hello php"</font><font color="#007700">;<br></font><font color="#0000bb">$post</font><font color="#007700">= </font><font color="#dd0000">"receive.php?Name="</font><font color="#007700">.</font><font color="#0000bb">urlencode</font><font color="#007700">(</font><font color="#0000bb">$Var</font><font color="#007700">);<br></font><font color="#0000bb">header</font><font color="#007700">(</font><font color="#dd0000">"location:$post"</font><font color="#007700">);<br></font><font color="#0000bb">?><br></font></font>
;
The correct way is:

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi


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

SublimeText3 Mac version
God-level code editing software (SublimeText3)

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

WebStorm Mac version
Useful JavaScript development tools

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

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
