TheJjokerR
Gebruiker
- Lid geworden
- 25 apr 2008
- Berichten
- 104
Hey allemaal,
Ik ben erg benieuwd of een van mijn eerste scripts(met hulp natuurlijk) veilig is tegen MySQL injecties?
Ik ben artikelen over MySQL Injecties aan het bekijken maar wat hulp is ook altijd handig
Dit zijn de delen die een user input hebben, die dus in aanmerking komen voor MySQL Injecties:
De Login
De Zoekfunctie:
Bij de zoekfunctie word $name door de gebruiker gegeven.
Alvast Bedankt :thumb:
EDIT
Ik las ook ergens iets over: mysql_real_escape_string(), kan dat zo worden opgelost:
Dat roept dus al de functies..
Ik ben erg benieuwd of een van mijn eerste scripts(met hulp natuurlijk) veilig is tegen MySQL injecties?
Ik ben artikelen over MySQL Injecties aan het bekijken maar wat hulp is ook altijd handig

Dit zijn de delen die een user input hebben, die dus in aanmerking komen voor MySQL Injecties:
De Login
PHP:
if( isset($_POST['submit']) ) {
if(!$_POST['steamid']) die("<div id='post'>Error: You must enter your steamid before logging in. </div>");
if(!$_POST['password']) die("<div id='post'>Error: You must enter your password before logging in.</div>");
if(!empty($_POST['stay_in'])) {
$joined =''.$_POST['steamid'].'[]'.$_POST['password'].'';
setcookie('login_cookie', $joined, 2147483647, '/', ".$homepage");
} //end if
$get_user = mysql_query("SELECT * FROM `players` WHERE _SteamID = '".$_POST['steamid']."' AND password = '".$_POST['password']."'");
$quser = mysql_fetch_object($get_user);
if(!$quser) die("<div id='post'>Login Failure: An error occured, please verify your steamid and password are correct.</div>");
$_SESSION['logged_in'] = 1;
$_SESSION['steamid'] = $quser->_SteamID;
$_SESSION['password'] = $_POST['password'];
session_write_close();
header("Location: index.php?steamid=".$_SESSION['steamid']."");
} else {
//show login form
?>
<form name="login" method="post" action="<? $_SERVER['PHP_SELF']; ?>">
<table>
<tr>
<td><div id='post'>SteamID:</div><input type="text" id="steamid" name="steamid"><div id='post'>(For Example: 'STEAM_0:1:1234567')</div></td>
</tr>
<tr>
<td><div id='post'>Password:</div><input type="password" id="password" name="password"></td>
</tr>
<tr>
<td><div id='post'></div><input type="submit" value="Log In" name="submit" id="submit"></td>
</tr>
<tr>
<td><div id='post'>Remember? <input type="checkbox" name="stay_in[]">(Be careful with this, your password and steamid will be saved in a cookie)</div></td>
</tr>
</table>
</form>
<?
}//end else
De Zoekfunctie:
PHP:
function Search($mode,$name){
if($mode == 0){ //Search by player name
$get_userinfo = mysql_query("SELECT * FROM `players` WHERE _Name LIKE '%". $name ."%'");
}elseif($mode == 1){ //Search by clan name
$get_userinfo = mysql_query("SELECT * FROM `players` WHERE _Clan LIKE '%". $name ."%'");
}else{ // Just dont call a function without the right argument -.-
die("<div id='post'>Function Error: Invalid Mode ( 0 = Player Name / 1 = Clan Name )</div>");
}
echo "<div id='post'>Search results:<BR>";
echo "<BR><table border='0' width='100%' id='resultstable'>";
echo "<tr><td><div id='post'><b>Name</b></div></td><td><div id='post'><b>Clan</b></div></td> <td><div id='post'><b>SteamID</b></div></td> <td><div id='post'><b>UniqueID</b></div></td><td><div id='post'><b>Online Profile</b></div></td></div>";
while($row = mysql_fetch_array($get_userinfo))
{
echo "<tr>";
echo "<td><div id='post'>".$row['_Name']."</div></td><td><div id='post'>".$row['_Clan']."</div></td> <td><div id='post'>".$row['_SteamID']."</div></td> <td><div id='post'>".$row['_UniqueID']."</div></td><td><div id='post'><a href='index.php?uniqueid=".$row['_UniqueID']."'>Show Online Profile</a></div></td>";
echo "</tr>";
}
echo "</table><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>";
}
Bij de zoekfunctie word $name door de gebruiker gegeven.
Alvast Bedankt :thumb:
EDIT
Ik las ook ergens iets over: mysql_real_escape_string(), kan dat zo worden opgelost:
PHP:
if(isset($_GET['uniqueid'])){
GetUserInfo(0,mysql_real_escape_string($_GET['uniqueid']));
}elseif(isset($_GET['steamid'])){
GetUserInfo(1,mysql_real_escape_string($_GET['steamid']));
}elseif(isset($_GET['pname'])){
Search(0,mysql_real_escape_string($_GET['pname']));
}elseif(isset($_GET['cname'])){
Search(1,mysql_real_escape_string($_GET['cname']));
}elseif(isset($_POST['submitsearch'])){
if(isset($_POST['pname'])){
header("Location: index.php?pname=".$_POST['pname']."");
}elseif(isset($_POST['pname'])){
header("Location: index.php?cname=".$_POST['cname']."");
}elseif(isset($_POST['steamid'])){
header("Location: index.php?steamid=".$_POST['steamid']."");
}elseif(isset($_POST['uniqueid'])){
header("Location: index.php?uniqueid=".$_POST['uniqueid']."");
}
}
Dat roept dus al de functies..
Laatst bewerkt: