14 Notes for PHP

Source: Internet
Author: User
Tags flock
1. The get, post, and session2.Win32 variables cannot be passed between pages. When apache2 uses the get method to pass Chinese parameters, the following error occurs: test. php? A: Hello B. If you pass the parameter, an internal error will occur. Solution: test. php? A. urlencode (Hello). B. urlencode (you can also)... 3. The session under win32 cannot be positive.

1. The get, post, and session variables cannot be passed between pages. 2. in Win32, when apache2 uses the get method to pass Chinese parameters, the following error occurs: test. php? A = Hello B = You can pass the parameter, which will lead to an internal error. Solution: "test. php? A = ". urlencode (Hello)." B = ". urlencode (you can also)... 3. The session under win32 cannot be normal.

1. Variables get, post, and session cannot be passed between pages

2. An error occurs when apache2 uses the get method to pass Chinese parameters under Win32:

Test. php? A = Hello & B = You
Passing parameters will cause an internal error.
 
Solution: "test. php? A = ". urlencode (Hello)." & B = ". urlencode (you can also)
.............

3. The session in win32 cannot work normally.

Php. ini default session. save_path =/tmp
This is obviously a configuration in linux. php in win32 cannot read or write session files, and thus the session cannot be used. You can change it to an absolute path, for example, session. save_path = c: windows emp.

4. Display Error Information

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. A prompt is displayed before the variable is assigned a value. The solution is to detect or block the variable. For example, if (isset ($ foo) echo $ foo or echo @ $ foo

5. Email cannot be sent by mail () under Win32

Sendmail configured in linux can be sent. in win32, you need to call the smtp server to send an email and modify the SMTP = ip address of php. ini.
// The ip address is an smtp server without verification (it is hard to find it online)
The best solution for sending emails in php is to directly send emails to the recipient's email server using socket instead of forwarding the server.

6. If no password is set for the newly installed mysql instance

Use update mysql. user set password = "yourpassword" where user = "root" to change the password

7. 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 .!

8. php. ini has not changed.

Restart the web server, such as IIS and Apache, and then apply the latest settings.

9. install php on 2003 (for how to install ISAPI, please advise)

Php4isapi. dll of PHP4 seems to be in conflict with 2003. It can only be installed in CGI Mode.
  Step 1:First www.php.net under an installer, I installed: php-4.2.3-installer.exe, you can also find the latest version
Before installing php-4.2.3-installer.exe, ensure that your IIS6.0 is started and can be accessed. After installation, go to the default website --> Application
Configuration.
  Step 2:Click web Service Extension> Create web service extension.
  Step 3:Extension --> php, and then add
  Step 4:Find the php.exe path and add it.
  Step 5:OK!
 
  Step 6:Select the php service extension and click "allow.

10. Sometimes SQL statements do not work

The most simple debugging method for database operation failure is echo the SQL statement to see if the value of the variable can be obtained.

11. 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 my tests, 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 document 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;
}

12. 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 be referenced 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, and isset ($ foo) returns true, that is, assigning a null value does not cancel a variable.
 
To cancel a variable, you can use unset ($ foo) or $ foo = NULL.

13. mysql query statements contain 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 the query. The simple method is to add '[ tab key above] to the table name or column name in the SQL statement, for example, select * from 'order'

14. How to upload multiple files at a time through the HTTP protocol

There are two ways to implement the same method. The specific program also needs 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 type = file name = usefile []>
<Input type = file name = usefile []>
<Input type = file name = usefile []>
</Form>

In this way, perform the following tests on the server:

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 type = file name = usefile_a>
<Input type = file name = usefile_ B>
<Input type = file name = usefile_c>
</Form>

Perform the same test on the server:

Echo "<pre> ";
Print_r ($ _ FILES );
Echo "</pre> ";

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.