Workaround for invalid session and cookie in thinkphp _php instance

Source: Internet
Author: User
This article describes a workaround for invalid session and cookie in thinkphp. Share to everyone for your reference. The specific analysis is as follows:

Problem Description:

In the local debugging session and the cookie is not a problem, I am using the session to save the current login account information, upload the server, found after the jump session no longer exist, why? The current page output session is present.

Encounter this problem three days, because is self-study no teacher can consult, side also not a few is to get PHP, so really is very tragic, Baidu, and Baidu, and many people are fart words, nothing can solve the problem, after three days of modification finally found the root, The original is because the vast majority of support thinkphp server is a Linux system, and our programming is still windows, this will be the problem of BOM header, and PHP for the BOM header can not be resolved, and directly taken down, resulting in session and cookie can not be used.

Workaround:

What is a BOM header? In the Utf-8 encoded file, the BOM in the file header, occupies three bytes, used to indicate that the file belongs to the Utf-8 encoding, now has a lot of software to identify the BOM header, but also some do not recognize the BOM header, such as PHP does not recognize the BOM header, This is also the reason why the error occurs when you edit Utf-8 encoding with Notepad.

The way to get rid of BOM head, simple is the following two kinds:

1, EditPlus to the BOM head method

After the editor is resized to UTF8 encoded format, the saved file will be preceded by a string of hidden characters (also known as BOMs), used by the editor to identify whether the file is encoded in UTF8.

Run EditPlus, click Tools, select Preferences, select files, UTF-8 identity Select always delete signatures, and then edit and save php files without BOM.

2, UltraEdit removal of BOM head method

After opening the file, Save As option to choose the encoding format (utf-8 no BOM header), OK, how to remove the BOM header is very simple.

Another discussion of UTF8 BOM information, BOM refers to the PHP file itself is stored in a BOM with the UTF-8, the normal page of Chinese garbled way is generally not caused by this reason.
Copy the Code code as follows: Header ("content-type:text/html; Charset=utf-8 ");

This sentence controls the HTML output page encoding, the BOM only in Windows under the "notepad" stored as UTF-8, this can be used to winhex the beginning of the 2 bytes deleted.

In Dreamweaver inside the encoding settings can be set whether with a BOM, generally as long as PHP output is not a picture (GDI stream), the BOM will not cause problems, GDI stream if the beginning of the additional characters will be displayed as a red fork.

It is hoped that this article is helpful to the PHP program design based on thinkphp framework.

  • Related Article

    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.