Calling a php program from another php program
Moderator: General Moderators
Calling a php program from another php program
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???
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???
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).
Code: Select all
include 'kisgb/index.php'- protokol
- Forum Contributor
- Posts: 353
- Joined: Fri Jun 21, 2002 7:00 pm
- Location: Cleveland, OH
- Contact:
Re: Calling a php program from another php program
I'm willing to bet that the problem lies in the include("$body");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???
Try this instead:
include_once "{$_GET['body']}";
some code
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
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
do a and show us what you get; the $ in the URI might be messing it up
Code: Select all
print_r($_GET);- protokol
- Forum Contributor
- Posts: 353
- Joined: Fri Jun 21, 2002 7:00 pm
- Location: Cleveland, OH
- Contact:
Re: some code
$_GET['$body'] is incorrect. The way I typed it was not a typo. The correct statement is:rvoyek wrote: include_once ( "contentfiles/top-border.inc" );
include_once "{$_GET['$body']}";
include_once ( "contentfiles/top-border.inc" );
example: http://myweb.com/test1.php?$body=kisgb/index.php
include_once "{$_GET['body']}";
Also, don't pass the body var with $body. Use this:
http://myweb.com/test1.php?body=kisgb/index.php
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
You really don't need all those parenthesis and quotes around include statements:
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
Code: Select all
include_once 'contentfiles/top-border.inc';
include_once $_GETї'body'];
include_once 'contentfiles/top-border.inc';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
Last edited by twigletmac on Fri Jul 05, 2002 1:36 am, edited 2 times in total.
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
Further explanation
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.
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.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Is there a better Way????
Mac,
Is there a way to do what I'm trying to accomplish??
RV
Is there a way to do what I'm trying to accomplish??
RV