Solved

Get remote file content?

Posted on 2004-10-10
4
265 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

733 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