Content-Length Does Not Output When Retrieving a Page Created by PHP

Asked 2 months ago, Updated 2 months ago, 3 views

Thank you for your help.

We are installing PHP-created pages on the website.
 I got the response header for that page, but I'm a little troubled because it doesn't seem to print Content-Length.
 Is it possible to solve this problem by setting up PHP?
 I would appreciate it if you could give me some advice.
 Thank you for your cooperation.

php

2022-09-30 11:39

1 Answers

(Please forgive me for using the wrong Japanese. I use Google translation to answer this question.)

The best way to calculate the Content-Length response is to use the PHP output buffer. Give me an example:

<?php
    ob_start();// Start capturing your output
    echo('Useful Output'."\n"); // Add some outputs
    header('Content-Length:'.ob_get_length()) ;/ Set HTTP header
    ob_end_flush();// Display your output

This is also useful for creating files and images.

I hope this will help you!


2022-09-30 11:39

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.