Several small mistakes that PHP novices often make

WBOY
Release: 2016-07-25 09:07:28
Original
915 people have browsed it
This article lists several small mistakes that PHP novices often make for your reference. 1. header already sent This error usually occurs when you use HEADER. It may be due to several reasons.

This article lists several small mistakes that PHP novices often make for your reference.

1. header already sent This error usually occurs when you use HEADER. It may be due to several reasons: 1. You PRING or ECHO before using HEADER 2. There is a blank line in front of your current file 3. You may have INCLUDEd a file. This error will also occur if there is a blank line at the end of the file or the output. !

2. Variables cannot be passed between pages The automatic global variables of get, post, and session are turned off in the latest PHP version, so to get the submitted variables from the previous page, use $_GET['foo'],$ _POST['foo'],$ _SESSION['foo'] to get. Of course, you can also modify the automatic global variables to be on (php.ini changed to reGISter_globals = On); considering compatibility, it is better to force yourself to become familiar with the new writing method.

3. Using the get method to pass Chinese parameters to apache2 under Win32 will cause an error: test.php?a=Hello&b=Hello Passing parameters will cause an internal error ​ Solution: "test.php?a=".urlencode(Hello)."&b=".urlencode(Hello) .............

4. The session under win32 does not work properly. php.ini default session.save_path = /tmp This is obviously a configuration under Linux. PHP under win32 cannot read and write the session file, causing the session to be unusable. Just change it to an absolute path, for example, session.save_path = c:Windows emp

5. Mail() cannot send emails under Win32 Sendmail configured under Linux can be sent. Under win32, you need to call the smtp server to send emails. Modify SMTP = ip in php.ini //ip is an smtp server without verification function (hard to find on the Internet) The best solution for sending emails in PHP is to use socket to send directly to the other party's email server without forwarding the server.

6. If the password is not set for the initial installation of MySQL, you should use update mysql.user set password="yourpassword" where user="root" to change the password

7. Display error message When display_errors = On and error_reporting = E_ALL in php.ini, all errors and prompts will be displayed. It is best to turn it on during debugging for error correction. If you use the previous PHP writing method, most of the error messages will be about undefined variables. There will be a prompt when a variable is called before it is assigned a value. The solution is to detect or shield it. For example, to display $foo, you can if(isset($foo)) echo $foo or echo @$foo



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!