常见棘手问题答解

2021-08-24 淮安装修公司

在PHP4.2以后的版本中register_global默认为off

若想取得从另一页面提交的变量:

方法一:在i中找到register_global,并把它设置为on.

方法二:在接收页最前面放上这个extract($_POST);extract($_GET);(注意extract($_SESSION)前必须要有Session_Start()).

方法三:一个一个读取变量$a=$_GET[\"a\"];$b=$_POST[\"b\"]等,这种方法虽然麻烦,但比较安全.

PHP代码:

?PHP

Ob_Start();

Session_Start();

Echo \"pre\";

Echo \"本页得到的_GET变量有:\";

Print_R($_GET);

Echo \"本页得到的_POST变量有:\";

Print_R($_POST);

Echo \"本页得到的_COOKIE变量有:\";

Print_R($_COOKIE);

Echo \"本页得到的_SESSION变量有:\";

Print_R($_SESSION);

Echo \"/pre\";

?

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

PHP代码:

?php

$Var=\"hello php\";//修改为$Var=\"hello php\";试试得到什么结果

$post= \"p?Name=\".$Var;

header(\"location:$post\");

?

p的内容:

PHP代码:

?PHP

Echo \"pre\";

Echo$_GET[\"Name\"];

Echo \"/pre\";

?

正确的方法是:

PHP代码:

?php

$Var=\"hello php\";

$post= \"p?Name=\".urlencode($Var);

header(\"location:$post\");

?

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

规范你的SQL语句

在表格,字段前面加上\"`\",这样就不会因为误用关键字而出现错误,

“万一遇到警察突然袭击来检查 当然我并不推荐你使用关键字.

例如

$Sql=\"INSERT INTO `xltxlm` (`author`, `title`, `id`, `content`, `date`) VALUES (\'xltxlm\', \'use`\', 1, \'criterion your sql string \', \' 00:00:00\')\"

我怎么知道系统默认支持什么函数

PHP代码:

?php

$arr = get_defined_functions();

Function php() {

}

echo\"pre\";

Echo\"这里显示系统所支持的所有函数,和自定以函数php\\n\";

print_r($arr);

echo\"/pre\";

?

如何比较两个日期相差几天

PHP代码:

?PHP

$Date_1=\"\";//也可以是:$Date_1=\" 23:29:14\";

$Date_2=\"\";

$Date_List_1=explode(\"-\",$Date_1);

$Date_List_2=explode(\"-\",$Date_2);

$d1=mktime(0,0,0,$Date_List_1[1],$Date_List_1[2],$Date_List_1[0]);

$d2=mktime(0,0,0,$Date_List_2[1],$Date_List_2[2],$Date_List_2[0]);

$Days=round(($d1-$d2)/3600/24);

Echo\"偶已经奋斗了 $Days 天^_^\";

?数据放入数据库和取出来显示在页面需要注意什么

入库时

$str=addslashes($str);

$sql=\"insert into `tab` (`content`) values(\'$str\')\";

出库时

$str=stripslashes($str);

显示时

$str=htmlspecialchars(nl2br($str)) ;

查看本文来源

北京白癜风较好医院
小孩开胃健脾吃什么
月经导致腰疼怎么治疗
为你推荐