Skip to Content
PHP 5 Kochbuch, Third Edition
book

PHP 5 Kochbuch, Third Edition

by David Sklar, Adam Trachtenberg, Carsten Lucke, Matthias Brusdeylins, Ulrich Speidel, Stephan Schmidt
September 2009
Intermediate to advanced content levelIntermediate to advanced
912 pages
48h 11m
German
O'Reilly Verlag
Content preview from PHP 5 Kochbuch, Third Edition

17.17 SQL-Injection verhindern

Problem

Sie müssen die Gefährdung Ihrer PHP-Anwendung durch SQL-Injection-Angriffe ausräumen.

Lösung

Nutzen Sie eine Datenbankbibliothek wie PDO, die die für Ihre Datenbank erforderlichen Maskierungsvorgänge übernimmt:

<?php
$db = new PDO('mysql:host=localhost;dbname=users',
              $_SERVER['DB_USER'],
              $_SERVER['DB_PASSWORD']);
$statement = $db->prepare("INSERT
                             INTO   users (username, password)
                             VALUES (:username, :password)");
$statement->bindParam(':username', $clean['username']);
$statement->bindParam(':password', $clean['password']);
$statement->execute();
$db = NULL;
?>

Diskussion

Der Einsatz gebundener Parameter sichert, dass Ihre Daten nie in einen Kontext gelangen, in dem sie als etwas anderes betrachtet werden als reine ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP programmieren unter Windows

PHP programmieren unter Windows

Arno Hollosi

Publisher Resources

ISBN: 9783868993271Purchase book