include question

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
dessied
Forum Newbie
Posts: 3
Joined: Tue Mar 09, 2004 1:54 pm

include question

Post by dessied »

Hi..

Im a newbie to PHP and am having trouble with the include statement.

Is it possible to use include to echo/print html back to the browser from within a php page ?

i.e.

the php page calls include 'somefile.php?arg=1'

the somefile.php then uses GET to get the arg and passes back a different table depending on the value. If i call directly from the browser the file works ok, but if i use include from within a php page nothing is returned.

any help appreciated ...
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

includes inherit the vars from the file that did the including, ie you don't need to pass ?arg=1 in the include call.

You can just do something like:
$arg = 1;
include 'somefile.php';

and somefile has access to $arg as normal, eg somefile.php can just do echo $arg;
dessied
Forum Newbie
Posts: 3
Joined: Tue Mar 09, 2004 1:54 pm

ah ha !

Post by dessied »

Jeez thanks Mark

Your reply was quicker than my php code !

Another thing i was doing wrong though was not using the full server path to the file - i just used 'somefile.php. Read the php documentation on include and saw that was missing too.

I'll use your tip on pre-setting the variable though

Thanks again
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

There is reasons you might want to use the other method, but both are fine in my eye.

I do prefer the second though. I have only used the first method once, ever.
dessied
Forum Newbie
Posts: 3
Joined: Tue Mar 09, 2004 1:54 pm

Curious

Post by dessied »

Thanks Sami

Whats bad about the first method ? Presumably security ? Just curious as php is new to me, damn good but still new....
Post Reply