?
Solved

Get remote file content?

Posted on 2004-10-10
4
Medium Priority
?
280 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 1000 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 1000 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 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…
Suggested Courses

777 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