execute a .php script from other php 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
denisw
Forum Newbie
Posts: 14
Joined: Mon Jul 24, 2006 11:21 pm

execute a .php script from other php script

Post by denisw »

Hi All,

Is it viable to run a particular php script (e.g : a.php) from inside other php script (e.g : b.php) ?

pls advise.

Thanks.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

of course it is :wink:

include(), require()
denisw
Forum Newbie
Posts: 14
Joined: Mon Jul 24, 2006 11:21 pm

Post by denisw »

Hi Jcart,

thanks for your reply.

However, in my case I would need more control in executing the other script.

I will elaborate with simple pseudo code as follows :

if (condition a) run foo.php;
elseif (condition b) run bar.php;


thanks.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Whats your question? You can control the flow of your program using if() and else() and include() to appropriate file
denisw
Forum Newbie
Posts: 14
Joined: Mon Jul 24, 2006 11:21 pm

Post by denisw »

Oops, I thought that include() & require() can only be specified at the beginning of the script...

Ok, so the following codes shoud work for my case. Please advise :

if (condition a) include("a.php");
elseif (condition b) include("b.php");

thanks.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Have you tried it?
denisw
Forum Newbie
Posts: 14
Joined: Mon Jul 24, 2006 11:21 pm

Post by denisw »

Yes, I have tried and it works !

thanks.
Post Reply