Created
September 7, 2015 18:09
-
-
Save spencerdeinum/42bd35ba1dac06622570 to your computer and use it in GitHub Desktop.
Example of sql injection in PDO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$dbh = new PDO('mysql:host=localhost;dbname=injection', 'root'); | |
if(isset($_GET['id'])) { | |
// Example of injectable sql query | |
foreach($dbh->query('select * from users where id = ' . $_GET['id'] . ' LIMIT 1') as $query) { | |
$user = $query; | |
} | |
} | |
?> | |
<?php if(isset($user)): ?> | |
<div> | |
Found user | |
<?= $user['name'] ?> | |
</div> | |
<?php else: ?> | |
<div> | |
Search for a <a href="/?id=1">user</a>. | |
</div> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment