定义的函数";mysql“U实体”修复“U字符串”;在PHP中是';我没接到电话
您正在有条件地定义函数。如果函数是在定义的函数";mysql“U实体”修复“U字符串”;在PHP中是';我没接到电话,php,security,php-5.5,secure-coding,Php,Security,Php 5.5,Secure Coding,您正在有条件地定义函数。如果函数是在If语句中定义的,则该函数仅在代码在其上执行后才可用。相反,在主作用域中定义的函数(“在所有括号之外”)是在运行文件的其余部分之前定义的。我不清楚是否有人愿意回复。无论如何,我是新的PHP,所以学习的东西。明白你的意思了。从条件定义问题中重击@PiskvorApart,这是一种错误的输入处理方法。HTML转义是一个模板输出问题,在echo将内容转换为HTML标记时,应该使用htmlspecialchars进行转义。SQL转义是一个查询准备问题,在将内容插入SQ
If
语句中定义的,则该函数仅在代码在其上执行后才可用。相反,在主作用域中定义的函数(“在所有括号之外”)是在运行文件的其余部分之前定义的。我不清楚是否有人愿意回复。无论如何,我是新的PHP,所以学习的东西。明白你的意思了。从条件定义问题中重击@PiskvorApart,这是一种错误的输入处理方法。HTML转义是一个模板输出问题,在echo
将内容转换为HTML标记时,应该使用htmlspecialchars
进行转义。SQL转义是一个查询准备问题,在将内容插入SQL字符串文字时,应该执行此操作。(或者,更好的做法是,通过在mysqli
或PDO中使用参数化查询,而不是不推荐的mysql
函数,完全避免SQL转义的需要。)您不能在一个地方同时执行这两个操作,您将损坏不一致的内容。
<?php
require_once 'login.php';
require_once 'welcome.php';
$db_server = mysql_connect($db_hostname,$db_username,$db_password);
if(!$db_server) die("Unable to connect with MySql : " . mysql_error());
mysql_select_db($db_database) or die("Unable to connect with db");
echo <<<_END
<form action = 'ps.php' method = 'post'><pre>
Enter your Username <input type = 'text' name = 'username'>
Enter your Password <input type = 'text' name = 'password'>
<input type = 'submit' value = 'Cl1ck M3'>
</pre></form>
_END;
if (isset($_POST['username']) && isset($_POST['password']))
{
//echo "Fine till here1";
echo $_POST['username']." Without htmlentities <br>";
$usernameP = mysql_entities_fix_string($_POST['username']);
if (!$usernameP) die ("No value fetched in the variable usernameP");
$passwordP = mysql_entities_fix_string($_POST['password']);
if (!$passwordP) die ("No value fetched in the variable passwordP");
$query = "SELECT * FROM hacker WHERE username = '$usernameP' AND password = '$passwordP'";
$result = mysql_query($query,$db_server);
if(!$result) die ("Unable to execute query : " . mysql_error());
$rows = mysql_num_rows($result);
$row = mysql_fetch_row($result);
echo $row[0];
if ($row[0] == '$username' && $row[1] == '$passwordP')
{
echo "Credentials Authorized";
}
function mysql_entities_fix_string($string)
{
return htmlentities(mysql_fix_string($string));
}
function mysql_fix_string($string)
{
if (get_magic_quotes_gpc()) $string = stripslashes($string);
return mysql_real_escape_string($string);
}
}
mysql_close($db_server);
?>