Skip to content

Instantly share code, notes, and snippets.

@spencerdeinum
Created September 7, 2015 18:09
Show Gist options
  • Save spencerdeinum/42bd35ba1dac06622570 to your computer and use it in GitHub Desktop.
Save spencerdeinum/42bd35ba1dac06622570 to your computer and use it in GitHub Desktop.
Example of sql injection in PDO
<?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