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.phpto 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.
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 2 of 2 people found this answer helpful. Did you? Yes No
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 2 of 2 people found this answer helpful. Did you? Yes No THANKSSSS, This has solved my problem. Cheers. :)
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.phpto 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 1 of 1 people found this answer helpful. Did you? Yes No
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 :
Posted: is_set 0 of 0 people found this answer helpful. Did you? Yes No 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
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 2 of 2 people found this answer helpful. Did you? Yes No
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¶mb=valueb You can then grab these from $_GET in a.php and b.php Is this what you are trying to do? Posted: MacOS 2 of 2 people found this answer helpful. Did you? Yes No |
© Advanced Web Core. All rights reserved