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

WBOY
发布: 2016-07-15 13:23:22
原创
940 人浏览过

在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语句
在表格,字段前面加上"`",这样就不会因为误用

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. 方法二:在接...
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板