首页 > 解决方案 > 在循环中重定向到自我页面并处理数据

问题描述

我正在处理来自外部页面的一些数据。页面可以按顺序访问,即http://localhost/info/1.html , http://localhost/info/2.html , http://localhost/info/3.html , ....

<?php
$id = 0;
$id = intval($_GET['id'])+1;
$url = 'http://localhost/info/'.$id.'.html';

if (!$html = @file_get_contents($url)) {
  $url = 'http://localhost/crawler.php?id='.$id;
  //header("Location: ".$url);
  echo '<html><script>window.location.href = "'.$url.'";</script>    </html>';
  die();
}

//process data

$url = 'http://localhost/crawler.php?id='.$id;
//header("Location: ".$url);
echo '<html><script>window.location.href = "'.$url.'";</script></html>';
die();
?>

问题是 PHP 重定向停止显示错误页面未正确重定向,并且使用 JavaScript 重定向看起来更慢。已经尝试使用标头删除回声。

**

有什么方法可以加快这个过程吗?

**

标签: phphttp-headers

解决方案


推荐阅读