Tom Miller
Tom Miller

Reputation: 1

Remotely include directories with PHP

I've done some research on an issue I'm having with taking a remote directory from Server A and linking that directory to Server B. I'm not fully sure if I can take the remote directory using PHP and use the contents from that directory on Server B

Here's what is what I want to go one between both servers

Server A (code.php)

<?php

  $FileTitle = '/code/';

  if (!isset($_GET['file'])) {
    exit('This file cannot be found');
  }

  $FileTitle = $_GET['file'];

?>

What I have going on with this script is that every time a person enters in a url ending with /code.php?=testfile.txt or any other file in the directory /code/ on Server A will be echoed using <?php echo $FileTitle; ?>. My problem with this is that I host all the files on Server A rather on Server B. I want the title of the file from the URL to show up in index.php on Server B

Server B (index.php)

<?php
include 'http://example.com/code.php';
?>

<?php echo $FileTitle; ?>

I'm planning for this to take the code from Server A and be able to find the directory /code/ on that server as well.

I've done a ton a research the past few days both on Stackoverflow and around the internet. I haven't found anything even close to what I am trying to do. If you can, please show me how to do this. I would really appreciate figuring out how to have a remote connection to a file on another server and be able to use that file remotely. Thanks :)

Upvotes: 0

Views: 130

Answers (1)

James L.
James L.

Reputation: 4097

code.php will execute on the remote server so you will get the output of code.php if any. The only thing I can think of is writing a script that outputs code.php..

Ex: server b, index.php

<?php
eval(str_replace(array('<?php', '?>'), '', file_get_contents('http://example.com/sendcode.php)));
?>

server a, sendcode.php

<?php
$code = file_get_contents('code.php');
echo $code;
?>

Completely insecure, but it works.

Edited: try new server b code. If that doesn't work I'm out of ideas.

Upvotes: 1

Related Questions