PHP hurt me in some places

Source: Internet
Author: User

PHP has been written for a while. There are not many codes, but we have encountered some intractable diseases. This is the first article, which is saved for a long time and updated for a long time to feed the latter.

1. After PHP outputs anything, it cannot plant cookies or header (location :'');

Don't worry, where is var_dump ()? I will handle it myself.

What about utf8bom? So when writing your PHP code, notepad ++ please be sure to use "UTF-8 without BOM format encoding ";

When your code is finally written, enter it with satisfaction. '?> ', Make sure there is no carriage return. In some cases, include will introduce '?> 'Cannot contain cookies. Therefore, we recommend that you open the header in a file '<? PHP ', J does not end with'?> '

The end mark of the PHP code segment at the end of the {Ref: PhP manual} file may not be required. In some cases, it would be better to omit it when using include () or require, in this way, unexpected white spaces will not appear at the end of the file, and the response header can still be output later. It is also convenient to use the output buffer, so you will not see unexpected white spaces generated by the contained files.

2. Fatal error: Can't use method return value in write context in/data/www/test_controller.php

This error occurs when I use empty ($ this-> function (). It mainly means that parameters in the empty () function cannot be returned by other methods.

3. What cookies are used in PHP to obtain cookies?

The cookie in one request cannot be obtained through $ _ cookie in the grade request. The cookie can be obtained only after the next request.

4. header ("Location: http: // your_addresss ");

After the header ("Location: XXXX") is executed, exit is generally added. Otherwise, the code below this sentence will continue to be executed. Of course, you have special requirements. For example, if an error occurs, you can use the header to jump to the error page and then perform some asynchronous error handling procedures.


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.