Fourteen PHP head start to make a big headache summary

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags automatic beginners change content course data difference echo

Fourteen PHP head start to make a big headache summary

Today for everyone to make a headache for PHP beginners to summarize the following 14 questions hope to help beginners PHP.

1, the page can not be passed variables get, post, session Automatic global variables in the latest php version is turned off, so to get over the variables from the previous page to use $ _GET ['foo'], $ _ POST [ 'foo'], $ _ SESSION ['foo']. Of course, you can also modify the automatic global variable to open (php.ini to register_globals = On); For compatibility, or forcing yourself familiar with the new wording better.

2, Win32 apache2 using get method to pass the Chinese parameters will be wrong test.php? A = hello & b = You pass the parameters will lead to an internal error Solution: "test.php? A =". Urlencode (Hello ) "& b =". urlencode (you too)

...

3, win32 under the session can not work php.ini default session.save_path = / tmp

This is obviously the configuration under linux, win32 php session file can not read and write session can not be used to change it into an absolute path on it, for example, session.save_path = c: windows emp

4, showing the error message When php.ini display_errors = On and error_reporting = E_ALL, will display all the errors and prompts, debugging is best opened for error correction, if you use the previous php error message is mostly about undefined Variable The variable is called before the assignment will be prompted, the solution is to detect or shield.

For example, show $ foo, you can if (isset ($ foo)) echo $ foo or echo @ $ foo

5, Win32 mail () can not send e-mail Configured in linux sendmail can be sent under win32 need to call smtp server to send e-mail, modify php.ini SMTP = ip / / ip is without authentication smtp server (hard to find on the Internet) php send mail the best solution is to use socket directly to the other email server without forwarding the server.

6, the initial installation of mysql If you do not set a password, you should use update mysql.user set password = "yourpassword" where user = "root"

Change password 7, header already sent

This error usually occurs when you use HEADER, he may be several reasons: 1, PRING or ECHO before you use the HEADER 2 free lines in front of your current file 3. You may INCLUDE a file, the file Tail of the blank lines or output will be such mistakes.

8, no change after changing php.ini Restart the web server, such as IIS, Apache, etc., and then the latest settings will be applied 9, php installed in 2003 (ISAPI installation method please enlighten expert)

PHP4 php4isapi.dll seems somewhat in conflict with 2003, only CGI mode installation:

Step one, first www.php.net under an installer, I was installed: php-4.2.3-installer.exe, you can also find the latest version, install php-4.2.3-installer. exe prior to ensure that your IIS6.0 started, and be able to visit. After installation, the default site -> application configuration;

Step two: click web service extension -> new web service extension;

Step three: extension -> php, and then add;

Step four: find php.exe path to add up;

Step five: OK on it;

Step Six: Select the php service extension, then click Allow.

10, sometimes sql statement ineffective, the easiest way to debug the database operation, echo that sql, take a look at the value of the variable can not be.

11, the difference between include and require There is not much difference between the two, if you want to include the file does not exist, include prompt notice, and then continue to implement the following statement, require prompt fatal error and exit, as far as I test, win32 platform Is included after the implementation, it is best not to be included in the file include or require statement, this will cause directory confusion. Perhaps * nux under different circumstances, yet to test if a file does not want to be included multiple times can use include_once or require_once ## read and write document data:

The following is quoted content:
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;
}
www.devdao.com

12, the difference between isset () and empty () both test variables.

But isset () is a test variable is assigned, and empty () is to test whether a variable has been assigned empty. If a variable is not assigned on the php reference is allowed, but there will notice notice. If a variable is assigned a null value of $ foo = "" or $ foo = 0 or $ foo = false then empty ($ foo) returns true and isset ($ foo) returns true, meaning that the void value will not be written off A variable

To unregister a variable, use unset ($ foo) or $ foo = NULL.

13, mysql query contains the keyword php query mysql sometimes mysql table name or column name will have a keyword. This time the inquiry will be wrong. For example, the table name is order, the inquiry will be wrong. The simplest way is sql statement table name or column name plus `[tab key above] to be distinguished,

For example select * from `order`.

14, There are two ways to upload multiple files through the HTTP protocol at one time, which are two implementations of the same method. Specific procedures need their own design:

1, set in the form of multiple file input box, name their name with an array, as follows:

The following is quoted content:
<form action = "" method = post>
<input type = file name = usefile []>
<input type = file name = usefile []>
<input type = file name = usefile []>
</ form>
In this way, do the following test on the server echo "<pre>";
print_r ($ _ FILES);
echo "</ pre>";


2, in the form of setting more than one file input box, but the name is different, as follows:

The following is quoted content:
<form action = "" method = post>
<input type = file name = usefile_a>
<input type = file name = usefile_b>
<input type = file name = usefile_c>
</ form>
Do the same test on the server side:
echo "<pre>";
print_r ($ _ FILES);
echo "</ pre>";

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.