简体   繁体   English

PHP脚本访问多个网页

[英]php script to access multiple web pages

I need a function/method in php to access multiple web pages in a loop. 我需要php中的函数/方法来循环访问多个网页。 Just as someone can manually access a web page and load any scripts on there. 就像有人可以手动访问网页并在其中加载任何脚本一样。 I'm not downloading any information I just want the script to access it so that any php code can run on that page. 我不下载任何信息,我只希望脚本可以访问它,以便任何php代码都可以在该页面上运行。 It's a hack for a program i'm working on that needs cron jobs running. 这是我正在开发的程序的黑客,需要运行cron作业。 The cron job will run one script that will load multiple pages eg. cron作业将运行一个脚本,该脚本将加载多个页面,例如。 http:// localhost/program/script1, http:// localhost/program/script2. http:// localhost / program / script1,http:// localhost / program / script2。 I can then dynamically add pages from a database as time goes on. 然后,随着时间的推移,我可以从数据库中动态添加页面。

here you would just separate the code you want shared into another file and then use 在这里,您只需将要共享的代码分成另一个文件,然后使用

require("/path/to/filename.php");

The path instead of being a url will be the filesystem path to where you saved the file. 该路径(而不是url)将是保存文件的文件系统路径。

Good starting points to reference this file is $_SERVER["DOCUMENT_ROOT"] so you could say something like. 引用此文件的一个很好的起点是$ _SERVER [“ DOCUMENT_ROOT”],因此您可以这样说。

require($_SERVER["DOCUMENT_ROOT"]."/program/script1.php");

You could scan a directory and loop through each of the files in it then read or write to it with fopen 您可以扫描目录并遍历目录中的每个文件,然后使用fopen对其进行读写

$files = scandir('folder/');
  foreach($files as $file) {
   //do your work here
   $fhandle = fopen($file, 'r');
}

http://www.w3schools.com/php/func_directory_scandir.asp http://www.w3schools.com/php/func_directory_scandir.asp

http://php.net/manual/en/function.fopen.php http://php.net/manual/zh/function.fopen.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM