誰かが私のPHPコーディングの保護を強化するのを手伝ってくれるかどうか疑問に思っていました。それは非常に基本的であり、ある程度の防御が必要です。
私が助けを必要としていることについて十分な詳細を提供したことを願っています、どうもありがとう!
<?php
//This is only displayed if they have submitted the form
if ($searching =="yes") {
echo "<h2>Results</h2><p>";
//If they did not enter a search term we give them an error
if ($find == "")
if ($f == "")
if ($info == "")
if ($zip == "")
if ($state == "")
if ($email == "")
if ($address == "")
{
echo "<p>You forgot to enter a search term";
exit;
}
// Otherwise we connect to our Database
mysql_connect("xx.xx.xx", "xxxx", "xxxxx") or die(mysql_error());
mysql_select_db("xxxxx") or die(mysql_error());
// We preform a bit of filtering
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);
$f = strtoupper($f);
$f = strip_tags($f);
$f = trim ($f);
$info = strtoupper($info);
$info = strip_tags($info);
$info = trim ($info);
$zip = strtoupper($zip);
$zip = strip_tags($zip);
$zip = trim ($zip);
$state = strtoupper($state);
$state = strip_tags($state);
$state = trim ($state);
$email = strtoupper($email);
$email = strip_tags($email);
$email = trim ($email);
$address = strtoupper($address);
$address = strip_tags($address);
$address = trim ($address);
//Now we search for our search term, in the field the user specified
$data = mysql_query("SELECT * FROM users WHERE fname
LIKE '%" . mysql_real_escape_string($find) . "%' AND lname
LIKE '%" . mysql_real_escape_string($f) . "%' AND info
LIKE '%" . mysql_real_escape_string($info) . "%' AND zip
LIKE '%" . mysql_real_escape_string($zip) . "%' AND state
LIKE '%" . mysql_real_escape_string($state) . "%' AND email
LIKE '%" . mysql_real_escape_string($email) . "%' AND address
LIKE '%" . mysql_real_escape_string($address) . "%'");
//And we display the results
while($result = mysql_fetch_array( $data ))
{
echo $result['fname'];
echo "<br>";
echo $result['lname'];
echo "<br>";
echo $result['info'];
echo "<br>";
echo $result['zip'];
echo "<br>";
echo $result['state'];
echo "<br>";
echo $result['email'];
echo "<br>";
echo $result['address'];
echo "<br>";
}
//This counts the number or results - and if there wasn't any it gives them a little message explaining that
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}
//And we remind them what they searched for
echo "<b>Searched For:
</b> " .$find;
}
?>