session_write_close() 用法
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了session_write_close() 用法,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1786字,纯文字阅读大概需要3分钟。
内容图文
![session_write_close() 用法](/upload/InfoBanner/zyjiaocheng/1242/df76244e8ab34566bc3f0cfa07541032.jpg)
1.需要session控制的大文件下载,防止因为占用session文件时间太久,导致其他页面的session无法执行
session_write_close() worked as a lifesaver for me when automatically uploading files to a user (forcing a download instead of a link). If files are large, and since session_start() does not allow another page using session_start() to proceed until it‘s done, i was not able to upload more than one file at a time. By using session_write_close() before beginning the file upload, my users can now download as many big files as they like, at the same time. Example:
<?
session_start();
/* Do session stuff here; security; logging; etc. */
session_write_close();
/* NOW write out the requested file. */
header("Content-type: audio/x-mpeg"); /* or whatever type */
header("Content-Disposition: attachment; filename=" . $filename);
header("Content-Length: " . $filesize);
header("Content-Transfer-Encoding: binary\n\n");
header("Pragma: no-cache");
header("Expires: 0");
$file_contents = file_get_contents($filepath);
print($file_contents);
?>
2.保存当前的session变化,防止由于header页面跳转导致修改的session内容没有保存,被丢失
This
function is essencial when you change $_SESSION[] variables and then,
at some poit in the middle of the script, you send an header("Location: )
function to the browser, because in this case the session variables may
not be saved before the browser change to the new page.
To prevent
from lossing session data, allways use session_write_close before this
header function. session_write_close will force session data to be saved
before the browser change to the new page.
Hope this will help you
not to loose 1 day wondering why people could not authenticate or make
other changes in session vars in your site.
原文:http://www.cnblogs.com/jking10/p/3821066.html
内容总结
以上是互联网集市为您收集整理的session_write_close() 用法全部内容,希望文章能够帮你解决session_write_close() 用法所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。