首頁 > php教程 > php手册 > 主體

PHP 常见棘手问题答解

WBOY
發布: 2016-06-13 11:00:22
原創
803 人瀏覽過

在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;>登入後複製</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>
登入後複製


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;>登入後複製</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>
登入後複製


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

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

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門推薦
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板