Solved

Get remote file content?

Posted on 2004-10-10
4
228 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
4 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 250 total points
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

762 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now