Re: Re: Returning response includes HTML form data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



brian wrote:
Edward Diener wrote:
Maciek Sokolewicz wrote:
Edward Diener wrote:
I have a PHP file which does an:

echo "someresponse"

to return some data. When I run it from a Windows client program, the response I am seeing is not only the "someresponse" above but also has the entire HTML form in the PHP file appended to it.


Here is the code, with names suitable changed to protect actual functionality of proprietary software:

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

<?php
if ( ! (isset($_GET['zzzzz']) && $_GET['zzzzz'] == 124) )
   {             ?>
        <script>
        alert(" UnAuthorised Access..............");
         window.location ="ascript.php";
        </script>
       <?php
       echo " UnAuthorised Access..............";
       exit;
   }

function MyExampleFunction($param1, $param2, $param3,$param4="")
{
    $param5  = 'Info1' . "\r\n";
    $param5 .= 'Info2' . "\r\n";
    $param5 .= 'Info3';
    if(SomePHPFunction($param1,$param3,$param2."\r\n\r\n",$param5))
        echo "SomePHPFunction called for $param1 OK.\n";
    else
echo "Could not call SomePHPFunction for $param1.\nError: ".$param4."\n";
}

if ($_FILES['AFileName']['name'] == "")
{
    echo "No AFileName.";
    exit;
}
if ($_POST['AInput1'] == "")
{
    echo "No AInput1.";
    exit;
}
if ($_POST['AInput2'] == "")
{
    echo "No AInput2.";
    exit;
}

$AVariable1 = $_POST['AInput1'];
$AVariable2 = $_POST['AInput2'];
$size = filesize($_FILES['AFileName']['tmp_name']);
$fp = fopen ($_FILES['AFileName']['tmp_name'], "r");
$AVariable3 = fread($fp, $size);
fclose ($fp);
@MyExampleFunction($AVariable1, $AVariable3, $AVariable2);
    ?>
<form ENCTYPE="multipart/form-data" ACTION="" METHOD="POST">
<input NAME="AFileName" TYPE="file">
<input NAME="AInput1" TYPE="text">
<input NAME="AInput2" TYPE="text">
<input VALUE="submit" TYPE="submit"></form>

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

The code takes to input fields and a single file upload,
calls the MyExampleFunction, which calls the SomePHPFunction successfully. The SomePHPFunction is a function in one of PHP's
libraries.

The response comes from the:

echo "SomePHPFunction called for $param1 OK.\n";

statement, plus

<form ENCTYPE="multipart/form-data" ACTION="" METHOD="POST">
<input NAME="AFileName" TYPE="file">
<input NAME="AInput1" TYPE="text">
<input NAME="AInput2" TYPE="text">
<input VALUE="submit" TYPE="submit"></form>

I have no idea why all the form data is being appended to the response.


Because you haven't included any conditions to test whether or not to output the form, nor exited the script before the form is parsed. Pick one or the other.

I do not understand what you mean by your first statement above when you say 'you haven't included any conditions to test whether or not to output the form'. Am I not 'responding' to the form in my PHP code based on the input parameters to the form in my PHP code ? I also do not understand what you mean by 'nor exited the script before the form is parsed'. Does not the script 'exit' when the PHP code reaches the ending '?>' tag ?

As I understand it the PHP code, in between the '<?php' and '?>' tag, is there to process the form, in essence responding to a request on the form. Is this incorrect ? In my PHP code the 'echo' statement sends a response back for the request. Is that not correct ?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux