If there is any error, you have a better idea, welcome to post. Please take a closer look beforewards.
PHP manual
,
MySQL manual
And the settings inside PHPINFO I hope you read it.
PHP programming standard
PHP manual download address
1: Why can't I get a variable?
I won't have any value when I output $ Name when I output $ Name? Register_global defaults in the version after PHP4.2, if I want to get the variable submitted from another page: Method 1: Locate register_global in php.ini, set it to ON. Method 2: Put this extra in front of the page, put it onto this Extract ($ _ get); (Note Extract ($ _ session) must have Session_Start ()). Method 3: A read variable $ A = $ _ get ["a"]; $ b = $ _ post ["b"], etc., although this method is troublesome, but is safe.
2: Debug your program
You must know what a variable must be known at runtime. I did this, build a file debug.php, the content is as follows:
PHP code:
Php ob_start (); session_start (); echo "
"; echo "This page obtained:"; Print_R ($ _ get); echo "This page received _post variables are:"; Print_r ($ _ post); echo "This page received _Cookie variables are:"; Print_R ($ _ cookie); Echo "This page is:"; Print_R ($ _ session); echo " pre> "Then set in php.ini: include_path = "c: / php", and put the debug.php in this folder, you can include this file in each web page, view the obtained variable name and value .3: How to Using sessions All with session, you must call the function session_start (); it is simple to pay for the session, such as:
PHP code:
php session_start (); $ name = "This is a session example"; session_register ("name"); // Note, don't write: session_register ("$ name"); Echo $ _SESSION ["name"]; / / After $ _SESSION ["Name"] "Is this a session example?>
After PHP4.2, you can pay for the session:
PHP code:
Php session_start (); $ _SESSION ["Name"] = "value";?>
Cancel session can be like this:
PHP code:
php session_start (); session_unset (); session_destroy ();?>>
Cancel a session variable is also bug above PHP4.2. Note: 1: No output before calling session_start (). For example, it is wrong. =============== =========================== 1 line 2 line Php3 line session_start (); // There is already output in the first line 4 Row ..... 5 line?> =========================================== == Tip 1: Any "....... HEADERS ALREADY SENT ..........", it is sent to the browser before session_start (). It is normal to remove the output, (cookie also This error occurs, the error reason is the same) Tip 2: If your session_start () is placed in the loop statement, and it is difficult to determine where to output information to the browser, you can use the following method: 1 line Php ob_start ();?> ...... Here is your procedure ... 2: What is wrong with this? Warning: session_start (): Open (/ tmp / sess_7d190aa36b4c5ec13a5c1649cc2da23f, o_rdwr) failed: ... Because you don't specify the storage path of the session file. Solution: (1) Open php.ini in the C disk, find session.save_path, modified to session.save_path = "C: / TMP" 4 : Why do I send variables to another web page, I only get the first half, and all lost PHP code at the beginning of the space:
php $ var = "Hello PHP"; // Modified to $ VAR = "Hello PHP"; try what results $ pos = "Receive.php? Name =". $ var; header ("location: $ POST ");?>
Receive.php content:
PHP code:
Php echo "
"; echo $ _GET ["name"]; echo " pre>";?>The correct way is:
PHP code:
PHP $ VAR = "Hello PHP"; $ pos = "Receive.php? Name =". Urlencode ($ VAR); Header ("Location: $ POST");?>
You don't need to use urldecode () in the receiving page, and the variable will automatically encode .5: How to intercept the designated length of Chinese characters without the end of "?>", Exceeding the part to "..." instead of general, to take it The variable comes from mysql, first to ensure that the length is long enough, generally CHAR (200), can keep 100 Chinese characters, including punctuation.
PHP code:
Php $ str = "This character is long, ^ _ ^"; $ Short_Str = Showsh ($ STR, 4); // Intercept four Chinese characters, the result is: this character ... Echo "$ Short_STR" Function Csubstr ($ Str, $ Start, $ LEN) {$ Strlen = Strlen ($ STR); $ Clen = 0; for ($ I = 0; $ I
= $ LEN) Break; IF (Substr ($ Str, $ I, 1))> 0xA0) {IF ($ Clen> = $ Start) $ TMPSTR. = Substr ($ Str, $ I , 2); $ I ;} else {IF ($ Clen> = $ Start) $ TMPSTR. = Substr ($ Str, $ I, 1);}} Return $ TMPSTR;} Function Showsh ($ STR, $ LEN) {$ Tempstr = CSUBSTR ($ STR, 0, $ LEN); if ($ STR <> $ TEMPSTR) $ TEMPSTR. = "..."; // To end, modify here. Return $ TEMPSTR; } 6: Specifies your SQL statement in front of the table, the field is "` ", so it will not have an error because of misuse the keyword, of course, I don't recommend you to use keywords. For example, $ sql =" Insert Into` Xltxlm` (`Author`,`, `date`) Values ('XLTXLM', 'Use`', 1, 'Criterion Your Sql string', '2003-07-11 00 : 00: 00 ') "" `" How to enter? On top of the Tab button. 7: How to make the string of the HTML / PHP format is not interpreted, but is displayed as PHP code:
PHP $ STR = "
PHP h1>"; echo "is explained:" $ Str. "
processed:"; Echo Htmlentities (NL2BR ($ STR));? >8: How to get the variable value outside the function in the function
PHP code:
Php $ a = "php"; foo (); function foo () {global $ a; // Delete here to see what results Echo "$ a";}?>>
9: How do I know what function is supported by default?
PHP code:
php $ arr = get_defined_functions (); function php () {} echo "
"; echo "here display all functions supported by the system, and self-qualified function PHP / N"; Print_R ($ ARR); Echo " pre>";?>10: How to compare two dates a few 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); $ D1 = MKTIME (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 "Even I have already struggled $ days day ^ _ ^";?> 11: Why after I upgrade PHP, the original program appears full screen NOTICE: Undefined Variable: This is the meaning of warning, because the variable is not defined. Open php.ini, find the lowermost error_reporting, modify to Error_Reporting = E_ALL & ~ E_NOTICE For PARSE ERROR Error Error_Reporting (0) Can't turn off. If you want to close any error prompt, open php.ini, find display_errors, set to display_errors = Any error will not be prompted later. What is ERROR_REPORTING? 12: I want to add a file in front of each file, but in the end, but a one is very trouble 1: Open the php.ini file settings include_path = " C: "2: Write two files auto_prepend_file.php and auto_append_file.php Save in the C drive, they will automatically attach the head and tail of each PHP file. 3: Find in php.ini: Automatically Add Files Before or After any php document.auto_prepend_file = auto_prepend_file.php; Reit the head auto_APpend_file = auto_append_file.php; After the end of the tail, you will be equivalent to each PHP file.
PHP code:
php include "auto_prepend_file.php"; ....... // Here is your program incrude "auto_append_file.php";?>
13: How to use the PHP upload file
PHP code:
Upload file form title> head>