Jump to content

trouble with php and cgi


jackiesilva

Recommended Posts

Hi,

I am a newbie to web development. I have a php file that calls a php class to display a captcha (an image with skewed chars and a text box for user to enter the correct code--used to deter auto bots) and an upload box on the same page. The class members are also called to verify that the code was entered correctly. By the way, the text is a POST var that is sent to the class. If the code is correct, the file specified in the upload box should be sent to a cgi file (redirected) that handles the upload stuff. If the code isn't correct, it redirects to itself with an error and a chance to do it again. The problem is, that if the code is correct and it redirects to the cgi file, the post vars are not sent with them. I hope I am explaining this clearly...Any ideas?

Link to comment
Share on other sites

yeah, it seems that your input field name is not what the php class is expecting it to be.

 

<input type="text" name="whatever">

 

where 'whatever' needs to be what the php class wants it to be. is the php class creating the input field? or are you writing it yourself in html?

Link to comment
Share on other sites

my html file is creating the input field:

 

 

<HTML>

<HEAD>

<TITLE>File Upload Manager</TITLE>

</HEAD>

<BODY>

<?PHP

require_once('b2evo_captcha.config.php');

require_once('b2evo_captcha.class.php');

 

        //Initialize the captcha object with our configuration options

        $captcha =& new b2evo_captcha($CAPTCHA_CONFIG);

        if (isset($_POST['image'])) {

                switch($captcha->validate_submit($_POST['image'],$_POST['attempt']))

                {

 

                        // form was submitted with incorrect key

                        case 0:

                                echo '<p><br>Sorry. Your code was incorrect.';

                                echo '<br><br><a href="'.$_SERVER['PHP_SELF'].'">Try AGAIN</a></p>';

                                break;

 

                        // form was submitted and has valid key

                        case 1:

                                header("Location: http://mycompany.com/cgi-bin/upload.cgi");

                                break;

                }

        }

        else {

        $imgLoc = $captcha->get_b2evo_captcha();

        echo '<form name="captcha" action="'.$_SERVER['PHP_SELF'].'" method="POST">'."\n";

        echo '<img src="'.$imgLoc.'" alt="This is a captcha-picture. It is used to prevent mass-access by robots." title=""><br>'."\n";

        echo '<input type="hidden" name="image" value="'.$imgLoc.'">'."\n";

        echo '<input type="text" name="attempt" value="" size="10">  ';

        echo '<table align="center" border=0 cellspacing=0 cellpadding=10 width="430">';

        echo '<tr>';

        echo '<td><input type="FILE" name="FILE1"></td>';

        echo '<td><input type="SUBMIT" value="Submit Form" style="cursor:hand;"></td>';

        echo '</tr>';

        echo '<tr>';

        echo '<td><br></td>';

        echo '</tr>';

        echo '</table>';

        echo '</form>'."\n";

        }

?>

 

 

</FORM>

</BODY>

</HTML>

 

 

 

 

Link to comment
Share on other sites

it looks like your input field name is correct, and it's expecting what is being sent. but, you have a header() function after you have echoed text to the browser... it should be bringing you an error. is it printing an error to the page? if it's not, then you don't have PHP installed on your system (or whatever server you're using). that is a separate problem entirely, because as far as i can tell, your code looks fine, except for the header() function that is.

 

also, it looks like http://mycompany.com/cgi-bin/upload.cgi is a restricted site. that may also be the cause of the problem. what exactly is happening when you submit your form?

Link to comment
Share on other sites

yes...

This script must be called using a form. Your form should point to this script. Your form tag must contain the following attributes :

 

<form action="http://mycompany.com/cgi-bin/upload.cgi" method="post" enctype="multipart/form-data">

 

The method must equal post and the enctype must equal multipart/form-data. The action has to point to this script (on your server). If you are reading this, copy and paste the example above. It has the correct values.

 

This error is generated by the upload.cgi file...

-Jackie

Link to comment
Share on other sites

Also,

mycompany.com is just a fictitious name

 

well that's part of the problem. www.mycompany.com is an actual website. do you have a hosting account with somebody or are you on your local machine running the script?

 

 

again, what is happening when you see the page? are there any errors? what happens when you submit the form?

Link to comment
Share on other sites

Sorry, yes, I am working on a company website. The error message is:

-----------------

 

This script must be called using a form. Your form should point to this script. Your form tag must contain the following attributes :

 

<form action="http://mycompany.com/cgi-bin/upload.cgi" method="post" enctype="multipart/form-data">

 

The method must equal post and the enctype must equal multipart/form-data. The action has to point to this script (on your server). If you are reading this, copy and paste the example above. It has the correct values.

-----------------

This is generated by upload.cgi because it hasn't received any post vars.

 

-Jackie

Link to comment
Share on other sites

ok i've taken a quick glance at upload.cgi, and it seems as if there are a few variables in there that you need to change. i'm not sure if you changed them before you added it to your post, but everywhere you see www.mycompany.com, you need to change it to your URL. i'm not sure if that's all you need to do, but we'll go from there.

Link to comment
Share on other sites

that helps, thank you. taking another look at upload.cgi, it seems to throw that error only if it's not recieving any input fields from your form. meaning it thinks that nobody typed in anything at all. or even that there were no input fields to begin with. so, can you elaborate a little bit on what happens when you don't type anything in? or type in something wrong? basically try to break it as many different ways as you can and record the behavior.

Link to comment
Share on other sites

here is a screenshot-- I know it's small but anything else was too big and couldn't be uploaded here. When I entered the wrong code for the captcha, it just gives an errror message, as it should, and a link to try again. This keeps continuing until the correct captcha code is entered. Oh, but if the correct captcha code is entered but the file upload box is left blank, I get this again:

 

This script must be called using a form. Your form should point to this script. Your form tag must contain the following attributes :

 

<form action="http://mycompany.com/cgi-bin/upload.cgi" method="post" enctype="multipart/form-data">

 

The method must equal post and the enctype must equal multipart/form-data. The action has to point to this script (on your server). If you are reading this, copy and paste the example above. It has the correct values.

 

-Jackie

 

[attachment deleted by admin]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.