Multiple PHP file execution.

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
yempee
Forum Newbie
Posts: 6
Joined: Sat Oct 24, 2009 5:56 am

Multiple PHP file execution.

Post by yempee »

Hi friends....



Am new to php.



I have one parent php file(index.php) and 5 child files [test1.php, test2.php.........test5.php, with some contents each(let say each file may print "Hello world1...Hello world5") ]. I want to run all these child files when i fetch index.php. After all at the end of the execution control should remains in the parent file.



Can any one please help me.....



ThankS in advance.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Multiple PHP file execution.

Post by Mark Baker »

Code: Select all

 
include('test1.php');
include('test2.php');
include('test3.php');
include('test4.php');
include('test5.php');
 
User avatar
yempee
Forum Newbie
Posts: 6
Joined: Sat Oct 24, 2009 5:56 am

Re: Multiple PHP file execution.

Post by yempee »

Thanks the above code works fine...

Now i want to pass some string along with the file...

Let say [ include('test1.php?id=abc') ]

but above code gives error....

Can anyone please update the correct syntax...
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Multiple PHP file execution.

Post by Mark Baker »

You don't need to pass variables to the include
Variables defined in your index.php are already available to the include file.

index.php

Code: Select all

 
$id = 1;
include('file1.php')
include('file2.php')
echo $id.'<br />';
 
file1.php

Code: Select all

 
echo $id.'<br />';
$id += 1;
 
file2.php

Code: Select all

 
echo $id.'<br />';
$id += 1;
 
User avatar
yempee
Forum Newbie
Posts: 6
Joined: Sat Oct 24, 2009 5:56 am

Re: Multiple PHP file execution.

Post by yempee »

I have slight deviation in my requirement...

Each child file should execute independently.

I mean to say i should see septate request for each child execution execution. The original content of the the child files follows

setcookie("name1", Test1, time()+3600, "/","", 0) -> for child test1.php
setcookie("name2", Test2, time()+3600, "/","", 0) -> for child test2.php
setcookie("name3", Test3, time()+3600, "/","", 0) -> for child test3.php
setcookie("name4", Test4, time()+3600, "/","", 0) -> for child test4.php
setcookie("name5", Test5, time()+3600, "/","", 0) -> for child test5.php

So when i execute the index file five cookies should be set from 5 different file.

At the end of the final child execution control should come back to the parent file.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Multiple PHP file execution.

Post by Mark Baker »

Can't be done: not as a completely separate request if you want the included file to interact with the browser (and setting cookies definitely qualifies as interaction with the browser).

But why do they need to be compeletely independent? What are you actually trying to do?

Your example doesn't need to be independent! It doesn't even need separate files, because your cookie setting could all be done from index.php
User avatar
yempee
Forum Newbie
Posts: 6
Joined: Sat Oct 24, 2009 5:56 am

Re: Multiple PHP file execution.

Post by yempee »

I have to prepare some cookie related test page using PHP.

My requirement is like, i need to set 100 cookie of size 2MB form 100 different pages.
But this 100 cookie should be set when i fetch the index page.

[Note:If i see the request using any protocol analyzer i should see 100 separate request. ]

Can anyone plz suggest how to tackle this.

Thanks in advance.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Multiple PHP file execution.

Post by VladSun »

yempee wrote:My requirement is like, i need to set 100 cookie of size 2MB form 100 different pages.
You can't - the usual cookies data size permitted by the browsers per single domain is only 4 Kbyte.
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply