Solved

Get remote file content?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Keep getting 503 on Curl request 6 33
Store image url and display it for user profile 6 23
Site hacked - decoding the PHP? 15 72
Session timeout 5 15
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

863 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

22 Experts available now in Live!

Get 1:1 Help Now