Summary of the most confusing questions for PHP beginners

  • 2020-03-31 20:33:02
  • OfStack

[1] there is no way to pass variables get,post, and session between pages. In the latest version of PHP, automatic global variables are closed, so to get the submitted variables from the previous page, you need to use $_GET['foo'],$_POST['foo'], and $_SESSION['foo']
Of course, you can also change the automatic global variable to open (php.ini to register_globals = On). For compatibility reasons, it's better to force yourself to familiarize yourself with the new writing.
[2] under Win32, apache2 using get method to pass Chinese parameters will be wrong
Test. The PHP? A = hello &b= you too
Passing an argument can cause an internal error
Solution :"test.php? A =".urlencode(hello)."&b=". Urlencode (hello).
.

[3] win32 session does not work properly
Php.ini default session.save_path = / TMP
This is obviously a Linux configuration, win32 PHP can not read and write session file so that session can not be used
Change it to an absolute path, such as session.save_path = c: Windows emp
[4] display error messages
When php.ini's display_errors = On and error_reporting = E_ALL, all errors and prompts are displayed. It is best to turn them On when debugging to correct errors. Variables are called before they are assigned. The solution is to detect or mask them
For example, show $foo, if(isset($foo)) echo $foo or echo @$foo
[5] Win32 under mail() can not send E-mail
Configured sendmail can be sent under Linux, and an SMTP server needs to be called to send E-mail under win32
Modify php.ini's SMTP = IP // IP is an SMTP server without authentication (hard to find on the Internet)
The best way for PHP to send mail is to send it directly to the other email server using a socket instead of forwarding it to the server
[6] the newly installed mysql should be used if no password is set
Update mysql.user set password="yourpassword" where user="root"
Change the password
[7] header already sent
This error usually occurs when you use the HEADER, and it can be attributed to several reasons: 1, you PRING or ECHO before using the HEADER; 2, there are empty lines in front of your current file; 3, you may INCLUDE a file, and there are empty lines at the end of the file or output. !
There is no change after changing php.ini
Restart web server, such as IIS, Apache, etc., and then apply the latest Settings
[9] PHP was installed on 2003 (the installation method of ISAPI is kindly advised by the expert)
PHP4 php4isapi.dll seems to have some conflict with 2003, can only be installed in CGI mode
Step one, first under www.php.net in an installation program, I am installed is: php-4.2.3-installer.exe, you can also go to find the latest version, before installing php-4.2.3-installer.exe to ensure that your IIS6.0 started, and can access. Once installed, on the default site --> Application configuration
Step 2: click web service extension --> New web service extension.
Step 3: extension --> PHP, and then add
Step 4: find the path to php.exe and add it.
Step 5: just be sure!
Step 6: select the service extension for PHP, and then click allow.
[10]
Sometimes the SQL statement doesn't work and the operation on the database fails
The easiest way to debug, echo that SQL, is to see if you can get the value of the variable no
【 11 】 the difference between include and require
There's not much difference between the two. If the file you want to include doesn't exist, include prompt notice, and then proceed with the following statement, require prompt fatal error, and exit
According to my test, win32 platform they are first include after execution, so it is best not to include or require statements in the included files, which will cause directory confusion. Maybe *nux is different, not tested yet
If a file doesn't want to be included multiple times, you can use include_once or require_once## to read and write to the 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] the difference between isset() and empty()
Both are used for testing variables
But isset() tests whether a variable is assigned, and empty() tests whether an already assigned variable is empty
It is allowed in PHP to refer to a variable if it is not assigned, but there is an alert
If a variable is assigned a null value, $foo="" or $foo=0 or $foo=false, then empty($foo) returns true and isset($foo) returns true, which means that a null value does not cancel a variable.
To log out a variable, use either unset($foo) or $foo=NULL
[13] mysql query statements contain keywords
When PHP queries mysql, sometimes mysql table names or column names have keywords
There will be an error in the query. For example, if the table name is order, there will be an error in the query
The easy way is to distinguish the table name or column name in the SQL statement with '[TAB key above]
For example, select * from 'order'
[14] the method of uploading more than one file at a time through the HTTP protocol
There are two ideas, two implementations of the same method. Specific procedures also need to design their own
1. Set multiple file input fields in the form and name them with 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, do the following tests on the server side
 
echo "<pre>"; 
print_r($_FILES); 
echo "</pre>"; 

1. Set multiple file input fields 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 same code at the page code block index 2

Related articles: