dsieyx2015 2016-02-19 19:07
浏览 53

PHP加载page1,睡5秒,加载第2页

I need to do something that in theory sounds very easy but i've been running into alot of issues to get it done correctly.

There's a layer of complexity added because i'm running a custom frauddetection script but that shouldn't have any impact on this.

Basically, I need my PHP code to do the following

-Load Page 1 (through Include() so the URL doesn't change) -Show that page for 5 seconds -Stop showing Page 1, and instead show Page 2 (using an Include() again so the URl stays the same)

Any ideas?

Closest i've gotten is this:

<?php
ob_start();
include ("1b.html");
ob_clean();
sleep(5);
include ("1c.html");

 ?>

But it just displays nothing for 5 seconds, as if the page is still loading, and then just shows 1c without ever showing 1b for 5 seconds.

</div>
  • 写回答

2条回答 默认 最新

  • douba6361 2016-02-19 19:21
    关注

    This is impossible. This is not at all how PHP works. You can't send a blob of data to the user, and then redact it and send a new blob of data to the client. Output buffering cannot be used in this way.

    But it just displays nothing for 5 seconds, as if the page is still loading,

    That's because the page is still loading. You're in the middle of an HTTP request, and you told PHP to sleep for 5 seconds.


    To make this work, you need to send both parts to the client, and in JavaScript, programatically hide the first part and show the second after 5 seconds

    Or

    Send the first part to the user, and (either through a meta refresh or JavaScript) reload the page after 5 seconds and use some signal such as a query string parameter to session state to serve up the second page of content to the user.

    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程