i have application that retrieves data from database using id.
when you click on search, it displays in the browser the id used in the database table creation
example
In my database, i have a user with id = 1,2,3 etc.
if i entered 2 from browser, it will fetch the row 2 and so on
Now with the id exposure, i guess the code is vulnerable to attack.
i have enforced SQL Injection and XSS attack protection using function mysql_real_esca pe_String and htmlentities()
my question is how do i protect this code against web attack of any kind eg CSRF attack,Content Spoofing and many more attacks
when you click on search, it displays in the browser the id used in the database table creation
example
Code:
http://localhost/guess2/Search.php?id=1
In my database, i have a user with id = 1,2,3 etc.
if i entered 2 from browser, it will fetch the row 2 and so on
Now with the id exposure, i guess the code is vulnerable to attack.
i have enforced SQL Injection and XSS attack protection using function mysql_real_esca pe_String and htmlentities()
my question is how do i protect this code against web attack of any kind eg CSRF attack,Content Spoofing and many more attacks
Code:
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="testaa"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<td colspan="4"><strong>List data from mysql </strong> </td>
</tr>
<tr>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Lastname</strong></td>
<td align="center"><strong>Email</strong></td>
<td align="center"><strong>Update</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><? echo htmlentities($rows['name']); ?></td>
<td><? echo htmlentities($rows['lastname']); ?></td>
<td><? echo htmlentities($rows['email']); ?></td>
// link to search value of id
<td align="center"><a href="up2.php?id=<? echo htmlentities($rows['id']); ?>">search</a></td>
</tr>
<?php
}
?>
</table>
</td>
</tr>
</table>
<?php
mysql_close();
?>
Comment