PHP 常见棘手问题答解_PHP教程

WBOY
Freigeben: 2016-07-15 13:23:22
Original
942 Leute haben es durchsucht

在PHP4.2以后的版本中register_global默认为off
若想取得从另一页面提交的变量:
方法一:在PHP.ini中找到register_global,并把它设置为on.
方法二:在接收网页最前面放上这个extract($_POST);extract($_GET);(注意extract($_SESSION)前必须要有Session_Start()).
方法三:一个一个读取变量$a=$_GET["a"];$b=$_POST["b"]等,这种方法虽然麻烦,但比较安全.

PHP代码:
<font color=&quot;#000000&quot;><br><font face=&quot;新宋体&quot; color=&quot;#0000bb&quot;><?PHP <br>Ob_Start</font><font face=&quot;新宋体&quot;><font color=&quot;#007700&quot;>();<br></font><font color=&quot;#0000bb&quot;>Session_Start</font></font><font face=&quot;新宋体&quot;><font color=&quot;#007700&quot;>();<br>Echo </font><font color=&quot;#dd0000&quot;>&quot;<div class=&quot;code&quot; style=&quot;position:relative; padding:0px; margin:0px;&quot;><pre class=&quot;brush:php;toolbar:false&quot;>&quot;</pre><div class=&quot;contentsignin&quot;>Nach dem Login kopieren</div></div></font></font><font face=&quot;新宋体&quot;><font color=&quot;#007700&quot;>;<br>Echo </font><font color=&quot;#dd0000&quot;>&quot;本页得到的_GET变量有:&quot;</font></font><font face=&quot;新宋体&quot;><font color=&quot;#007700&quot;>;<br></font><font color=&quot;#0000bb&quot;>Print_R</font><font color=&quot;#007700&quot;>(</font><font color=&quot;#0000bb&quot;>$_GET</font></font><font face=&quot;新宋体&quot;><font color=&quot;#007700&quot;>);<br>Echo </font><font color=&quot;#dd0000&quot;>&quot;本页得到的_POST变量有:&quot;</font></font><font face=&quot;新宋体&quot;><font color=&quot;#007700&quot;>;<br></font><font color=&quot;#0000bb&quot;>Print_R</font><font color=&quot;#007700&quot;>(</font><font color=&quot;#0000bb&quot;>$_POST</font></font><font face=&quot;新宋体&quot;><font color=&quot;#007700&quot;>);<br>Echo </font><font color=&quot;#dd0000&quot;>&quot;本页得到的_COOKIE变量有:&quot;</font></font><font face=&quot;新宋体&quot;><font color=&quot;#007700&quot;>;<br></font><font color=&quot;#0000bb&quot;>Print_R</font><font color=&quot;#007700&quot;>(</font><font color=&quot;#0000bb&quot;>$_COOKIE</font></font><font face=&quot;新宋体&quot;><font color=&quot;#007700&quot;>);<br>Echo </font><font color=&quot;#dd0000&quot;>&quot;本页得到的_SESSION变量有:&quot;</font></font><font face=&quot;新宋体&quot;><font color=&quot;#007700&quot;>;<br></font><font color=&quot;#0000bb&quot;>Print_R</font><font color=&quot;#007700&quot;>(</font><font color=&quot;#0000bb&quot;>$_SESSION</font></font><font face=&quot;新宋体&quot;><font color=&quot;#007700&quot;>);<br>Echo </font><font color=&quot;#dd0000&quot;>&quot;&quot;</font></font><font face=&quot;新宋体&quot; color=&quot;#007700&quot;>;<br></font><font face=&quot;新宋体&quot; color=&quot;#0000bb&quot;>?><br></font></font><br>

为什么我向另一网页传送变量时,只得到前半部分,以空格开头的则全部丢失

PHP代码:
<font color=&quot;#000000&quot;><br><font color=&quot;#0000bb&quot;><?php <br>$Var</font><font color=&quot;#007700&quot;>=</font><font color=&quot;#dd0000&quot;>&quot;hello php&quot;</font><font color=&quot;#007700&quot;>;</font><font color=&quot;#ff8000&quot;>//修改为$Var=&quot;     hello php&quot;;试试得到什么结果<br></font><font color=&quot;#0000bb&quot;>$post</font><font color=&quot;#007700&quot;>= </font><font color=&quot;#dd0000&quot;>&quot;receive.php?Name=&quot;</font><font color=&quot;#007700&quot;>.</font><font color=&quot;#0000bb&quot;>$Var</font><font color=&quot;#007700&quot;>;<br></font><font color=&quot;#0000bb&quot;>header</font><font color=&quot;#007700&quot;>(</font><font color=&quot;#dd0000&quot;>&quot;location:$post&quot;</font><font color=&quot;#007700&quot;>);<br></font><font color=&quot;#0000bb&quot;>?><br></font></font>
Nach dem Login kopieren


receive.php的内容:

PHP代码:
<font color=&quot;#000000&quot;><br><font color=&quot;#0000bb&quot;><?PHP <br></font><font color=&quot;#007700&quot;>Echo </font><font color=&quot;#dd0000&quot;>&quot;<div class=&quot;code&quot; style=&quot;position:relative; padding:0px; margin:0px;&quot;><pre class=&quot;brush:php;toolbar:false&quot;>&quot;</pre><div class=&quot;contentsignin&quot;>Nach dem Login kopieren</div></div></font><font color=&quot;#007700&quot;>;<br>Echo   </font><font color=&quot;#0000bb&quot;>$_GET</font><font color=&quot;#007700&quot;>[</font><font color=&quot;#dd0000&quot;>&quot;Name&quot;</font><font color=&quot;#007700&quot;>];<br>Echo </font><font color=&quot;#dd0000&quot;>&quot;</font></font>
"
;
?>


正确的方法是:

PHP代码:
<font color=&quot;#000000&quot;><br><font color=&quot;#0000bb&quot;><?php <br>$Var</font><font color=&quot;#007700&quot;>=</font><font color=&quot;#dd0000&quot;>&quot;hello php&quot;</font><font color=&quot;#007700&quot;>;<br></font><font color=&quot;#0000bb&quot;>$post</font><font color=&quot;#007700&quot;>= </font><font color=&quot;#dd0000&quot;>&quot;receive.php?Name=&quot;</font><font color=&quot;#007700&quot;>.</font><font color=&quot;#0000bb&quot;>urlencode</font><font color=&quot;#007700&quot;>(</font><font color=&quot;#0000bb&quot;>$Var</font><font color=&quot;#007700&quot;>);<br></font><font color=&quot;#0000bb&quot;>header</font><font color=&quot;#007700&quot;>(</font><font color=&quot;#dd0000&quot;>&quot;location:$post&quot;</font><font color=&quot;#007700&quot;>);<br></font><font color=&quot;#0000bb&quot;>?><br></font></font>
Nach dem Login kopieren


在接收页面你不需要使用Urldecode(),变量会自动编码.

规范你的SQL语句
在表格,字段前面加上"`",这样就不会因为误用

http://www.bkjia.com/PHPjc/446874.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/446874.htmlTechArticle在PHP4.2以后的版本中register_global默认为off 若想取得从另一页面提交的变量: 方法一:在PHP.ini中找到register_global,并把它设置为on. 方法二:在接...
Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage