A summary of headaches for PHP beginners

Source: Internet
Author: User

Variable get,post,session cannot be passed between "1" pages in the latest version of PHP the automatic global variable is turned off, so to get the submitted variable from the previous page use $_get[' foo '],$_post[' foo '],$_session['. Foo '] to get

Of course, you can also modify the automatic global variable to open (php.ini changed to Register_globals = ON), and it is better to force yourself to be familiar with the new wording, considering compatibility.
"2" Win32 under the apache2 to pass the Chinese parameter with get method will make an error
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)
.............

The session under the

"3" 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 cause session cannot be used


change it to an absolute path, such as Session.save_path = C:windowstemp


"4" Displays the 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 open them when debugging, if you have used PHP to spell the error message mostly about undefined variables. Variables are prompted before they are assigned, and the solution is to detect or mask


such as display $foo, can be if (Isset ($foo)) echo $foo or echo @ $foo


"5" Win32 Mail () cannot send e-mail


The configured SendMail can be sent under Linux, and the SMTP server must be invoked under Win32 to send e-mail


modifies php.ini SMTP = IP//ip is an SMTP server without authentication (hard to find on the Web)

The best way to
PHP is to send mail 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"


Modify Password


"7" header already sent


This error usually occurs when you use the header, which may be several reasons: 1, you pring or Echo 2 before using header. You have a blank line 3 in front of your current file. You may include a file,  This error occurs when there is a blank line in the tail of the file or output.


"8" changes php.ini unchanged after


Restart the Web server, such as Iis,apache, and so on, before applying the latest settings


"9" PHP installed on 2003 (ISAPI installation method kindly advise)


PHP4 's php4isapi.dll seems to be in conflict with 2003 and can only be installed in CGI mode


Step One, First www.php.net in a setup program, I was installed is: Php-4.2.3-installer.exe, you can also go to find the latest version, in the installation of Php-4.2.3-installer.exe before you ensure that your IIS6.0 started, and can access. After installation,--> application configuration on the default Web site


Step Two: Click the Web Service extension--> Create a new Web service extension.


Step three: Extension-->php, then add


Step four: Find the path to the 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 and the database operation fails


easiest way to debug, echo SQL, look at the value of the variable can get no


the distinction 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 a fatal error and exit


according to my test, the Win32 platform they are all included after the execution, so the included file is best not to have include or require statements, which will cause directory confusion. Perhaps *nux under different circumstances, not yet tested


If a file does not want to be included multiple times, you can use include_once or require_once## read 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 () is  
Both are   for the test variable,
but Isset () is the test variable is assigned, and empty () is to test whether a variable that has already been assigned is null  
If a variable is not assigned to the reference in PHP is allowed, but there will be notice hint  
If a variable is null, $foo = "" or $foo=0 or $foo =false, then empty ($foo) returns True, Isset ($ Foo) also returns True, that is, the null value does not unregister a variable. &NBSP
To unregister a variable, you can use Unset ($foo) or $foo=null 
"13" The MySQL query contains keywords  
php query MySQL, Sometimes the MySQL table name or column name will have a keyword  
this time the query will have an error. For example, the table name is Order, the query error  
The simple way is to distinguish the table name or column name in the SQL statement with the ' [Tab key]  
For example, select * from ' Order '  
14 The method of uploading multiple files at a time through HTTP protocol  
has two ideas and is the two implementations of the same method. The specific program also needs to design  
1, set up multiple file input boxes in form, and name them by array, as follows:  
<form action= "" METHOD=POST>&NBSP;
< Input type=file name=usefile[]> 
<input type=file name=usefile[]> 
<input type=file Name =USEFILE[]>&NBSP
</form> 
, do the following test   on the server side;
Echo <pre>;  
Print_r ($_ FILES);  
Echo </pre>;

1, set multiple file input boxes in form, but with different names, as follows:  
<form action= "" Method=post> 
<input type=file USEFILE_A>&NBSP
<input type=file name=usefile_b> 
<input type=file name=usefile_c> &NBSP
</form> 
Do the same test on the server side:  
Echo <pre>;  
Print_r ($_files);  
echo "</pre>";  

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.