Page 1 of 2
Calling a php program from another php program
Posted: Wed Jul 03, 2002 1:28 pm
by rvoyek
I'm new to php so this may be a simple question, but I can't seem to figure it out.
I am trying to minimize the number of pages on my web site so I came up with and index.php that has all my includes in it and I also pass to it what page I want included in the body. THis works fime for simple pages, but I have a few other programs that I want to execute from the index.php page. My problem is the other php programs need to execute from their installed directory not form the directory where index.php resides.
eg. code snippet from index.php:
<?
include( "$body" );
?>
now i pass index.php?body=kisgb/index.php this guestbook app won't run becuase it can't find it's files.
What do I need to make this work???
Posted: Wed Jul 03, 2002 3:34 pm
by llimllib
you need to use the local directory for the file you need to include, not the URI for the file. e.g.
if that is where the file is located (relative to index.php).
Re: Calling a php program from another php program
Posted: Wed Jul 03, 2002 3:36 pm
by protokol
rvoyek wrote:
<?
include( "$body" );
?>
now i pass index.php?body=kisgb/index.php this guestbook app won't run becuase it can't find it's files.
What do I need to make this work???
I'm willing to bet that the problem lies in the include("$body");
Try this instead:
include_once "{$_GET['body']}";
Posted: Wed Jul 03, 2002 3:38 pm
by llimllib
oops, misread the Q...my bad, prot is right
Tried it
Posted: Wed Jul 03, 2002 4:04 pm
by rvoyek
I tried it and this is the message i am getting:
Warning: Failed opening '' for inclusion (include_path='') in /home/www/johnstonsoccer/test1.php on line 53
Line 53 is the $_GET line
Posted: Wed Jul 03, 2002 4:17 pm
by llimllib
could you post the line that is giving the error, or is it the line above?
Posted: Wed Jul 03, 2002 4:19 pm
by protokol
also post the url given which is processed
some code
Posted: Wed Jul 03, 2002 5:06 pm
by rvoyek
ok here is the line from test1.php taht is giving me the error message
include_once ( "contentfiles/top-border.inc" );
include_once "{$_GET['$body']}";
include_once ( "contentfiles/top-border.inc" );
Test1.php is the going to be the main page for the web site. To get to the other pages or application I pass an argument through test1.php
example:
http://myweb.com/test1.php?$body=kisgb/index.php
Posted: Wed Jul 03, 2002 5:19 pm
by llimllib
do a
and show us what you get; the $ in the URI might be messing it up
Re: some code
Posted: Wed Jul 03, 2002 5:57 pm
by protokol
$_GET['$body'] is incorrect. The way I typed it was not a typo. The correct statement is:
include_once "{$_GET['
body']}";
Also, don't pass the body var with $body. Use this:
http://myweb.com/test1.php?body=kisgb/index.php
Posted: Thu Jul 04, 2002 1:39 am
by twigletmac
You really don't need all those parenthesis and quotes around include statements:
Code: Select all
include_once 'contentfiles/top-border.inc';
include_once $_GETї'body'];
include_once 'contentfiles/top-border.inc';
Should work fine.
Also you should be sure that the way you are passing the name of the file to include isn't open to abuse, surely giving the full path and filename means that someone could pretty much choose any file to display they want, including one from their own file system with whatever code they want on it...
Mac
Posted: Thu Jul 04, 2002 11:38 am
by hob_goblin
it's probably just because he was doing ?$body ... and if it still doesn't work, he might try $HTTP_GET_VARS incase he is running an old version
Further explanation
Posted: Fri Jul 05, 2002 9:18 am
by rvoyek
I need to give a little more info I think. It looks to me like the application I'm trying to execute is not executing in it's home directory. It llok slike the execution is taking palce where test1.php is located.
Here is the code that's failing and the output form it.
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<body>
<?
print_r($_GET);
include_once $_GET['body'];
?>
</BODY>
</HTML>
Here is the line I'm excuting:
http://myweb/test2.php?body=kisgb/index.php
Array ( [body] => kisgb/index.php )
Fatal error: Failed opening required 'config.php' (include_path='') in /home/www/myweb/kisgb/index.php on line 12
kisgb is located just of the root and test1.php is in the root.
Posted: Fri Jul 05, 2002 9:26 am
by twigletmac
It looks like the execution is taking palce where test1.php is located
That's how include() works, all paths have to be relative to the first file (test1.php) not to the included file (kisgb/index.php).
Mac
Is there a better Way????
Posted: Fri Jul 05, 2002 9:34 am
by rvoyek
Mac,
Is there a way to do what I'm trying to accomplish??
RV