Page 1 of 1

include question

Posted: Tue Mar 09, 2004 1:54 pm
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 ...

Posted: Tue Mar 09, 2004 1:56 pm
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;

ah ha !

Posted: Tue Mar 09, 2004 2:01 pm
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

Posted: Tue Mar 09, 2004 2:19 pm
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.

Curious

Posted: Tue Mar 09, 2004 5:16 pm
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....