Include from another site

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

Include from another site

Post by Calimero »

Hi,


I have a problem, looked at the manual - but didn't get answers.


If the script that includes second script in on the site:

http://www.somedomain.com/first.php

and I want to include a php script located on another site:

http://www.otherdomain.com/second.php


and those sites are on different machines (not local area but internet connection)


Is this possible in PHP ???


I tried, but something didn't quite work.


Thanks Ahead !
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

lets think about this, if you could include a file from another webserver on your page you would be able to see their source, passwords......

for security you are not allowed to do what your trying to do

maybe have them copy the source of the file, and put it in a txt file then you would be able to include it
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

if you include http://example/script.php you are including the parsed output of that script

i think you want to include http://example/script.phps
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

wow i forgot about the phpsource file...... handy to have around

maybe you could have a script that everyonce in a while will automatically update the foo.phps file you want to include so that you have updated info
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

...

Post by Calimero »

What's the difference between script.php and script.phps

Will this way work for my idea ?!?!
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

phps is just a common server config that people use

if there exists a file named script.phps on the server, then it will be output the script as plain text, w/out parsing/executing the script.
basically, it will show the source. its just handy.

to simplify things, so you dont need to add config options to your other server,
just save the file as script.txt

then run your
include('http://foo.com/script.txt');

but be warned, this is NOT a good idea. if the other server is unreachable, your website will hang. it will also be very slow.
and, doing remote includes is just generally a very bad idea security wise. and also, now anyone can goto http://foo.com/script.txt
and see your source code, and any passwords etc inside of it.


what is your reason for wanting to do this? there likely exists a much better solution to your problem.
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

...

Post by Calimero »

This file will contain IF, ELSE, ELSEIF structure - based on the page that includes it - it will output different URL's (that are later used for choosing the advertisement on the page).

So basicaly, I don't need much security (no such data will be in it), but I need it to function because I have several machines for my search engine site, and different types of searches are on different machines - and the scripts are makin localhost queries, and those scripts must call the advertisements.

The idea was to be fast for the user, and easy for me to administer (I didn't wan't to use the DB - for T.S. reasons :))

So... what do you suggest?
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

you mean you want to use more than 1 server to do multiple queries at the same time to make it faster?


is your app really that intensive to where it needs to spread the load like this?

theres a lot of very large websites that do not need to spread the load in this mannor, maybe look into refining your sql queries.
sometimes you can make enourmous improvements.

no matter what though. even if you do need this, i dont think include() is the right answer.

theres other ways to do this. some may take more effort, but its your call.


take a look at fsockopen()
and file_get_contents()

using one of those you could retrieve a response from one of the servers, then parse it, and act upon the results. all without actually inclduing it.,
Post Reply