Solved

Get remote file content?

Posted on 2004-10-10
4
276 Views
Last Modified: 2010-08-05
I have a file called version.php on my remote webservers and inside that file i have:
<?PHP
$Version = '1.9.1';
?>


I want to code a page that will remotely connect to the webservers and check what version that version.php file is running then echo the results of each webserver. How can I do that?


Brad

0
Comment
Question by:Brad_nelson1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 250 total points
ID: 12274122
version.php:
<?php
$version = '1.9.1';
echo $version;
?>

getallversions.php
<?php
$urls = array(
  'http://www.example.com/1/version.php',
  'http://www2.example.com/1/version.php',
  'http://www.3example.com/1/version.php',
);

foreach ($urls as $url) {
    echo "$url is running version " . file_get_contents($url) . "</br>\n";
}

Call the getallversion to get an overview of which sites are using which version. In the array $urls enter the urls where those installations can be found.
0
 
LVL 1

Assisted Solution

by:gportal
gportal earned 250 total points
ID: 12351875
The above would work if you modify the version.php file.  If you are unable to do so, you may need to consider the more long winded approach to get the file itself, via FTP.

<?php

// open file for writing
$file = '/tmp/tempverfile.php';
$fp = fopen($file, 'w');

// set up basic connection
$conn_id = ftp_connect($ftp_server);  //$ftp_server = "ftp.yourserver.com" etc.

// login with username and password
ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// try to download $file (i.e. $file = "/public_html/version.php";)
ftp_fget($conn_id, $fp, $file, FTP_ASCII, 1);

// close the connection and the file handler
ftp_close($conn_id);
fclose($fp);

include ($file);
echo $version;
unlink ($file);
?>

You'll want to add your own error checking (i.e. if file is not downloaded, or if server is down) and most likely create the tempvarfile.php in a more secure area than just /tmp/, as well as randomly generating the filename and checking that it doesn't exist (if you are running multiple instances of the script.)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question