Summary and Analysis of PHP headaches for beginners

Source: Internet
Author: User
Tags flock
Article title: Summary and Analysis of PHP headaches for beginners. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
PHP beginners have a headache!
  
[1] The get and post variables cannot be passed between pages. in the latest php version, automatic global variables are disabled, 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.
  
[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 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 thus the session cannot be used.
Change it to an absolute path, for example, session. save_path = c: \ windows \ temp.
  
[4] 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. A prompt is displayed before the variable value is assigned. the solution is to detect or block the variable.
For example, if $ foo is displayed, you can use if (isset ($ foo) echo $ foo or echo @ $ foo.
  
[5] Win32 mail () cannot send email
Sendmail configured in linux can be sent. In win32, you need to call the smtp server to send emails.
Modify SMTP = ip address of php. ini // ip address is an smtp server without verification function (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 the password is not set for the newly installed mysql, use
Update mysql. user set password = "yourpassword" where user = "root"
Change 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 install php-4.2.3-installer.exein www.php.net. you can also find the latest version. before installing php-4.2.3-installer.exe, ensure that your IIS6.0 is started and accessible. After installation, go to the default website --> Application Configuration
Step 2: Click web service extension> Create web service extension.
Step 3: Add the extension --> php
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 and database operations fail.
The simplest debugging method is echo the SQL statement to see if the variable value 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 * nux is different. it hasn't 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 variables.
However, isset () is used to test whether a variable is assigned a value, while empty () is used to test whether a variable that has been assigned a value 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.
  
[13] mysql Query statement contains keywords
When php queries mysql, sometimes the mysql table name or column name has a keyword
At this time, the query will have an error. For example, if the table name is order, an error occurs during query.
The simple method is to add '[tab top] to the table name or column name in the SQL statement to differentiate it.
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. 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:
  
In this way, perform the following tests on the server side:
Echo"
";
  print_r($_FILES);
  echo "
";
  
1. set multiple file input boxes in form with different names, as shown below:
  
Perform the same test on the server:
Echo"
";
  print_r($_FILES);
  echo "
";
  
Related Article

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.