Exclude URL in file_get_contents

Hi,

I have 2 domain

http://foammachines.net/ - main site
http://foamcuttingwire.net/

I use file_get_contents to have the same content from foammachines.net and it work.

The problem is when I tried to echo the servername of foamcuttingwire.net the output is foammachines.net.

it should display the server name that you visit not the servername you get the contents

is there a way to exclude the URL in getting the contents.

code inside foamcuttingwire.net

echo file_get_contents('http://foammachines.net/');

code inside foammachines.net

<h1>MAIN SITE</h1>

<?php

echo  $_SERVER['SERVER_NAME'];

?>

I sorry if my explanation is not clear.

Hi @gerryl and welcome to the forum.

Please post the PHP script that is not working.

To ensure the PHP script is correctly formatted, please enclose the script between three back-ticks starting and finishing on a new line or use </>

Both URLs supplied are 403 Forbidden?

I updated the post sir and its working now…

I have just tried this on my localhost:

$src = file_get_contents('http://foammachines.net/');
echo '<iframe src="' .$src .'" style="width:88%; margin:auto">';
echo '</iframe>';

Warning: file_get_contents(http://foammachines.net/): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden
in /_FILENAME/ on line 5

As mentioned before both URLs supplied are not accessible.

its working sir

If you are wanting to pull unevaluated code from one site to be evaluated on the other you could give the remote file a txt extension, then eval it on the calling site
* be forewarned and aware, using eval is not a good idea
http://php.net/manual/en/function.eval.php

Caution
The eval() language construct is very dangerous because it allows execution of arbitrary PHP code. Its use thus is discouraged. If you have carefully verified that there is no other option than to use this construct, pay special attention not to pass any user provided data into it without properly validating it beforehand.

callee.txt

echo  $_SERVER['SERVER_NAME'];

caller.php

<?php
eval(file_get_contents('http://example.com/callee.txt'));
?>

No problem either way, links to output is of little to no help with PHP code.

The reason that is working is because echo $_SERVER['SERVER_NAME']; is calling a file which is located on the same site.

Try clicking both links in your original post. Maybe it is just my browser but both links cannot be displayed.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.