Php 向其他站点发送参数

Php 向其他站点发送参数,php,Php,这个问题是相关的。让我稍微改变一下这个问题,我没有正确地解释我自己。我打算让z.php读取一个名为“sites.txt”的文本文件,其中包含一个站点列表: site1.com/a.php site2.com/b.php site3.com/c.php 要在'sites.txt'中执行站点中的URL,我希望它通过siteA.com/z.php?ip=xxx.xxx.xx.xxx&location=UK(z.php将读取'sites.txt')。“sites.txt”文件中的所有站点都将作为 si

这个问题是相关的。让我稍微改变一下这个问题,我没有正确地解释我自己。我打算让z.php读取一个名为“sites.txt”的文本文件,其中包含一个站点列表:

site1.com/a.php
site2.com/b.php
site3.com/c.php
要在'sites.txt'中执行站点中的URL,我希望它通过
siteA.com/z.php?ip=xxx.xxx.xx.xxx&location=UK
(z.php将读取'sites.txt')。“sites.txt”文件中的所有站点都将作为

site1.com/a.php?ip=xxx.xxx.xx.xxx&location=UK
site2.com/b.php?ip=xxx.xxx.xx.xxx&location=UK
我试着四处看看,但找不到我要找的东西

site3.com/c.php?ip=xxx.xxx.xx.xxx&location=UK

HTTP请求

使用该库从z.php访问其他站点

cURL允许您从PHP脚本中向另一个web服务器发出HTTP请求

IP地址

您可以使用
$\u SERVER['REMOTE\u ADDR']
获取客户端IP地址。如果您从用户输入中获取IP地址,则必须对其进行筛选

读取文本文件

读取文件的最简单方法可能是使用
file()
函数,该函数将每一行读取到数组的一个元素中。下面的代码行将删除换行符并忽略空行

$lines = file('sites.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
然后,您只需遍历这些行并执行您需要执行的操作:

foreach($lines as $line) {
  echo $line;
}
像这样的东西(未经测试)


您可能还想验证GET变量

您可以使用file\u GET\u内容和环境变量查询字符串来执行此操作:

<?php
 // read your site urls into an array, each line as an array element
 $sites = file('sites.txt');

 // walk thru all sites, one at a time
 foreach ($sites as $site) {
   // combine your incoming query string (?ip=...&location=...) with your site, by appending it to $site
   $site .= '?' . getenv('QUERY_STRING');

   // prepend $site with http:// if it is not in your text file
   if ( substr($site, 0, 4) != 'http' ) {
     $site = 'http://' . $site;
   }

   // open the url in $site
   $return = file_get_contents ($site);
 }

<?php
 // read your site urls into an array, each line as an array element
 $sites = file('sites.txt');

 // walk thru all sites, one at a time
 foreach ($sites as $site) {
   // combine your incoming query string (?ip=...&location=...) with your site, by appending it to $site
   $site .= '?' . getenv('QUERY_STRING');

   // prepend $site with http:// if it is not in your text file
   if ( substr($site, 0, 4) != 'http' ) {
     $site = 'http://' . $site;
   }

   // open the url in $site
   $return = file_get_contents ($site);
 }