execute an external script within a script

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
ansa
Forum Commoner
Posts: 31
Joined: Tue Aug 29, 2006 1:58 am
Location: Hamburg, Germany

execute an external script within a script

Post by ansa »

Hi,

I have a script, let's say myscript.php.

In myscript.php, I want to execute an external script with its parameters, let's say:

http://www.otherserver.com/external.php?var1=a&var2=b

I have tried include() and exec() for this, but didn't work.

Is there a way to do this? Thanks for any hint!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Re: execute an external script within a script

Post by volka »

ansa wrote:I have tried include() and exec() for this, but didn't work.
If it didn't work you probably got an error message. If not try again with

Code: Select all

error_reporting(E_ALL);
ini_set('display_errors', true);
at the beginning of your php script.
ansa
Forum Commoner
Posts: 31
Joined: Tue Aug 29, 2006 1:58 am
Location: Hamburg, Germany

Post by ansa »

Which function should work with this, include() or exec()?

With exec(), I don't get any error message. The page acts as if nothing happened. With include(), I also don't get any error message. The script in the link just does not work the way I want it. Because this is an external link, I can not do any debugging.

But if I copy the link (http://www.otherserver.com/external.php?var1=a&var2=b) onto the browser and run it, it works just fine.

Wondering why...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Including a file from a remote site is highly dangerous. file_get_contents() or fsockopen(), et al should work depending on your server's settings.
Post Reply