PHP 常见郁闷问题答解
问题
在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代码:
Ob_Start();
Session_Start();
Echo "";<br>Echo "本页得到的_GET变量有:";<br>Print_R($_GET);<br>Echo "本页得到的_POST变量有:";<br>Print_R($_POST);<br>Echo "本页得到的_COOKIE变量有:";<br>Print_R($_COOKIE);<br>Echo "本页得到的_SESSION变量有:";<br>Print_R($_SESSION);<br>Echo "
?>
为什么我向另一网页传送变量时,只得到前半部分,以空格开头的则全部丢失
PHP代码:--------------------------------------------------------------------------------
$Var="hello php";//修改为$Var=" hello php";试试得到什么结果
$post= "receive.php?Name=".$Var;
header("location:$post");
?>
--------------------------------------------------------------------------------
receive.php的内容:
PHP代码:--------------------------------------------------------------------------------
Echo "
";<br>Echo <br>转自喜悦村<br>在PHP4.2以后的版本中register_global默认为off若想取得从另一页面提交的变量:方法一:在PHP.ini中找到register_global,并把它设置为on.方法二:在接收网页最前面放上这个extract($_POST);extract($_GET);(注意extract($_SESSION)前必须要有Session_Start()).方法三:一个一个读取变量$a=$_GET["a"];$b=$_POST["b"]等,这种方法虽然麻烦,但比较安全.<br>PHP代码:<?PHPOb_Start ();Session_Start();Echo "<pre class="brush:php;toolbar:false">";Echo "本页得到的_GET变量有:";Print_R($_GET);Echo "本页得到的_POST变量有:";Print_R($_POST);Echo "本页得到的_COOKIE变量有:";Print_R($_COOKIE);Echo "本页得到的_SESSION变量有:";Print_R($_SESSION);Echo "
为什么我向另一网页传送变量时,只得到前半部分,以空格开头的则全部丢失
PHP代码:--------------------------------------------------------------------------------
$Var="hello php";//修改为$Var=" hello php";试试得到什么结果
$post= "receive.php?Name=".$Var;
header("location:$post");
?>
--------------------------------------------------------------------------------
receive.php的内容:
___FCKpd___1
正确的方法是:
PHP代码:--------------------------------------------------------------------------------
$Var="hello php";
$post= "receive.php?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 ', '2003-07-11 00:00:00')"
我怎么知道系统默认支持什么函数
PHP代码:
--------------------------------------------------------------------------------
"; Echo "这里显示系统所支持的所有函数,和自定以函数php\n"; print_r($arr); echo ""; ?> <br>如何比较两个日期相差几天</p> <p>PHP代码:<br>--------------------------------------------------------------------------------<?PHP $Date_1="2003-7-15";//也可以是:$Date_1="2003-6-25 23:29:14"; $Date_2="1982-10-1"; $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)) ; <br>GET["Name"];<br>Echo "";<br>?></p> <p>--------------------------------------------------------------------------------</p> <p>正确的方法是:</p> <p><br>___FCKpd___2</p> <p>在接收页面你不需要使用Urldecode(),变量会自动编码.</p> <p><br>规范你的SQL语句</p> <p><br>在表格,字段前面加上"`",这样就不会因为误用关键字而出现错误,<br>当然我并不推荐你使用关键字.</p> <p>例如<br>$Sql="INSERT INTO `xltxlm` (`author`, `title`, `id`, `content`, `date`) VALUES ('xltxlm', 'use`', 1, 'criterion your sql string ', '2003-07-11 00:00:00')"</p> <p><br>我怎么知道系统默认支持什么函数</p> <p>___FCKpd___3<br>--------------------------------------------------------------------------------</p> <p><?php <br/>$arr = get_defined_functions(); <br>Function php() {<br>} <br>echo "</p> <pre class="brush:php;toolbar:false">"; <br>Echo "这里显示系统所支持的所有函数,和自定以函数php\n"; <br>print_r($arr); <br>echo "
?>
如何比较两个日期相差几天
___FCKpd___4
--------------------------------------------------------------------------------
$Date_1="2003-7-15";//也可以是:$Date_1="2003-6-25 23:29:14";
$Date_2="1982-10-1";
$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)) ;

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.
