I am on an Apache server that runs all CGI files that have a .cgi extension as SETUID, which means they run as my username. I am in a public_html directory. The sysadmin told me how to run my PHP scripts as my own username by changing the .php extension to .cgi and putting in a SheBang line at the beginning. The SheBang line specifies the PHP binary as the script interpreter, and in addition a line specifying the MIME type is needed. Therefore, any script like:
phpscript001.php:
Code: Select all
<html>
<head></head>
<body>
<?php echo "Hello!"; ?>
</body>
</html>phpscript001.cgi:
Code: Select all
#!/usr/bin/php
Content-type: text/html
<html>
<head></head>
<body>
<?php echo "Hello!"; ?>
</body>
</html>Now here is the major problem that I found with PHP scripts run as .cgi files: the special PHP variables are not set for them! The variables $_POST, $_GET, $_COOKIE, and $_REQUEST are not set at all like they are for a normal PHP script, and since my code depends on these variables, it dies. It must be because generic CGI executables/scripts aren't run via the standard PHP module under Apache. The script does, however, get passed the generic CGI environment variables, like the query string, post information, etc. They would just have to be parsed manually, which can be unsafe and takes a lot of unnecessary work to make it robust.
Can anyone tell me if I would really need to reinvent the wheel on these PHP variables and parse them myself? Isn't there any way I could just explicitly call the PHP module, library, or header that would do this for me so I can effectively get it to run like a normal PHP script? Maybe there is a special way to call the PHP binary, or some standard API library in include files?
Please note that this post is based on viewtopic.php?f=34&t=80287&p=449753#p449753; it's just that I'm not getting any responses there because I guess I loaded the question too much. Here I'm just isolating the issue of how to fix the PHP variable problem that occurs when I run PHP as an external interpreter.
Thanks