10 knowledge points to confuse PHP beginners (1)

Source: Internet
Author: User
Tags array error code file upload header variables php error version variable

Variable get,post,session cannot be passed between "1" pages in the latest version of PHP the automatic global variable is turned off, so to get the submitted variable from the previous page use $_get[' foo '],$_post[' foo '],$_session['. Foo '] to get. Of course, you can also modify the automatic global variable to open (php.ini changed to Register_globals = ON), and it is better to force yourself to be familiar with the new wording, considering compatibility.

NOTE: Super Global variables in PHP

Starting with the PHP 4.2.0, the default value of Register_globals is off, so many of the previous variables that can be used directly, such as $PHP _self or your set of session variables, cannot be accessed in the form of "$ variable name". This may give you a lot of the same, but it will help you improve your security. To access these variables, you need to use PHP super global variables, as follows:


Variables are set by the WEB server or are directly associated with the execution environment of the current script. Similar to the old array $HTTP _server_vars array. Previous $php_self correspond to $_server[' php_self ', you can use Phpinfo to view your $_server variables.


A variable that is submitted to a script via an HTTP get method. Similar to the old array $HTTP _get_vars array.


A variable that is submitted to the script via the HTTP POST method. Similar to the old array $HTTP _post_vars array.


A variable that is submitted to a script via an HTTP cookie method. Similar to the old array $HTTP _cookie_vars array.


The variable currently registered to the script session. Similar to the old array $HTTP _session_vars array.


A variable submitted to the script via an HTTP POST file upload. Similar to the old array $HTTP _post_files array.


Executes the variables that the environment submits to the script. Similar to the old array $HTTP _env_vars array.

For $_files variables: (File Field field is "MyFile")

$_files[' myfile ' [' Name ']

The original name of the client machine file (including the path).

$_files[' myfile ' [' type ']

The MIME type of the file, which requires the browser to provide support for that information, such as "Image/gif".

$_files[' myfile ' [' Size ']

The 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 associated with the file upload. [' ERROR '] is added in PHP version 4.2.0.

When the register_globals in PHP.ini is set to ON, the $myfile _name equivalent to $_files[' myfile ' [' name '], $myfile _type equivalent to $_files[' myfile '] [' Type '], and so on.

The session under "2" Win32 does not work properly

php.ini default Session.save_path =/tmp

This is obviously the configuration under Linux, Win32 PHP can not read and write session file cause session can not be used, it can be changed to an absolute path, such as Session.save_path = C:\Windows\Temp.

"3" displays an error message

When PHP.ini's display_errors = on and error_reporting = E_all, all errors and prompts are displayed, and it is best to turn on the error when debugging, if you use the previous PHP error message is mostly about undefined variables. Variables are prompted before the assignment, either by probing or masking, such as displaying $foo, or if (Isset ($foo)) Echo$foo or echo @ $foo

"4" header already sent

This error usually occurs when you use the header, he may be several reasons: 1, you are Pring or Echo 2 before using header. You have a blank line 3 in front of your current file. You may include a file with a blank line at the end of the file or an error in the output.

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.