tags:

views:

50

answers:

3

look here first http://stackoverflow.com/questions/2883338/how-can-i-send-a-date-from-one-site-to-other-sites let me change the question a bit, i didnt really explain myself properly. What i intend to do is get z.php to read a text file called 'sites.txt' which has a list of sites:

site1.com/a.php
site2.com/b.php
site3.com/c.php

to execute the urls in the sites in 'sites.txt' i want it to go through siteA.com/z.php?ip=xxx.xxx.xx.xxx&location=UK (z.php will then read 'sites.txt') All sites in the 'sites.txt' file will be executed as

site1.com/a.php?ip=xxx.xxx.xx.xxx&location=UK
site2.com/b.php?ip=xxx.xxx.xx.xxx&location=UK

I hope that makes more sense, i have tried looking around but couldnt find what i was looking for. Thanks for your help so far everyone. site3.com/c.php?ip=xxx.xxx.xx.xxx&location=UK

+1  A: 

HTTP Requests

Use the cURL library to hit the other sites from z.php.

cURL allows you to issue HTTP requests to another web server from within a PHP script.

IP Address

You can get the client IP address with $_SERVER['REMOTE_ADDR']. If you get the IP address from user input, then you must filter it.

Reading the Text File

Probably the easiest way to read the file is with the file() function, which reads each line into an element of an array. The following line of code strips out the newlines and ignores empty lines.

$lines = file('sites.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

Then you just iterate through the lines and do what you need to do:

foreach($lines as $line) {
  echo $line;
}
Marcus Adams
+2  A: 

Something like this (not tested)?

$handle = fopen("sites.txt", "r");
while (!feof($handle)) {
  $site = fgets($handle);
  $sitestats = fopen(trim($site) . "?ip={$_GET['ip']}&location={$_GET['UK']}", 'r');
}
fclose($handle);

You probably want to validate the GET variables as well

baloo
A: 

you can do this using file_get_contents in combination with the environment variable query string:

<?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);
 }

If you use this in your z.php, you will forward all the incoming get url parameters to your urls.

favo