Re: Returning response includes HTML form data

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

 



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.

Naturally I do not want the form to be included in the response and do not understand how or why I am getting it back ? Does anybody know why this is happening ?

As an example of what is happening my form data in the PHP file looks like:

<form ENCTYPE="multipart/form-data" ACTION="" METHOD="POST">
<input NAME="name1" TYPE="file">
<input NAME="name2" TYPE="text">
<input NAME="name3" TYPE="text">
<input VALUE="submit" TYPE="submit"></form>

Somewhere in the PHP file I am doing:

echo "someresponse"

and the data being read back in the response is a string of:

"someresponse\n<form ENCTYPE="multipart/form-data" ACTION=""METHOD="POST">\n<input NAME="name1" TYPE="file">\n<input NAME="name2" TYPE="text">\n<input NAME="name3" TYPE="text">\n<input VALUE="submit" TYPE="submit"></form>"

My magical sight into your code reveals.... nothing.
Why? because I can't see it, I don't have any magical sight, so if you don't post any code, I don't know what it is.

Now, usually this is simply a designflaw, eg. you have a script like so:
<?php
// do something
echo "someresponse";

// do something else
// do even more
echo '<form ENCTYPE="multipart/form-data" ACTION=""METHOD="POST">\n<input NAME="name1" TYPE="file">\n<input NAME="name2" TYPE="text">\n<input NAME="name3" TYPE="text">\n<input VALUE="submit" TYPE="submit"></form>';
// do more stuff
?>

Probably your code further on doesn't check if you really want to show it or not, there are 2 ways to resolve this:
1. exit after your response (using eg. die() or exit)
2. surround your form with an if() which checks that you really DO wish to show it.

But, it might also be something else (though I doubt it), in which case: Post your code, fool!! ([TM] mr. T)

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.

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