okey hier mal vorweg die index.php und die captcha.php
index.php
PHP-Code:
<?php
// Session starten
session_start();
error_reporting(E_ALL);
ini_set('display_errors');
$section = array();
$section['start'] = 'start.php';
$section['about'] = 'ueber.php';
$section['ref'] = 'refs.php';
$section['info'] = 'infos.php';
$section['contact'] = 'contact.php';
$section['preis'] = 'preis.php';
$section['impressum'] = 'impressum.php';
$section['formular'] = 'formular.php';
$section['sitemap'] = 'sitemap.php';
?>
<!DOCTYPE html>
<html>
<head>
<?php
$title = 'Herzlich Willkommen auf Art Webdesign';
require_once ('head.php');
?>
</head>
<body>
<?php
echo ' <div id="wrapper">';
require_once ('header.php');
echo ' <div id="content">';
if (isset($_GET['menu'], $section[$_GET['menu']]))
{
include $section[$_GET['menu']];
} else {
include 'start.php'; // falls keine menu angegeben ist lade standardmäßig die start.php
}
echo ' <div class="clear"></div>';
echo ' </div>';
echo ' </div>';
require_once ('footer.php');
?>
</body>
</html>
captcha.php
PHP-Code:
<?php
## CAPTCHA ##
// Session starten
session_start();
// Größe des Bildes
$size_x = 70;
$size_y = 25;
// Erzeuge eine Zufallszahl
$zufallszahl = mt_rand("100000", "999999");
// Zufallszahl der Session-Variablen übergeben
$_SESSION["captcha_code"] = $zufallszahl;
// Erstelle das Bild mit der angegebenen Größe!
$bild = imageCreate($size_x, $size_y);
// Erstelle einen weißen Hintergrund
imageColorAllocate($bild, 255, 255, 255);
// Zufallsfarbe (RGB) erstellen
$farbe1 = mt_rand("0", "175");
$farbe2 = mt_rand("0", "175");
$farbe3 = mt_rand("0", "175");
// Verteile die Farben
$rahmen = imageColorAllocate($bild, 0, 0, 0); // Rahmenfarbe
$farbe = imageColorAllocate($bild, $farbe1, $farbe2, $farbe3); // Textfarbe
// Hole die Zahlen der Punkte zum Zeichnen
$alle_punkte = ($size_x * $size_y)/15;
// Zeichne viele Punkte mit der selben Farbe des Textes
for ($zaehler = 0; $zaehler < $alle_punkte; $zaehler++) {
// Erzeuge die Zufallspositionen der Punkte
$pos_x = mt_rand("0", $size_x);
$pos_y = mt_rand("0", $size_y);
// Zeichne die Punkte
imageSetPixel($bild, $pos_x, $pos_y, $farbe);
};
// Zeichne den Rahmen
imageRectangle($bild, 0, 0, $size_x-1, $size_y-1, $rahmen);
// Koordinaten der Position von der Zufallszahl
$pos_x = 8; // links
$pos_y = 5; // oben
// Zeichne die Zufallszahl
imageString($bild, 5, $pos_x, $pos_y, $zufallszahl, $farbe);
// Sende "browser header"
header("Content-Type: image/png");
// Sende das Bild zum Browser
echo imagePNG($bild);
// Lösche das Bild
imageDestroy($bild);
?>