Forum Moderators: coopster

Message Too Old, No Replies

PHP parse CGI

form.cgi with <?php?>

         

mcibor

7:37 pm on Feb 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi All

My customer runs a <form action="form.cgi" script.
Is it possible to add .cgi to be parsed by php and eg write there:

<?php
require_once('function.php');
if(!validate())
{
require_once('bad_url.html');
exit;
}

I have found a workaround at virtual [php.net] but that doesn't allow me to check validation.
I have no way of testing that myself.
Thanks for any info

Michal

eelixduppy

8:21 pm on Feb 25, 2007 (gmt 0)



In httpd.conf or .htaccess you can make .cgi files parsed as php with the following:

AddType application/x-httpd-php .php .cgi

Should work :)

mcibor

8:28 pm on Feb 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



doesn't work :/

I get internal server error 500.

I put working cgi with:


#!/usr/bin/perl
<?php
?>
...rest of cgi

The same is when <?php is in first line :/
Will go to perl forum to ask how to read session :/

Or you guys are having some idea? I don't want to rewrite whole cgi to php.

Regards
Michal

StupidScript

8:57 pm on Feb 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How about making the form's action="validate.php" where you grab the POST/GET array, validate the input with PHP and then redirect (header("Location: ...)) back to the form page or send it on to form.cgi, depending on whether it validates or not?

"validate.php" could easily be the form page itself.

mcibor

7:34 am on Mar 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I tried that using virtual, but it didn't work... There was just blank page formmail.cgi, whereas it should somehow redirect.

But I'm starting to have ideas on how to perform that in clear perl...

Thanks anyway

PS. If you know of any way to redirect to formmail.cgi that will work I'm open for suggestions.

StupidScript

12:13 am on Mar 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not having any trouble with a GET request:
<?
if ($_GET) {
$test="http://example.com/cgi-bin/test.cgi?".$_SERVER['QUERY_STRING'];
# DO VALIDATION
if ($valid) {
header("Location: $test");
exit;
}
else {
print "Not valid:<br />";
echo <<<FORM
<form method=get action="$PHP_SELF">
TEST1: <input type="text" name="test1" /><br />
TEST2: <input type="text" name="test2" /><br />
<input type="submit" />
</form>
FORM;
}
}
else {
echo <<<FORM
<form method=get action="$PHP_SELF">
TEST1: <input type="text" name="test1" /><br />
TEST2: <input type="text" name="test2" /><br />
<input type="submit" />
</form>
FORM;
}
?>

For a POST request, you'd want to do a little routine to pull the variables and include them into the
$test
string, because QUERY_STRING only grabs GET items ... but I'm too lazy to do that, this late on a Friday afternoon. ;)

[edited by: StupidScript at 12:23 am (utc) on Mar. 3, 2007]

mcibor

8:07 am on Mar 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'll just rewrite the form to php, it will be much easier for me that way :)

Thanks for answers.

PS. Get was passed, I think, but as the script just returned blank page I cannot say where the error was...