Have an account? Sign in
Login  Register  Facebook
Sending parameters to other sites (B & C) from site A?
Hi,
Im not much of a php coder, mainly use VB. But i had a problem with one of my apps. To make it more secure i would need each php parameter to go through one site. Here is an example of what i mean:

- Application loads
- sends ip and location to 2 servers (a.php & b.php)
the problem so far is that the pc is making direct connections to these pages. What i was trying to do is make it so that it only sends one command to z.php and the page z.php would send the data to a.php and b.php.

My question is how would i set up z.php?

I hope i make sense, i have looked everywhere and couldnt find an answer.

Thanks

EDIT:

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
site3.com/c.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.
Started: September 16, 2011 Latest Activity: September 16, 2011 php
6 Answers
you can do this using file_get_contents in combination with the environment variable query string:
 // 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.

Posted: xtremex
In: September 16, 2011

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 or
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.

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.

Posted: MacOS
In: September 16, 2011

THANKSSSS, This has solved my problem. Cheers. :)
September 16, 2011

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
site3.com/c.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.

Posted: ashking
In: September 16, 2011

You'll have to write your z.php file to perform connection to a.php and b.php. You can retreive IP and location though $GET variable, an example would be :
  • You call z.php?ip=xxx.xxx.xxx.xxx&location=yyyy
  • z.php makes an HTTP request (you can use cURL for that)
  • z.php waits for the response and send it back to your original script.

Posted: is_set
In: September 16, 2011

yes thats basically what i wan, but how could i do it so it would read a.php and b.php from a text file (one site per line) ? would that be possible
September 16, 2011

This cab be achieve using cURL function in PHP...see the below references..
http://php.net/manual/en/book.curl.php
http://www.askapache.com/htaccess/sending-post-form-data-with-php-curl.html

Posted: xtremex
In: September 16, 2011

You can have z.php make a GET request to a.php and b.php, passing the required parameters in the querystring.

i.e. a.php?parama=valuea&paramb=valueb

You can then grab these from $_GET in a.php and b.php

Is this what you are trying to do?

Posted: MacOS
In: September 16, 2011

Your Answer

xDo you want to answer this question? Please login or create an account to post your answer