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

WBOY
풀어 주다: 2016-07-15 13:23:22
원래의
942명이 탐색했습니다.

在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으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿