Tijd voor een voorbeeldje.
header.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$sitenaam[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000] - [/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$paginanaam[/COLOR][COLOR= #007700];[/COLOR] ?></title>
</head>
<body>
footer.php:
<br /><br />
© [COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/date"]date[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Y[/COLOR][COLOR= #007700]).[/COLOR][COLOR= #DD0000] [/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$sitenaam[/COLOR][COLOR= #007700];[/COLOR] ?>
</body>
</html>
config.php:
[COLOR= #0000BB]<?php
$sitenaam[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]one2xs[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/extract"]extract[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700]);[/COLOR]
index.php:
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/include_once"]include_once[/URL] [COLOR= #DD0000]config.php[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$paginanaam[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]homepage[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/include_once"]include_once[/URL] [COLOR= #DD0000]header.php[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$naam[/COLOR][COLOR= #007700]))
{[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] htmlentities[COLOR= #007700]([/COLOR][COLOR= #0000BB]$naam[/COLOR][COLOR= #007700]).[/COLOR][COLOR= #DD0000], welkom op one2xs![/COLOR][COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL]
[COLOR= #007700]{[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Welkom op one2xs![/COLOR][COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/include_once"]include_once[/URL] [COLOR= #DD0000]footer.php[/COLOR][COLOR= #007700];[/COLOR]
Lijkt prima toch?
Je kunt hem aanroepen met:
/index.php
en dan krijg je keurig een welkom te zien en een mooie footer.
Je kunt hem ook met
/index.php?naam=lennard
aanroepen, en dan krijg je een persoonlijk welkom te zien en nog dezelfde footer; XSS werkt niet want daar hebben we HTML entities voor
Maar je kan hem ook zo aanroepen:
/index.php?naam=lennard&sitenaam=GHED
en kijk dan eens naar de footer.....
(al kun je dat met de tweede parameter wel oplossen, maar het idee blijft hetzelfde)
En dat is juist de ellende van die extract(). Het lijkt handig maar het is gewoon totaal onwenselijk, want je kunt geen enkele variabele meer vertrouwen, en dat maakt de kans op bugs en hacks onwijs groot.
Doe het gewoon niet, de PHP ontwikkelaars hebben niet voor niets besloten om het $_GET en $_POST te noemen en niet alles direct naar lokale variabelen te porten.
Er staat ook niet voor niets een grote rode dikgedrukte waarschuwing op de PHP pagina van extract().