


Struggling for 5 hours to solve the weird PHP problem - 'Image XX cannot be displayed because it has errors'_PHP Tutorial
Yesterday, I finally migrated a client’s website to a virtual host and typed in the URL with great hope. With a snap, the website was opened easily. I feel so happy~~~ Hey, why are the product pictures not shown? Every block is blank. Type in the address corresponding to img src and see what's going on? The result shows the following effect:
This is what it looks like under IE:
No way, start the long debugging process. The solution steps are as follows:
1. Whether it is an error in the function code: follow the keyword image . . . Since there is something wrong with it and it cannot be displayed, I quickly googled a few solutions.
Header("Content-type: image/PNG");这句代码前加上ob_clean();清除输出
Add ob_clean();
to the corresponding code locationThere is no change in the running results.
PS: In order to locate this error, I used echo to output step-by-step debugging for a long time before locating the specific code.
2. Thinking: Why does it work well locally but fails when uploaded? Is it an environment configuration problem?
Local environment XAMP, server environment: windows + IIS7.5.
In order to compare the similarities and differences in the results returned by the Server, we decided to use Fiddler2 to track the similarities and differences between local access to the same file and server access to the same file.
Open Fiddler2 and quickly locate the results.
Test address:
A、http://www.server.net/index.php?ac=public&at=zoom&filename=upfile%2F2011%2F08%2F30%2F20110830222415_540.jpg&w=&h=120&iszoom=1 B、http://localhost:90/index.php?ac=public&at=zoom&filename=upfile%2F2011%2F08%2F30%2F20110830222415_540.jpg&w=&h=120&iszoom=1
The server returns the result:
Local return results:
The similarities and differences are: the server file header has one more
What is this? Continue searching and the result is the BOM header of UTF8. That is, there is an additional BOM header in the file returned by IIS.
For popular knowledge about UTF8, see: http://blog.csdn.net/hiruyue/article/details/8747221
3. Start checking which file was changed into UTF8 with BOM header, so I found a PHP version of the code to detect the BOM header, saved it as a PHP file, and sent it to the server. The result was quickly located. The system configuration file was changed to a file with a BOM header.
At this time, I remembered that after uploading the website using FTP, I used the editing tool that comes with FTP to modify the configuration file. It was modified using NOTEPAD at that time. That's it, quickly download the configuration file again, use NOTEPAD++ to change the file type to UTF8 without BOM, save, upload, and access. The website is finally back to normal.
Look at the time, 5 hours have passed.
PS: In the second step, I also saw that IIS sent an ICO file stream before sending the image binary stream, which also caused an error.
Conclusion:
After the modification was completed, I discovered Brother Orain’s article. He had similar problems to me. PHP uses streaming method to download files and UTF-8 BOM problem
Summary:
1. When you encounter a problem, first think about the cause and then solve it. Otherwise it's easy to get stuck in debugging code.
2. Search multiple times

PHPsessionscanstorestrings,numbers,arrays,andobjects.1.Strings:textdatalikeusernames.2.Numbers:integersorfloatsforcounters.3.Arrays:listslikeshoppingcarts.4.Objects:complexstructuresthatareserialized.

TostartaPHPsession,usesession_start()atthescript'sbeginning.1)Placeitbeforeanyoutputtosetthesessioncookie.2)Usesessionsforuserdatalikeloginstatusorshoppingcarts.3)RegeneratesessionIDstopreventfixationattacks.4)Considerusingadatabaseforsessionstoragei

Session regeneration refers to generating a new session ID and invalidating the old ID when the user performs sensitive operations in case of session fixed attacks. The implementation steps include: 1. Detect sensitive operations, 2. Generate new session ID, 3. Destroy old session ID, 4. Update user-side session information.

PHP sessions have a significant impact on application performance. Optimization methods include: 1. Use a database to store session data to improve response speed; 2. Reduce the use of session data and only store necessary information; 3. Use a non-blocking session processor to improve concurrency capabilities; 4. Adjust the session expiration time to balance user experience and server burden; 5. Use persistent sessions to reduce the number of data read and write times.

PHPsessionsareserver-side,whilecookiesareclient-side.1)Sessionsstoredataontheserver,aremoresecure,andhandlelargerdata.2)Cookiesstoredataontheclient,arelesssecure,andlimitedinsize.Usesessionsforsensitivedataandcookiesfornon-sensitive,client-sidedata.

PHPidentifiesauser'ssessionusingsessioncookiesandsessionIDs.1)Whensession_start()iscalled,PHPgeneratesauniquesessionIDstoredinacookienamedPHPSESSIDontheuser'sbrowser.2)ThisIDallowsPHPtoretrievesessiondatafromtheserver.

The security of PHP sessions can be achieved through the following measures: 1. Use session_regenerate_id() to regenerate the session ID when the user logs in or is an important operation. 2. Encrypt the transmission session ID through the HTTPS protocol. 3. Use session_save_path() to specify the secure directory to store session data and set permissions correctly.

PHPsessionfilesarestoredinthedirectoryspecifiedbysession.save_path,typically/tmponUnix-likesystemsorC:\Windows\TemponWindows.Tocustomizethis:1)Usesession_save_path()tosetacustomdirectory,ensuringit'swritable;2)Verifythecustomdirectoryexistsandiswrita


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
