included php file does not work

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
hoangvu.che
Forum Newbie
Posts: 19
Joined: Thu Mar 22, 2007 9:54 pm

included php file does not work

Post by hoangvu.che »

I have two .php files, say a.php and b.php
a.php is included in b.php. When b.php is loaded, I dont know why the php code in a.php is not parsed (run).
When I check the source code in browser, the php code of a.php exists there.

Please help me with this.

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

Post by feyd »

Posting an example of this behavior (the code, not the resultant HTML) would be helpful.

This isn't a theory thread however. Moved to PHP - Code.
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

How is b.php being included (should be include() or require()), and have you checked that b.php is wrapped with PHP tags (<?php and ?>)?
hoangvu.che
Forum Newbie
Posts: 19
Joined: Thu Mar 22, 2007 9:54 pm

Post by hoangvu.che »

I use readfile() function as follows:

Code: Select all

readfile("a.php");
hoangvu.che
Forum Newbie
Posts: 19
Joined: Thu Mar 22, 2007 9:54 pm

Post by hoangvu.che »

aaronhall, thanks for your answer.

I have tried include() instead of readfile() and it runs OK.

regards.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Look into include(), include_once(), require() and require_once(). Each has a place and I am sure they could all be beneficial to you.
Post Reply