Re: Re: Returning response includes HTML form data

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

 



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.

b

--
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