Forum Moderators: coopster

Message Too Old, No Replies

Passing arguments to included php script

PHP isn't meant to be confined to cgi-bin, but it is on my system

         

raimondious

6:55 pm on Aug 17, 2005 (gmt 0)

10+ Year Member



I am working on a server that does not allow PHP to be embedded into documents unless they are in the cgi-bin directory. This is annoying but I've been working around it with wrapper pages in other directories that contain only
<!--include virtual="/cgi-bin/relevant_script.php" -->
.

One of my scripts is more difficult to work with because it is a collection of links, each of which points to the same script with different arguments.

It is not acceptable to my boss to go to a URL like mysite.com/sub/script1.html (which just includes a script in cgi-bin) and have that link to mysite.com/cgi-bin/script2.php?arg1=blah . I want to have the script included in script1.html to link to another wrapper page that takes arguments (script2.html?arg1=blah) and have the included script take those arguments... Does anyone think this is possible or have a suggestion to do something like this?
Thanks, Ray

mcibor

8:07 pm on Aug 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't know about cgi, but the php compiler passes the variables to includes:

cgi-bin/include.php:

<?php echo "This is blah: ".$blah;?>

main.php:

<!DOCTYPE...
<html...
<body>
<p><?php
$blah = "Variable blah passed successfully to include";
include("cgi-bin/include.php");
?></p>
</body></html>

Do you have a php parser installed? Because the include you wrote doesn't look like php include, only cgi
Hope this post will help you to include php files normally
Best regards
Michal Cibor

raimondious

8:35 pm on Aug 17, 2005 (gmt 0)

10+ Year Member



Thank you for your reply.

The problem is that the pages that are to be viewed by the public are not in my cgi-bin directory. The server is set up (beyond my control) to only parse php in the cgi-bin directory. Therefore, to be able to display the output of any php scripts in the public directory, I have to use a cgi-style server-side include instead of just embedding the php into my file. If I could use php out of the cgi-bin directory, there wouldn't be any problem.

mcibor

8:54 pm on Aug 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In that case try passing those vars via GET

<!--include virtual="/cgi-bin/relevant_script.php?var=blah" -->

Maybe this will work...

Michal Cibor

[edited by: coopster at 11:15 pm (utc) on Aug. 17, 2005]
[edit reason] removed reference to a removed thread [/edit]

raimondious

3:59 pm on Aug 18, 2005 (gmt 0)

10+ Year Member



The problem isn't putting the arguments into the path to the script, it's taking the arguments in the URL to the wrapper document and having the script that is included in the wrapper file take those arguments.

I have script1.html which includes /cgi-bin/script1.php and this script generates a list of links that go to script2.html. script2.html is a static html page that only contains

<!--#include virtual="/cgi-bin/script2.php" -->
.
But, I want script2.html?arg=blah to display the result of /cgi-bin/script2.php?arg=blah. Is there a way to do that?

raimondious

2:49 pm on Aug 25, 2005 (gmt 0)

10+ Year Member



Is there a way to use an SSI variable in the include directive?

Something like...
<!--#include virtual="/script.php?var" var="QUERY_STRING"-->

I don't know the syntax or if this is possible...

raimondious

7:28 pm on Aug 25, 2005 (gmt 0)

10+ Year Member



Turns out you *can* do this with
<!--#include virtual="script.php?${QUERY_STRING}"--> but of course, our server doesn't have the version of SSI that allows this, so I'm up a creek.