Web Hosting Talk







View Full Version : Including remote files


UrlGuy
04-05-2005, 08:26 AM
Hi!

I use this script to query my gameservers to show players ingame etc. And now I want to use this same script on different domains/servers, but this script resides on the server the the game are being played from.

I want to show only playernumber on my page, like;
Playing: 22
or something, and always display the correct playernumber.

But I havent found out how to do this.. as it doesnt seem to be included somehow..

If I include it on the localserver everything goes o.k., but when I try to include it from my other server it just turns out blank.

I have tried

<?
include ("http://www.domain.com/file/to/be/included/file.php");
?>

But this only gives me a blank page.. not the results its meant to be.. =|

Is it impossible to do this, or..?
Any suggestions?

UH-Matt
04-05-2005, 08:30 AM
The remote server your including the file from should have safemode off, this may help?

EXOWorks
04-05-2005, 08:52 AM
It looks like he is including the parsed version of a php file (.php). What are you trying to do? Read the html from the remote file or trying to include the source of the remote file?

Use readfile() ..

UrlGuy
04-05-2005, 11:09 AM
I dont have root on that server and cant access php.ini on it =|

All I want to do is.. example:

<?
$sayhi="hello";
?>


I want to do <? include("http://domain.com/file.php"); ?>

And where I include it, lets say on top of the page, I want it to say "hello". Not only the html, nor the php source, just the output :\

UrlGuy
04-05-2005, 11:19 AM
So I have the file that output "hello" on one server, and want to output it on another using include (if possible)

error404
04-05-2005, 02:34 PM
Rather than including the file directly, you should write a simple remote script to pull the information you want and either serialize it or write it in an easily parsable format to the web page. Then get the file and parse it on the local script and output whatever you need.

including remote files is a huge security risk, makes updating the page layout or whatever a huge pain, and is (should) be disabled by most hosts. IMO include() should never have even had support for remote file including.

Omega-Mark
04-05-2005, 02:43 PM
are you trying to have the MOTD file on a gameserver include a PHP file showing the status using a php include?

if so then this is not possible unless you have php and apache etc.. installed and have the gameserver dir as a webhosting account..

mfonda
04-05-2005, 02:59 PM
If you are trying to include a PHP file on another server, and the file is saved as .php, the remote server will parse the PHP before sending it to you, so will will get the end result of the PHP script, not the PHP code itself.

For examlpe,

include.php on http://www.example.com
<?php
$test = 'Hello World';
echo $test;
?>

test.php on your server:
<?php

//Result of this will be 'Hello World'
include 'http://www.example.com/include.php';

//will cause warning, because $test is not defined
echo $test;
?>

UrlGuy
04-05-2005, 03:57 PM
But even if I just put this in test.php:
<?
include 'http://example.com/include.php';
?>


It gives me the following errors:

Warning: main(http://64.69.34.130/files/game1.php): failed to open stream: Connection timed out in /home/ownt/public_html/php.php on line 2

Warning: main(): Failed opening 'http://64.69.34.130/files/game1.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/ownt/public_html/php.php on line 2.

Neither do I want to redefine it, as long as its defined in test.php, shouldnt that be enough? :S

UrlGuy
04-06-2005, 12:14 PM
impossible? :\

mouldy_punk
04-06-2005, 12:23 PM
I'd say it's either extremely difficult to do, or impossible.

Think of the damage you could do by including across server, eg, everyone knows PHP Nuke sites have a config.php file, lets include it from elsewhere and echo $db_password (or what ever the variable name is) I would doubt very much that cross server includes can be done, simply because of security reasons.

mfonda
04-06-2005, 04:47 PM
you have to set an ini directive to allow remote includes, read the manual page about it.

UrlGuy
04-06-2005, 05:50 PM
Okay.. thx for response.

But isnt there any way I could just show the output of the file?
And let all the echoing and stuff be there.. I just need the output :|

Omega-Mark
04-06-2005, 05:53 PM
iframe perhaps

UrlGuy
04-06-2005, 06:13 PM
I dont know what iframe is or how to use it :(
*looking it up*

yet again.. thx for all your replies ppl!

insanelymacintosh
04-06-2005, 09:08 PM
I just tried to do a test to see what would pull up if I did the following:

<?
include ("http://www.google.com");
?>

and it showed the google home page. Try this test to see what shows up for you. If it shows a blank page for this example then maybe your host has turned it off completely.

UrlGuy
04-07-2005, 01:16 AM
Ok, thanks..

It actually seemed to work now..

I included my file, as you shown above with google.com as example, and it gave me the right output.

But when I am to implement this into my html with <? include("http://domain.com/file.php"); ?> in the middle of my html, it just shows nothing.. No output shows :S

Anyone got any idea why this is happening and not showing me the output I want? It just shows nothing where the included file should be.. just nothing.. And I am sure the server supports it as the google example worked fine, aswell as the script I am trying to include worked aswell when I made a standalone file named include.php and put <? include("http://domain.com/file.php"); ?> and made that just 1 file which I clicked.. it showed me the right output.. But when I implement this into my html it showd nothing :S ?

Anyone got any idea why this is happening?

Hope anyone got a solution for this! =)

error404
04-07-2005, 01:41 AM
Why not do the much more security-sane and more-likely-to-work

<?php

readfile("http://www.foo.com/foo.php");

?>


No remote code execution, and probably much more available. I don't understand why people insist on using 'include' for everything.

UrlGuy
04-07-2005, 02:15 AM
thx for reply agains.


But this is still showing me the empty white-space

I have now tried both include() and readfile(), tho include seemed to work, when I implement this into my html it just doesnt give any output.



Heres a short part of the html I put my PHP into:




<p>
<table border="0" cellpadding="0" cellspacing="0" width="150">
<tr>
<td width="100%" background="images/bar_bg2.gif"><img border="0" src="images/index.1.gif" width="150" height="24">
<div style="margin-left:10px; margin-right:10px">
<span lang="no-bok">&nbsp; <b>F&nbsp; E&nbsp; A&nbsp; T&nbsp;
U&nbsp; R&nbsp; I&nbsp; N&nbsp; G</b></span><p>
<span lang="no-bok"><b>&nbsp;
<?php
readfile("http://xxx.xx.xx.xxx/files/query.php");
?>
</b></span></p>
<hr>
<p>
<span lang="no-bok"><b>WebMail</b></span></p>
<p>



And on the left side of the page, where the file is included, its supposed to output a number, or if it doesnt work, say N/A. It just doesnt show anything at all.. just blank space there...


But when I for example make a file named "file.php" and put this inside: <?php include("http://domain.com/file.php"); ?> it works, and shows output, when I view that single file. But when I put this include or readfile inside my html.... nothing shows where its supposed to show a number :|

Anyone know what I might be doing wrong? :?

UrlGuy
04-07-2005, 02:57 AM
So when I make one single file with only the include function, and run it.. it shows me the right output.

But if I include this in my html, as shown above, this doesnt show me anything but a blank page :S

mfonda
04-07-2005, 02:07 PM
If it isnt showing anything, that probably means there is nothing in the file.

UrlGuy
04-07-2005, 03:19 PM
There is.

What I want to do is, I have found this script for querying my gameserver, which shows me the current number of players, which are currently playing in my server. I'm making, on a menu on the left of my webpage, where people can view how many playing, from my webpage. For this, I have to implement a short include line into my index.html. But when I try include this line <? include("http://domain.com/file.php"); >? in the middle of the html in index.html, it doesnt show me the output, not even a error as it would if it didnt work. But if I put that single line in a new file, save it and upload I can view it, but not after I have implemented it into my html. :S

When I make a .php file, and ONLY put <?php include("http://domain.com/file.php"); ?>

And save that php file with only that single line in it, and when I view it (ex from; http://domain.com/file.php), it shows me the right content.

But when I do this inclusion within my html as shown above (from ex; http://domain.com/index.html), it just gives me white-space =|

Sheps
04-07-2005, 03:45 PM
You need to create a "remote.php" and have it do everything you need it to do before the remote server includes the file...

stormraven
04-07-2005, 04:14 PM
I could be totally reading this wrong.. but I'm going to answer anyway.

If your local file is named index.html, chances are that your local server isn't using the PHP processor to process that file. In other words, you're not invoking PHP on your local machine at all!

I'll bet if you renamed index.html to index.php (or used some trick to make the web server use the PHP processor on HTML files) it'd work.

UrlGuy
04-07-2005, 04:25 PM
How would I make that remote.php? And would I be able to implement that in the html? And I have not renamed it to .php, its still html file, all code inside are html and when I need php in it I put it within php tags

mouldy_punk
04-07-2005, 04:52 PM
Couldn't you do an Iframe instead of a php inclusion, eg,

<iframe src="http://www.thedomain.com/thefile.php" width="whatever" height="whatever"></iframe>

UrlGuy
04-07-2005, 05:56 PM
Dont want it in a iframe :|

UrlGuy
04-07-2005, 11:20 PM
Dont want it in a iframe =|

stormraven
04-08-2005, 12:23 AM
By putting the <?php include(); ?> code inside your index.HTML file, you're effectively changing it from HTML to PHP. Thus, it needs to be parsed by the PHP engine to work.

In other words, you either need to rename the file with a .PHP extension - or use some .htaccess tricks to make the PHP engine read HTML files as well as PHP files.

UrlGuy
04-08-2005, 01:25 AM
sounds hard.. =\

insanelymacintosh
04-08-2005, 02:08 AM
It looks like people keep saying that you need to rename the file from .html to .php. Is the file that uses the PHP include satement an HTML file or php? Because you said that it will work if you ONLY have the PHP incude, then I take it that it is named something like something.php am I right?

UrlGuy
04-08-2005, 02:52 AM
Its named Index.html.

All code thats inside it are currently html, some tables, pictures and so. All I need is, on the left side of my page, I want a small file included, ,which shows a number.

Im querying my gameservers, and want to show players currentply playing from my webpage.

I found an other webpage which do this, and it seems to work, > http://www.strangelovejunky.com

:S

stormraven
04-08-2005, 08:27 AM
If you still can't figure this out, send me a PM and I'll give you a hand.

insanelymacintosh
04-08-2005, 08:38 AM
In order to use php in index page you have to rename it index.php. Once you do that you can have html and php in the same file.

UrlGuy
04-08-2005, 11:42 PM
I thought it was possible having PHP in HTML files only by having it within PHP tag =|
Atleast I do this in my form when its posted to itself with <?php echo $PHP_SELF ?>
I dont know why there should be a difference and it dont work with my index.html :S

stormraven
04-10-2005, 06:38 PM
The *only* way it would be possible to have PHP code *WORK* inside your .html files is to have them read by the PHP engine. The web server can be configured to send .html pages to the PHP engine; there were some threads on doing so in this forum not too long ago.

In short, you *MUST* either configure your web server to send .html pages to the PHP engine, or rename the file that has php code in it to a .php extension. There is no other way around it.

UrlGuy
04-10-2005, 08:44 PM
dam that sucks :\

Dont have access to php.in as this are on a reseller, and if I rename it to .php it looks all different with menus spread wildly over the page looking all ruined :\

O'well.. =|