PHP Common depressed problem answer

Source: Internet
Author: User
Problem

Register_global defaults to off in later versions of PHP4.2
To obtain a variable submitted from another page:
Method One: Find the Register_global in the php.ini and set it to on.
Method Two: The Extract ($_post) is placed at the front of the receiving page, and extract ($_get) must have extract () before the $_session (Session_Start) is noted.
Method Three: One reads the variable $a=$_get["a"]; $b =$_post["B"] and so on, this method although troublesome, but relatively safe.

PHP Code:

? Php
Ob_start ();
Session_Start ();
Echo "<pre>";
Echo "The _get variables obtained on this page are:";
Print_r ($_get);
Echo "The _post variables obtained on this page are:";
Print_r ($_post);
Echo "The _cookie variables obtained on this page are:";
Print_r ($_cookie);
Echo "The _session variables obtained on this page are:";
Print_r ($_session);
Echo "</pre>";
?>


When I transfer a variable to another page, I get only the first half, and all that start with a space are lost.

PHP Code:--------------------------------------------------------------------------------

<?php
$Var = "Hello php";//Modify to $var= "Hello php"; try to get a result
$post = "receive.php?" Name= ". $Var;
Header ("Location: $post");
?>

--------------------------------------------------------------------------------
Content of receive.php:


PHP Code:--------------------------------------------------------------------------------

? Php
Echo "<pre>";
Echo
Transfer from Joy Village
In later versions of PHP4.2, Register_global defaults to OFF if you want to obtain a variable submitted from another page: Method one: Find the Register_global in php.ini and set it to On. Method Two: This extract ($_post) is placed at the front of the receiving page and extract ($_get) must have extract () before the $_session (Session_Start). Method Three: One reading variable $a=$_get["a" $b =$_post["B"] and so on, this method, although troublesome, but relatively safe.
PHP Code: Phpob_start (); Session_Start (); Echo "<pre>"; Echo "The _get variables obtained on this page are:"; Print_r ($_get); Echo "The _post variables obtained on this page are:"; Print_r ($_post); Echo "The _cookie variables obtained on this page are:"; Print_r ($_cookie); Echo "The _session variables obtained on this page are:"; Print_r ($_session); Echo "</pre>";? >
When I transfer a variable to another page, I get only the first half, and all that start with a space are lost.

PHP Code:--------------------------------------------------------------------------------

<?php
$Var = "Hello php";//Modify to $var= "Hello php"; try to get a result
$post = "receive.php?" Name= ". $Var;
Header ("Location: $post");
?>

--------------------------------------------------------------------------------

Content of receive.php:

___fckpd___1

The correct approach is to:

PHP Code:--------------------------------------------------------------------------------

<?php
$Var = "Hello php";
$post = "receive.php?" Name= ". UrlEncode ($Var);
Header ("Location: $post");
?>

--------------------------------------------------------------------------------

On the receiving page you do not need to use UrlDecode (), the variable is automatically encoded.
Standardize your SQL statements with "'" in front of the table, field, so that you don't misuse the keyword, but I don't recommend using keywords. For example $sql= "INSERT into ' xltxlm ' (' Author ', ' title ', ' id ', ') ' Content ', ' Date '] VALUES (' xltxlm ', ' use ', 1, ' criterion your SQL string ', ' 2003-07-11 00:00:00 ')
How do I know what functions the system supports by default?

PHP Code:
--------------------------------------------------------------------------------<?php $arr = get_ Defined_functions (); Function php () {} echo   "<pre>"; echo   "Here shows all the functions supported by the system, and the self-tuning function php\n"; Print_r ($arr); echo   "</pre>"?> 
How to compare the two date difference days

PHP Code:
--------------------------------------------------------------------------------? PHP $Date _1= "2003-7-15";//can also be: $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); $d 1=mktime (0,0,0, $Date _list_1[1], $Date _list_1[2], $Date _list_1[0]); $d 2=mktime (0,0,0, $Date _list_2[1], $Date _list_2[2], $Date _list_2[0]); $Days =round (($d 1-$d 2)/3600/24); Echo "I've struggled $Days days";?> data into the database and out to display when the page needs to pay attention to what warehousing $str=addslashes ($str); $sql = "INSERT INTO ' tab ' (' content ') values (' $str '), $str=stripslashes ($STR) when out of the library, $str=htmlspecialchars (NL2BR ($STR) when displayed;
get["Name"];
Echo "</pre>";
?>

--------------------------------------------------------------------------------

The correct approach is to:


___fckpd___2

On the receiving page you do not need to use UrlDecode (), the variable is automatically encoded.


Specification of your SQL statements


In the table, precede the field with "'" so that no error occurs because of misuse of the keyword.
Of course I don't recommend using keywords.

For example
$SQL = "INSERT into ' xltxlm ' (' Author ', ' title ', ' id ', ' content ', ' Date ') VALUES (' xltxlm ', ' use ', 1, ' criterion your Sql s Tring ', ' 2003-07-11 00:00:00 ')


How do I know what functions the system supports by default?

___fckpd___3
--------------------------------------------------------------------------------

<?php
$arr = Get_defined_functions ();
Function php () {
}
echo "<pre>";
Echo "Here shows all the functions supported by the system, and the custom function php\n";
Print_r ($arr);
echo "</pre>";
?>


How to compare two dates by a few days

___fckpd___4
--------------------------------------------------------------------------------

? Php
$Date _1= "2003-7-15";//may also be: $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);
$d 1=mktime (0,0,0, $Date _list_1[1], $Date _list_1[2], $Date _list_1[0]);
$d 2=mktime (0,0,0, $Date _list_2[1], $Date _list_2[2], $Date _list_2[0]);
$Days =round (($d 1-$d 2)/3600/24);
Echo "I have struggled for $Days days";
?>
Data put into the database and taken out to display on the page need to pay attention to what

When in storage
$str =addslashes ($STR);
$sql = "INSERT INTO ' tab ' (' Content ') VALUES (' $str ')";
When you are out of the library
$str =stripslashes ($STR);
When displayed
$str =htmlspecialchars (NL2BR ($STR));



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.