Home Backend Development PHP Tutorial 关于ob_start();该怎么解决

关于ob_start();该怎么解决

Jun 13, 2016 am 10:36 AM
quot setcookie start

关于ob_start();
想问一下 ob_start();ob_get_contents();ob_end_clean();
此3个函数 具体有什么用 且什么情况下用这些函数

------解决方案--------------------
翻版一下03年怪署黍的回答

PHP4 的新函数介绍 - 输出信息控制函数
 魔族精灵


这些函数可以让你控制你的脚本输出的内容.可以用于许多不同的情况,特别是在你的脚本已经输出信息后需要发送文件头新的情况. 输出控制函数不对使用 header() 或 setcookie() 发送的文件头信息产生影响,只对那些类似于 echo() 和 PHP 代码的数据块有作用.

例 1. 控制输出


ob_start();
echo "Hello\n ";

setcookie ( "cookiename ", "cookiedata ");

ob_end_flush();

?>

在上面的例子中,使用 echo() 的输出内容将会保存在输出缓冲区中,直到调用了 ob_end_flush(). 这样做有意义的地方是,调用 setcookie() 的内容被成功的存储在 cookie 里面而不会引起错误. (正常情况下,你不可以在有数据已经发送后再发送文件头信息到用户浏览器.)

相关函数 header() and setcookie().

韩数列表
flush — 刷新输出缓冲区
保存在输出缓冲区的内容会被发送到浏览器

ob_start — 打开输出缓冲区
这样所有的输出信息不在直接发送到浏览器,而是保存在输出缓冲区里面

ob_get_contents — 返回输出缓冲区的内容
如果你想以后处理输出的内容,可以调用这个函数保留一个备份

ob_get_length — 返回输出缓冲区的内容长度

ob_end_flush — 结束(发送)输出缓冲区的内容,关闭输出缓冲区

ob_end_clean — 删除(放弃)输出缓冲区的内容,关闭输出缓冲区
如果你的程序发现输出内容有问题,可以放弃所有输出内容,可以防止泄漏某些秘密信息

ob_implicit_flush — 打开或关闭直接刷新
打开后,每个脚本输出都直接发送到浏览器,不再需要调用 flush(),

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What should I do if docker start cannot start? What should I do if docker start cannot start? Oct 21, 2022 pm 03:43 PM

Solution to docker start failure: 1. Check the running status, and then release the occupied memory through the "echo 3 > /proc/sys/vm/drop_caches" command; 2. Use "$netstat -nltp|grep .. ." command to check whether the port has been occupied. If it is found to be occupied after going online, change it to an available port and restart.

What to do if setcookie php fails What to do if setcookie php fails Oct 26, 2022 am 09:07 AM

Solution to the failure of setcookie php: 1. Open the corresponding PHP file; 2. Check whether the domain name parameters are standardized; 3. Implement it through global variables, code such as "foreach ($_COOKIE["cookie"] as $name => $value) {$name = htmlspecialchars($name);$value = htmlspecialchars($value);echo...".

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

What to do if node start reports an error What to do if node start reports an error Dec 29, 2022 pm 01:55 PM

Solution to node start error: 1. Execute "node xx.js" directly in the terminal; 2. Add start startup item "scripts": {"test": "echo \"Error: no test specified\" && exit 1 ","start":"node service.js"}"; 3. Re-execute "npm start".

How to use the setcookie function to set cookies in PHP How to use the setcookie function to set cookies in PHP Jun 26, 2023 pm 12:00 PM

In web development, cookies are a very common technology that allow web applications to store and access data on the client side. In PHP programming, setting cookies is usually implemented using the setcookie function. The syntax of the setcookie function is as follows: boolsetcookie(string$name[,string$value[,int$expire[,string$path[,

How to use the start method and run method in Java thread How to use the start method and run method in Java thread Apr 20, 2023 am 08:58 AM

start method and run method The $start()$ method is used to start a thread. At this time, the thread is in the ready (runnable) state and is not running. Once the $cpu$ time slice is obtained, the $run()$ method starts to be executed. . Directly calling the $run()$ method only calls a method in a class, which is essentially executed in the current thread. Therefore, it can only be achieved by using the $start()$ method to call the $run()$ method. True multithreading. Sample code@Slf4j(topic="c.Test4")publicclassTest4{publicstaticvoidmain(Strin

What does the timestamp of 0 in php setcookie mean? What does the timestamp of 0 in php setcookie mean? Mar 22, 2023 am 10:38 AM

The setcookie() function in PHP is a way to set a cookie to the client browser. It allows the website to recognize the user through cookies on the next visit and provide them with corresponding services. setcookie() has several parameters, including cookie name, value, expiration time, etc. When setting the expiration time, it can be specified by timestamp. However, sometimes we see timestamps being set to 0. What does this mean?

How to start a session using the session_start function in PHP How to start a session using the session_start function in PHP Jun 26, 2023 pm 01:33 PM

The session_start() function is one of the functions that opens a session in PHP. Session is a very common technology in web development, and the basis of session is to assign a unique session ID to the user when he visits the website, and to use this session ID to identify the user in subsequent visits. Sessions can be used to save the user's login status, shopping cart contents, and other user information, and can also be used to implement permission control for some functions on the website. The way to open a session in PHP is very simple, just use sess

See all articles