Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何循环浏览页面?_Php_Html - Fatal编程技术网

Php 如何循环浏览页面?

Php 如何循环浏览页面?,php,html,Php,Html,这是我最近面临的一个挑战。我还没有想出最好的办法,也许别人有主意 使用PHP和/或HTML,创建一个页面,以给定的间隔循环浏览任意数量的其他页面 例如,我们将加载这个页面,它将花费我们到谷歌20秒,然后到雅虎10秒,然后到stackoverflow 180秒等等 为内容使用单独的iframe,然后使用Javascript来延迟一段时间,并设置iframe的位置属性。当您被带到另一个站点(例如Google)时,控件会传递到该站点,因此为了让脚本继续运行,您需要在一个框架中加载新站点,并将您的脚本(

这是我最近面临的一个挑战。我还没有想出最好的办法,也许别人有主意

使用PHP和/或HTML,创建一个页面,以给定的间隔循环浏览任意数量的其他页面


例如,我们将加载这个页面,它将花费我们到谷歌20秒,然后到雅虎10秒,然后到stackoverflow 180秒等等

为内容使用单独的iframe,然后使用Javascript来延迟一段时间,并设置iframe的
位置
属性。

当您被带到另一个站点(例如Google)时,控件会传递到该站点,因此为了让脚本继续运行,您需要在一个框架中加载新站点,并将您的脚本(我认为最容易使用Javascript实现)保存在另一个框架中(可以使其变得非常小,这样您就看不见了)。

使用Javascript可以很容易地做到这一点。了解部署环境会有所帮助。它是一个售货亭还是什么的

对于JavaScript解决方案,提供一个包含JavaScript的页面,该页面将弹出一个新的浏览器窗口。控制器页面将使新浏览器窗口在一系列页面之间循环。这是我能想到的最简单的方法


编辑:同意西蒙的评论。此解决方案最适用于信息亭或大型公共显示环境,在这种环境中,页面只是在没有任何用户交互的情况下显示。

取决于您的具体要求。如果您允许使用JavaScript并允许使用框架,那么您可以在页面上的框架集中粘贴一个隐藏的框架,并在其中加载一些JavaScript。然后,该JavaScript将使用window.location对象和setTimeout函数控制主框架的内容

缺点是用户的地址栏不会用新的URL更新。我不确定如果不是这样的话,这将如何实现。如果你能澄清这些限制,我可以提供更多的帮助


编辑-Shad的建议是可能的,但除非用户触发该操作,否则浏览器可能会阻止弹出窗口。同样,您必须澄清是否允许弹出窗口。

创建一个包含IFrame的包装HTML页面,大小为
100%x100%
。然后添加一些javascript,在设置的时间间隔之间更改IFrame的
src

我认为它必须像这样工作,它会吸收其他网站,并在上面显示自己的内容

一旦你在中阅读了另一个站点并准备好显示它,你就不能真正用“PHP”实现它;您必须发送一个HTML重定向元标记:

<meta HTTP-EQUIV="REFRESH" content="15; url=http://www.thepagecycler.com/nextpage.html">


或者您可以使用Javascript而不是meta标记。

这在PHP脚本中是不可行的,除非您想编辑重定向。。。。PHP是一种后端技术;您需要用Javascript或类似的语言来实现这一点


据我所知,您最好在web服务器上创建一个文本文件,并根据该文本文件的超时情况加载不同的HTTP地址,然后将浏览器重定向到该文本文件中的站点。

首先想到的解决方案是在框架集中执行此操作。隐藏其中一个框架,另一个框架显示相关页面。使用Javascript从隐藏帧驱动页面转换

function RefreshFrame()
{
    parent.VisibleFrame.location.href = urlArray[i];
    i++;

    if(i < urlArray.length) SetTimeout("RefreshFrame()", 20000);
}

var i = 0;
var urlArray = ['http://google.com','http://yahoo.com', 'http://www.search.com'];
RefreshFrame();
函数RefreshFrame()
{
parent.VisibleFrame.location.href=urlArray[i];
i++;
if(i
在本例中,Javascript将位于hiddend框架中,您可以将可视框架命名为“VisibleFrame”


免责声明:我只是在评论窗口中编写了这段代码,并没有对其进行测试。请求背后的理论基本上是能够从“kiosk”PC上循环浏览各种系统的网页仪表板。我负责管理一个数据中心,我们有几个监控系统,允许我查看仪表板的温度、系统启动时间等。 想法是加载一个页面,在我指定的时间内,从一个仪表板循环到另一个仪表板,在这个仪表板上停留1分钟,在下一个仪表板上停留30秒,在下一个仪表板上停留2分钟,依此类推。。Javascript是绝对允许的(尽管我对它几乎没有经验)。我选择的媒体是PHP/HTML,我没有看到一种方法可以让这一切简单地发生在它们身上。


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>Dashboard Example</title>
<style type="text/css">
body, html { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; }
iframe { border: none; }
</style>
<script type="text/javascript">
var Dash = {
    nextIndex: 0,

    dashboards: [
        {url: "http://www.google.com", time: 5},
        {url: "http://www.yahoo.com", time: 10},
        {url: "http://www.stackoverflow.com", time: 15}
    ],

    display: function()
    {
        var dashboard = Dash.dashboards[Dash.nextIndex];
        frames["displayArea"].location.href = dashboard.url;
        Dash.nextIndex = (Dash.nextIndex + 1) % Dash.dashboards.length;
        setTimeout(Dash.display, dashboard.time * 1000);
    }
};

window.onload = Dash.display;
</script>
</head>
<body>
<iframe name="displayArea" width="100%" height="100%"></iframe>
</body>
</html>
仪表板示例 正文,html{边距:0;填充:0;宽度:100%;高度:100%;溢出:隐藏;} iframe{border:none;} 变量破折号={ 下一个索引:0, 仪表盘:[ {url:“http://www.google.com“,时间:5}, {url:“http://www.yahoo.com“,时间:10}, {url:“http://www.stackoverflow.com“,时间:15} ], 显示:函数() { var dashboard=Dash.dashboards[Dash.nextIndex]; 框架[“displayArea”].location.href=dashboard.url; Dash.nextIndex=(Dash.nextIndex+1)%Dash.dashboards.length; 设置超时(Dash.display,dashboard.time*1000); } }; window.onload=Dash.display;
我设法创造了这个东西。虽然不漂亮,但确实管用

<?php
# Path the config file, full or relative.
$configfile="config.conf"; 
$tempfile="tmp.html";
# Read the file into an array
$farray=file($configfile);  
# Count array elements
$count=count($farray);  
if(!isset($_GET['s'])){
    $s=0;
}else{  
    $s=$_GET['s'];
if($s==($count-1)){ # -1 because of the offset in starting our loop at 0 instead of 1
    $s=0;
}else{
    $s=$_GET['s']+1; # Increment the counter
}
}
# Get the line from the array
$entry=$farray[$s];
# Break the line on the comma into 2 entries
$arr=explode(",",$entry);       
# Now each line is in 2 pieces - URL and TimeDelay
$url=strtolower($arr[0]);
# Check our url to see if it has an HTTP prepended, if it doesn't, give it one.
$check=strstr($url,"http://"); 
if($check==FALSE){
    $url="http://".$url;
    }           
# Trim unwanted crap from the time
$time=rtrim($arr[1]);               
# Get a handle to the temp file
$tmphandle=fopen($tempfile,"w");
# What does our meta refresh look like?
$meta="<meta http-equiv=\"refresh\" content=\"".$time.";url=index.php?s=".$s."\">\n";
# The iframe to display
$content="<iframe src =\"".$url."\" height=\"100%\" width=\"100%\"></iframe>";
# roll up the meta and content to be written
$str=$meta.$content;
# Write it
fwrite($tmphandle,$str);
# Close the handle
fclose($tmphandle);
# Load the page
die(header("Location:tmp.html"));            
?>

有很多方法可以做到这一点,我用从JS到Ruby的各种工具编写了几个脚本和工具


最后,它更容易使用。它通过一个漂亮的简单GUI为我处理了浏览器重启、内存分配和意外关闭窗口的问题。

有一个小错误——frames[“displayArea”].location.href=dashboard.url;应读取帧[“displayArea”]。location.href=dashboards.url;我已经尝试过上面的代码,它工作得很好-但是一个特定的站点似乎导致整个页面(websitepulse)刷新,所以循环停止。有什么方法可以防止iframe中的站点接管整个浏览器页面?您可以