这篇文章主要为大家详细介绍了PHP开发需要注意的安全问题,具有一定的参考价值,可以用来参考一下。
感兴趣的小伙伴,下面一起跟随四海网的小编小韵来看看吧!
作为PHP程序员,特别是新手,对于互联网的险恶总是知道的太少,对于外部的入侵有很多时候是素手无策的,他们根本不知道黑客是如何入侵的、提交入侵、上传漏洞、sql 注入、跨脚本攻击等等。作为最基本的防范你需要注意你的外部提交,做好第一面安全机制处理防火墙。代码如下:
$myUsername = ‘tmyer';
$arrayarrayUsers = array(‘tmyer', ‘tom', ‘tommy');
define(“GREETING”, ‘Hello there' . $myUsername);
?>
代码如下:
$myUsername = $_POST['username']; //tainted!
$arrayarrayUsers = array($myUsername, ‘tom', ‘tommy'); //tainted!
define(“GREETING”, ‘hello there' . $myUsername); //tainted!
?>
代码如下:
$myUsername = cleanInput($_POST['username']); //clean!
$arrayarrayUsers = array($myUsername, ‘tom', ‘tommy'); //clean!
define(“GREETING”, ‘hello there' . $myUsername); //clean!
function cleanInput($input){ $clean = strtolower($input);
$clean = preg_replace(“/[^a-z]/”, “”, $clean);
$clean = substr($clean,0,12);return $clean;
}
?>
代码如下:
//obfuscated code
$input = (isset($_POST['username']) ? $_POST['username']:”);
//unobfuscated code
$input = ”;
if (isset($_POST['username'])){
$input = $_POST['username'];
}else{
$input = ”;
}
代码如下:
<html>
<head>
<title>Login</title>
</head>
<body>
<form action=”verify.php” method=”post”>
<p><label for='user'>Username</label>
<input type='text' name='user' id='user'/>
</p> <p><label for='pw'>Password</label>
<input type='password' name='pw' id='pw'/>
</p> <p><input type='submit' value='login'/></p>
</form>
</body>
</html>
代码如下:
<?php
$okay = 0;
$username = $_POST['user'];
$pw = $_POST['pw'];
$sql = “select count(*) as ctr from users where username='
”.$username.”‘ and password='”. $pw.”‘ limit 1″;
$result = MySQL_query($sql);
while ($data = mysql_fetch_object($result)){
if ($data->ctr == 1){
//they're okay to enter The application!
$okay = 1;
}
}
if ($okay){
$_SESSION['loginokay'] = true;
header(“index.php”);
}else{
header(“login.php”);
}
?>
代码如下:
<?php
$sql = “select count(*) as ctr from users where username=
'foo' and password=” or '1′='1′ limit 1″;
?>
代码如下:
<?php
$okay = 0;
$username = $_POST['user'];
$pw = $_POST['pw'];
$sql = "select count(*) as ctr from users where username='".mysql_real_
_string($username)."' and password='". mysql_real_escape_string($pw)."'
limit 1";
$result = mysql_query($sql);
while ($data = mysql_fetch_object($result)){
if ($data->ctr == 1){ //they're okay to enter the
application!
$okay = 1;
}
}
if ($okay){
$_SESSION['loginokay'] = true;
header("index.php");
}
else{
header("login.php");
}
?>
代码如下:
select count(*) as ctr from users where username='foo' and password=
'\' or \'1\'=\'1′ limit 1″
本文来自:http://www.q1010.com/173/13361-0.html
注:关于PHP开发需要注意的安全问题的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。
关键词:
四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。