Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP : virtual(script.cgi) - shell_exec(script.cgi) : EXPERT REQUIRED

Status
Not open for further replies.

mattscotne

Programmer
Aug 18, 2005
4
AU
Hi all,

My web host has php setup as a cgi and I need to use the virtual function to run a cgi script:

Code:
 virtual('full/server/path/to/script.cgi');

However because php has been setup as a cgi as apposed to an Apache module I can not use the virtual() function. The web host will not change the php install to an Apache module.

I have done lots of google research and found a number of commands that replicate what I am trying to do including:

passthru:
Code:
 passthru('full/server/path/to/script.cgi');

system:
Code:
 echo system('full/server/path/to/script.cgi');

exec:
Code:
 echo exec('full/server/path/to/script.cgi');

shell_exec:
Code:
 echo shell_exec('full/server/path/to/script.cgi');

All of the above ouput the "Content-type: text/html" and the javascript cookie set by the script.cgi to the browser.

The script.cgi should be recording the referer but it is not functioning correctly, it does not even record a page hit as a noreferer.

I know that there is nothing wrong with the script.cgi as it is a commercial application and it records the referer correctly when I use a .shtml page( <!--#include file="script.cgi"-->) instead of a .php page.

I think what is happening is that Apache's environment variables such as HTTP_REFERER are not being passed on to the subprocess environment correctly.

How can I get this to work? or in other words what can I do to replicate the virtual() function?
 
You have to understand what virtual does. It doesn't just run the script, it runs the script as a separate request to the web server. That's why you're not getting any referer information -- where referers require running the script through a web browser, you are effectively running the script from a command-prompt.

If you absolutely must run the script through a separate web request, you're going to have to open a connection from your script back to the server itself. Depending on the PHP installation, this can be accomplished using a URL with fopen(), using cURL functions, or even sockets.

However, I strongly recommend against doing this. I have yet to see an application where opening an HTTP connection from a script on a server back to another script on the same server is necessary. Often, include() will run the script nicely. And if there is common script code that all your scripts need to run, put that code in a separate file and have all scripts include() it.



Want the best answers? Ask the best questions! TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top