PHP Beginners Headaches Most of the 14 problems between the "1" side can not pass the variable get,post,session in the latest PHP version of the automatic global variable is turned off, so to get the submission from the previous variable to use $_get[' foo '],$_post[' foo '. , $_session[' foo '] to get. Of course, you can also modify the automatic global variable to open (php. ini to register_globals = on), in view of compatibility, or forced to familiarize themselves with the new writing is better.
"2" win under Apache the Get method to pass Chinese parameters will be wrong:
test.php a= Hello &b= you.
Passing parameters can cause an internal error
Solution: "test.php a=". UrlEncode (Hello). " &b= ". UrlEncode (you are also good)
"3" win under the session does not work properly
PHP. ini default Session.save_path =/tmp
This is obviously the configuration under Linux, win under the PHP can not read and write session files cause session can not use, change it to an absolute path on it, such as Session.save_path = C:windows emp
"4" displays an error message
When PHP. ini's display_errors = on and error_reporting = E_all, all errors and prompts are displayed, and it is best to turn on the error when debugging, if you use the previous PHP coding error message is mostly about undefined variables. Variables are prompted before they are assigned, and the solution is to detect or mask them.
For example, $foo can be displayed, if (Isset ($foo)) echo $foo or echo @ $foo
"5" Win under Mail () cannot send e-mail
Under Linux configured SendMail can send, under win need to invoke SMTP server to send e-mail, modify PHP. ini SMTP = IP//ip is without authentication function SMTP server (difficult to find on the Internet)
The best solution for PHP to send mail is to send it directly to the other email server without forwarding the server.
"6" first installed MySQL if you do not set a password, you should use the update mysql.user set password= "YourPassword" where user= "root" to modify the password
"7" header already sent
This error usually occurs when you use the header, which may be a few reasons: you are pring or echo before using the header. You have a blank line in front of your current file. You may include a file that has a blank line at the end of the file, and this error occurs in the output.
"8" Changes to PHP. INI no change
Restart the Web server, such as Iis,apache, and so on, before applying the latest settings.
"9" PHP installed on 00 (ISAPI installation method kindly advise)
PHP php Isapi.dll seems to be in conflict with 00, only CGI mode installation
Step One, first www.php. NET under one installer, I was pretending to be: PHP-.. -installer.exe, you can also go to the latest version in the installation of PHP-.. -installer.exe before you make sure your IIS6.0 is started and can be accessed. Once installed,--> the application configuration on the default Web site.
Step Two: Click the Web Services extension--> to create a new Web service extension.
Step three: Extension-->php, and then add
Step four: Find the path to PHP. exe add up.
Step five: Be sure!
Step Six: Select the service Extensions for PHP and click Allow.
"10" Sometimes the SQL statement does not work, the database operation failed, the easiest way to debug, echo SQL, look at the value of the variable can be obtained.
The difference between "11" include and require
There is not much difference between the two, if the file you want to include does not exist, include prompts notice, and then proceed to the following statement, require prompt for fatal error and exit.
According to my test, the win platform under which they are all included after the execution, so the included file is best not to have include or require statements, which can cause directory confusion. Perhaps *nux under different circumstances, not yet tested.
If a file does not want to be included multiple times, it can be read using include_once or require_once## to 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;
}
The difference between "12" isset () and Empty ()
Both are used for test variables, but Isset () is the test variable is assigned, and empty () is to test whether a variable that has already been assigned is empty.
If a variable is not assigned to the reference in PHP is allowed, but there will be notice hint, if a variable is assigned null value, $foo = "" or $foo=0 or $foo =false, then empty ($foo) return True, Isset ($foo) also return True, This means that the null value does not unregister a variable.
To unregister a variable, you can use Unset ($foo) or $foo=null
"13" MySQL query statement contains a keyword
PHP query MySQL, sometimes MySQL table name or column name will have a keyword, this time the query will have errors. For example, the table name is an order, the query will be an error, the simple way is the SQL statement table name or column name plus ' [tab] to distinguish between, such as SELECT * from ' order '
"14" Method of uploading multiple files at once via HTTP protocol
There are two ideas, which are two implementations of the same method. Specific procedures also need to design their own.
, set multiple file input boxes in form, and name them by array, as follows:
<form action= "" method=post>
<input Type=file name=usefile[]>
<input Type=file name=usefile[]>
<input Type=file name=usefile[]>
</form>
In this way, the following tests are done on the server side:
echo "<pre>";
Print_r ($_files);
echo "</pre>";
, and set multiple file input boxes in the form, but with different names, as follows:
<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:
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.