The get, post, and session variables cannot be passed between pages. in the latest php version, automatic global variables are disabled, therefore, to obtain and submit the variables from the previous page, you must use [1] pages to transfer the get and post Variables. in the latest php version, automatic global variables are disabled, therefore, to obtain the submitted variables from the previous page, use $ _ GET ['foo'], $ _ POST ['foo'], $ _ SESSION ['foo. Of course, you can also change the automatic global variable to On (php. ini is changed to register_globals = On). considering compatibility, it is better to force yourself to get familiar with the new writing method.
Note: Super global variables in PHP
From PHP 4.2.0, the default value of register_globals is off. as a result, many previous variables can be directly used, for example, $ PHP_SELF or the SESSION variable you set cannot be accessed in the form of "$ variable name". This may bring you a lot of changes, but it helps improve security. To access these variables, you need to use PHP hyper-global variables as follows:
$ _ SERVER
Variables are set by the Web server or directly associated with the execution environment of the current script. Similar to the old $ HTTP_SERVER_VARS array. The previous $ PHP_SELF corresponds to $ _ SERVER ['php _ SELF ']. you can use phpinfo to view your $ _ SERVER variable.
$ _ GET
Variables submitted to the script through the http get method. Similar to the old $ HTTP_GET_VARS array.
$ _ POST
Variables submitted to the script through the http post method. Similar to the old $ HTTP_POST_VARS array.
$ _ COOKIE
Variables submitted to the script through HTTP Cookies. Similar to the old $ HTTP_COOKIE_VARS array.
$ _ SESSION
The variable currently registered to the script session. Similar to the old $ HTTP_SESSION_VARS array.
$ _ FILES
Variables submitted to the script by uploading the http post file. Similar to the old $ HTTP_POST_FILES array.
$ _ ENV
Variables submitted to the script in the execution environment. Similar to the old $ HTTP_ENV_VARS array.
========================================================== ======================================
For the $ _ FILES variable: (the file field is "myfile ")
$ _ FILES ['myfile'] ['name']
The original name (including the path) of the client machine file ).
$ _ FILES ['myfile'] ['type']
The MIME type of the file, which must be supported by the browser, for example, "image/gif ".
$ _ FILES ['myfile'] ['size']
Size of the uploaded file, in bytes.
$ _ FILES ['myfile'] ['tmp _ name']
Temporary file name (including path) stored on the server after the file is uploaded ).
$ _ FILES ['myfile'] ['error']
The error code related to the file upload. ['Error'] is added in PHP 4.2.0.
When php. when register_globals in ini is set to on, $ myfile_name is equivalent to $ _ FILES ['myfile'] ['name'], $ myfile_type is equivalent to $ _ FILES ['myfile'] ['type.
[2] The session under win32 does not work normally
Php. ini Default session. save_path =/tmp
This is obviously a configuration in linux. In win32, php cannot read or write session files, and the session cannot be used. you can change it to an absolute path, for example, session. save_path = c: \ windows \ temp.
[3] displaying error messages
When php. when display_errors = On and error_reporting = E_ALL of ini, all errors and prompts are displayed. it is best to enable this function during debugging for error correction, if you use php to write errors, most of them are about undefined variables. The variable is called before the value assignment. the solution is to detect or shield the variable. for example, if (isset ($ foo) echo $ foo or echo @ $ foo is displayed.
[4] header already sent
This error usually occurs when you use the HEADER. it may be due to several reasons: 1. you PRING or ECHO before using the HEADER. 2. you have a blank line before the current file. 3. you may INCLUDE a file. this error may also occur if there are blank lines at the end of the file or the output.
[5] php. ini has not changed.
Restart the web server, such as IIS and Apache, and then apply the latest settings.
[6] sometimes SQL statements do not work and database operations fail. The simplest debugging method is echo the SQL statement to see if the value of the variable can be obtained.
[7] Differences between include and require
There is no big difference between the two. if the file to be included does not exist, include prompts notice, and then continues to execute the following statement. require prompts a fatal error and exits. According to the test, on the win32 Platform, they are all included first and then executed. Therefore, it is recommended that there be no include or require statements in the contained files, which will cause directory confusion. Maybe * The situation is different in nux and has not been tested yet. If you do not want to include a file multiple times, you can use include_once or require_once # to read and write the file data:
Function r ($ file_name ){
$ Filenum = @ fopen ($ file_name, "r ");
@ Flock ($ filenum, LOCK_SH );
$ File_data = @ fread ($ filenum, filesize ($ file_name ));
@ Fclose ($ filenum );
Return $ file_data;
}
Function w ($ file_name, $ data, $ method = "w "){
$ Filenum = @ fopen ($ file_name, $ method );
Flock ($ filenum, LOCK_EX );
$ File_data = fwrite ($ filenum, $ data );
Fclose ($ filenum );
Return $ file_data;
}
[8] Differences between isset () and empty ()
Both are used to test the variables, but isset () is used to test whether the variables are assigned values, and empty () is used to test whether a variable that has been assigned values is null. If a variable is not assigned a value, it is allowed to reference it in php, but there will be a notice prompt. If a variable is assigned a null value, $ foo = "" or $ foo = 0 or $ foo = false, empty ($ foo) returns true, isset ($ foo) returns the true value, that is, the null value will not cancel a variable. To cancel a variable, you can use unset ($ foo) or $ foo = NULL.
[9] mysql Query statement contains keywords
When php queries mysql, sometimes the mysql table name or column name has a keyword, and the query will be wrong at this time. For example, if the table name is order, an error will occur during Query. the simple method is to add the '[tab key above]' to the table name or column name in the SQL statement to distinguish it, for example, select * from 'order '.
[10] how to upload multiple files at a time through the HTTP protocol
There are two ways to implement the same method. Specific procedures also need to be designed by yourself
1. set multiple file input boxes in form and name them using arrays, as shown below:
<Form action = "" method = "post">
<Input name = "usefile []" type = "file">
<Input name = "usefile []" type = "file">
<Input name = "usefile []" type = "file">
</Form>
In this way, perform the following tests on the server side:
Echo "<pre> ";
Print_r ($ _ FILES );
Echo "</pre> ";
2. set multiple file input boxes in form with different names, as shown below:
<Form action = "" method = "post">
<Input name = "usefile_a" type = "file">
<Input name = "usefile_ B" type = "file">
<Input name = "usefile_c" type = "file">
</Form>
Perform the same test on the server:
Echo "<pre> ";
Print_r ($ _ FILES );
Echo "</pre> ";