Maison > php教程 > php手册 > le corps du texte

PHP 常见棘手问题答解

WBOY
Libérer: 2016-06-13 11:00:22
original
803 Les gens l'ont consulté

在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;>Copier après la connexion</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>
Copier après la connexion


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;>Copier après la connexion</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>
Copier après la connexion


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

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

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Recommandations populaires
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal