PHP beginner headache problem summary

xiaoxiao2021-03-06  57

PHP beginner headache problem summary!

Ganyf

[1] Unable to pass the variable GET, POST, session in the latest PHP version is closed, so you have to get submitted from the previous page to use $ _Get ['foo'], $ _ POST ['foo'], $ _ session ['foo'] get

Of course, the automatic global variable can be modified (php.ini is changed to register_globals = on); considering compatibility or forced yourself with new writing.

[2] Win32 Apache2 uses get method to pass Chinese parameters will be wrong

Test.php? a = Hello & b = you are good

Transfer parameters can cause an internal error

Solution: "Test.php? A =". Urlencode (Hello). "& B =". Urlencode (you)

...........

[3] SESSION below Win32 does not work properly

PHP.ini default session.save_path = / tmp

This is obviously the configuration under Linux, Win32 PHP cannot read and write session files, causing session unused

Change it into an absolute path, such as session.save_path = C: / Windows / Temp

[4] Display error message

When PHP.ini's Display_errors = ON and ERROR_REPORTING = E_ALL, all errors and prompts will be displayed. It is best to open when debugging to correct, if you use the previous PHP write error message, it is about the undefined variable. Variables are called before assignment, and the solution is to detect or block.

For example, Show $ FOO, you can IF (Isset ($ foo)) echo $ foo or echo @ $ foo

[5] Win32 Mail () cannot send an email

Configuring Sendmail in Linux can be sent, you need to call SMTP servers under Win32 to send email

Modifying php.ini's SMTP = IP // IP is a SMTP server without verification (it is difficult to find)

The best solution for PHP sends an email is to send it directly to the other party Email server without forwarding the server.

[6] The initial mysql should be used if you do not set a password.

Update mysql.user set password = "Yourpassword" Where user = "root"

change Password

[7] Header already SENT

This error usually appears when you use Header, he may be a few reasons: 1, you are using header pre-echo 2. You have a blank line in front of your current file 3. You may include a file, this file This error occurs if the tail has a space or output. !

[8] There is no change after changing php.ini

Restart Web Server, such as IIS, Apache, etc., then apply the latest settings

[9] PHP installed in 2003 (ISAPI installation method, please expert advice)

PHP4 of PHP4isapi.dll seems to have some conflicts with 2003, can only be installed with CGI mode

Step 1, first www.php.net is in a setup, I am installing: PHP-4.2.3-installer.exe, you can also go to the latest version, install PHP-4.2.3-Installer. EXE is previously guaranteed that your IIS6.0 is started and can be accessed. After installation, in the default website -> application configuration

Step 2: Click on the web service extension -> New web service extension. Step 3: Extended -> PHP, then add

Step 4: Find the path to PHP.exe to add it.

Step 5: OK is ok!

Step 6: Select the PHP service extension, then click Allow.

[10]

Sometimes the SQL statement does not work, and the database operation failed.

The easiest debugging method, echo SQL, see the value of the variable can be

[11] Interlude and Require

Both don't have much difference, if the file to be included does not exist, the include prompts notice, then proceeds to the statement below, the Require prompts a fatal error and exits

As far as I test, they all include after the Win32 platform, so it is best not to have an incrude or require statement in the included file, which will cause the directory confusion. Perhaps the situation is different under NUX, there is no test yet.

If a file does not want to be included using include_once or remove_once ## read, write document data

Function R ($ file_name) {

$ filenum = @ FOPEN ($ file_name, "r");

@flock ($ filenum, lock_sh);

$ FILE_DATA = @ Fread ($ Filenum, FileSize);

@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] ISSET () and EMPTY ()

Both are used by test variables

But isset () is whether the test variable is assigned, and EMPTY () is whether the variable that has been assigned is empty.

If a variable is not assigned, reference is allowed in PHP, but there will be a Notice prompt.

If a variable is assured, $ foo = "" or $ foo = 0 or $ fals, then Empty ($ foo) returns true, isset ($ foo) returns true, means that the empty value will not log out A variable.

To cancel a variable, you can use unset ($ foo) or $ foo = null

[13] MySQL query statement contains keywords

When PHP query MySQL, sometimes the mysql table name or column name will have keywords.

At this time, the query will have an error. For example, the table name is ORDER, and it will be wrong when the query is

A simple way is that the table name or column name is added in the SQL statement plus the `[Tab button above]

For example, SELECT * from `ORDER`

[14] Method for uploading multiple files at a time by HTTP protocol

There are two ideas, two implementations of the same approach. The specific program also needs to design it yourself.

1. Set multiple file input boxes in Form, name their name with the array, as follows:

In this way, the following test is made on the server.

Echo "

";

Print_r ($ _ files);

ECHO "";

1. Set multiple file input boxes in the Form, but the name is different, as follows:

Make the same test in the server:

Echo "

";

Print_r ($ _ files);

ECHO "";

Posted at 13:55:43 on 02/18/04 by

Sadly - category:

PHP FAQ

转载请注明原文地址:https://www.9cbs.com/read-118211.html

New Post(0)