ei, das klappt super.
Wenn ich das Formular einzeln aufrufe, durch "./contact.php", wird es mir korrekt angezeigt. Jedoch wird beim aufruf über meine index.php das Kontaktformular fehlerhaft angezeigt mit PHP Quellcode in den Textfeldern etc.
www.sandro-feyh.eu » Kontaktformular
secure.php
PHP-Code:
<?php
class SecureForm
{
private
$secret = null,
$keys = array (),
$confusing = array ();
public function __construct () {
@ini_set('session.use_cookies', 0);
@ini_set('session.use_only_cookies', 0);
session_start();
if (!empty ($_SESSION['secret'])) {
$this->secret = $_SESSION['secret'];
} else {
$this->secret = $this->generateID();
}
if (!empty ($_SESSION['keys'])) {
$this->keys = $_SESSION['keys'];
}
if (!empty ($_SESSION['confusing'])) {
$this->confusing = $_SESSION['confusing'];
}
if (!headers_sent ()) {
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
}
}
public function __destruct ()
{
$_SESSION['secret'] = $this->secret;
$_SESSION['keys'] = $this->keys;
$_SESSION['confusing'] = $this->confusing;
}
protected function generateID ()
{
return substr (chr (rand (97, 122)) . sha1 (uniqid ()), 0, rand (5, 8));
}
public function getID ($label)
{
if (empty ($this->keys[$label])) {
$this->keys[$label] = $this->generateID();
}
return $this->keys[$label];
}
public function getSecretID ()
{
return $this->secret;
}
public function regenerateIDs ()
{
if (headers_sent ()) return false;
@session_regenerate_id (true);
$this->secret = $this->generateID();
foreach ($this->keys as $key => $value) {
$this->keys[$key] = $this->generateID();
}
$this->confusing = array ();
return true;
}
public function generateCSS ($return = false)
{
$content = '@media all{';
$ids = array_values ($this->keys);
if (empty ($this->confusing)) {
for ($i = 0; $i < (rand(8, 15)); $i++) {
$id = $this->generateID();
$ids[] = $id;
$this->confusing[] = $id;
}
} else {
$ids = $ids + $this->confusing;
}
sort ($ids);
$num = count($ids);
$pos = array_rand ($ids);
$displayed = false;
for ($i = 0; $i < $num; $i++) {
if (($pos == $i) && (!$displayed)) {
$content .= '#' . $this->secret . ' {';
$content .= "position:absolute !important;left:-99999px;speak:none !important;display:none !important;}";
$displayed = true;
$i--;
} elseif (in_array ($ids[$i], $this->keys)) {
$content .= '#' . $ids[$i] . " {";
$content .= "position:absolute;left:-99999px;speak:none;display:none;}";
} else {
$r = (rand (0, 1) == 1);
$content .= '#' . $ids[$i] . " {";
$content .= "position:absolute" . ($r ? ' !important' : '') . ";left:-99999px;speak: none" . ($r ? ' !important' : '') . ";display: none" . ($r ? ' !important' : '') . ';}';
}
}
$content .= '}';
if ($return) {
return $content;
} else {
echo $content;
}
}
}
?>
contact.php
PHP-Code:
<?php
require_once 'secure.php';
$form_sent = false;
$form = new SecureForm();
$id_name = $form->getID('name');
$id_email = $form->getID('email');
$id_nachricht = $form->getID('nachricht');
$id_submit = $form->getID('submit');
if (isset ($_GET['getCSS'])) {
header ("Content-Type: text/css");
$form->generateCSS();
exit;
}
if (!empty ($_POST[$id_submit])) {
$form_sent = true;
if (!empty ($_POST[$id_name]) && !empty ($_POST[$id_email]) && !empty ($_POST[$id_nachricht])) {
if (!empty ($_POST[$form->getSecretID()])) {
session_destroy ();
echo 'Spambot erkannt.';
exit;
}
$name = $_POST[$id_name];
$email = $_POST[$id_email];
$nachricht = $_POST[$id_nachricht];
mail ('feyh.sandro@t-online.de', 'Nachricht von ' . $name, $name . ' (' . $email . ") hat eine Nachricht geschrieben:\n" . $nachricht,'From: host-admin@sandro-feyh.eu');
session_destroy ();
exit;
}
$form->regenerateIDs();
}
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Kontaktformular mit Spamschutz</title>
<style type="text/css">
body {
color: #555;
font: 0.8em \'Lucida Grande\', Verdana, Tahoma, sans-serif;
}
fieldset {
border: 1px dotted #A6A6A6;
padding: 10px;
margin: 5px;
margin-bottom: 20px;
}
fieldset legend {
font-weight: bold;
}
.form input, .form textarea {
position: static !important;
display: block !important;
speak: normal !important;
}
</style>
<link rel="stylesheet" type="text/css" href="secureForm_example.php?getCSS&' . SID . '" media="all" />
</head>
<body>
<fieldset>
<legend>Kontaktformular</legend>
<!-- Auch hier ist die Session-ID wichtig, um die IDs spaeter wieder den Feldern zuzuordnen -->
<form action="secureForm_example.php?' . SID . '" method="POST" class="form">';
echo '
<label>Dein Name' . ((($form_sent && empty ($_POST[$id_name]))) ? ' (fehlt)' : '') . ':</label> <input type="text" id="' . $id_name . '" name="' . $id_name . '" value ="' . ((!empty ($_POST[$id_name])) ? htmlspecialchars ($_POST[$id_name]) : '') . '" /><br />
<label>Deine E-Mail-Adresse' . ((($form_sent && empty ($_POST[$id_mail]))) ? ' (fehlt)' : '') . ':</label> <input type="text" id="' . $id_email . '" name="' .$id_email . '" value="' . ((!empty ($_POST[$id_email])) ? htmlspecialchars ($_POST[$id_email]) : '') . '" /><br />
<label>Deine Nachricht' . ((($form_sent && empty ($_POST[$id_nachricht]))) ? ' (fehlt)' : '') . ':</label><br />
<textarea name="' . $id_nachricht . '" id="' . $id_nachricht . '">' . ((!empty ($_POST[$id_nachricht])) ? htmlspecialchars ($_POST[$id_nachricht]) : '') . '</textarea><br />
<input type="text" name="' . $form->getSecretID() . '" id="' . $form->getSecretID() . '" value="" />' . // Auch das versteckte Feld bekommt seinen Platz
'
<input type="submit" name="' . $id_submit . '" id="' . $id_submit . '" value="Formular absenden" />
</form>
</fieldset>
</body>
</html>';
?>
index.php
PHP-Code:
<?php
define('page', isset($_GET['page']) ? $_GET['page'] : 'index');
switch(page) {
case 'index':
$title = 'www.sandro-feyh.eu » Startseite';
$text = file_get_contents('./html/index.html');
break;
case 'imprint':
$title = 'www.sandro-feyh.eu » Impressum';
$text = file_get_contents('./html/imprint.html');
break;
case 'contact':
$title = 'www.sandro-feyh.eu » Kontaktformular';
$text = file_get_contents('./contact.php');
break;
case 'aboutme':
$title = 'www.sandro-feyh.eu » Der Autor über sich selbst';
$text = file_get_contents('./html/aboutme.html');
break;
case 'gallery':
$title = 'www.sandro-feyh.eu » Bildergalerie';
$text = file_get_contents('./html/gallery.html');
break;
case 'media':
$title = 'www.sandro-feyh.eu » Videoclips';
$text = file_get_contents('./media.php');
break;
default:
$title = 'www.sandro-feyh.eu » Es ist ein Fehler aufgetreten';
$text = file_get_contents('./html/error.html');
}
?>
<!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" xml:lang="en">
<head>
<meta name="author" content="Sandro Feyh" />
<meta name="copyright" content="Sandro Feyh" />
<meta name="robots" content="index,follow" />
<meta name="revisit-after" content="7 days" />
<meta name="language" content="de" />
<meta name="keywords" content="sandro, feyh, sandro feyh, sandro-feyh, sandrofeyh, xhtml, css, w3, w3c, valide, konform, design, webdesign, milo, portfolio, website, webseite, page, homepage, internet, web, net, privat, internetauftritt" />
<meta name="description" content="Sandro-Feyh.eu - Mein Online Portfolio zu Themen wie - Milo, ein Jack-Russel-Terrier, meine Hobbies, Webdesign, Musik, Spiele, Fotografie und Videos." />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="shortcut icon" href="./images/favicon.ico" />
<title><?php echo $title; ?></title>
<script type="text/javascript" src="./js/mootools.js"></script>
<script type="text/javascript" src="./js/slimbox.js"></script>
<style type="text/css"><!--
body
{
font-family:Verdana, sans-serif;
font-size:9px;
background-color:#787878;
text-align:center;
}
h1 {font-size:18px;color:#333333;margin:0px;}
h2 {font-size:14px;color:#333333;}
h3 {font-size:14px;color:#333333;}
p {margin-top:0px;}
span.red {
color:#800000;
}
a:link, a:visited, a:active
{
text-decoration:none;
color:#3A88C7;
font-size:9px;
}
a:hover
{
color:#4D80B1;
}
a.menu:link, a.menu:visited, a.menu:active
{
color:#AA0000;
}
a.menu:hover
{
color:#800000;
}
#title {
padding-top:15px;
height:24px;
}
#menu {
background-image: url(./images/background.png);
color:#FF0000;
text-align:center;
padding:1px 0px;
clear:right;
}
#content {
border:1px solid #000000;
background-color:#FEFEFE;
padding:6px;
color:#000000;
}
#lbOverlay {
position: absolute;
z-index: 9999;
left: 0;
width: 100%;
background-color: #000;
cursor: pointer;
}
#lbCenter, #lbBottomContainer {
position: absolute;
z-index: 9999;
left: 50%;
overflow: hidden;
background-color: #fff;
}
.lbLoading {
background: #fff url(./images/loading.gif) no-repeat center;
}
#lbImage {
position: absolute;
left: 0;
top: 0;
border: 10px solid #fff;
background-repeat: no-repeat;
}
#lbPrevLink, #lbNextLink {
display: block;
position: absolute;
top: 0;
width: 50%;
outline: none;
}
#lbPrevLink {
left: 0;
}
#lbPrevLink:hover {
background: transparent url(./images/prevlabel.gif) no-repeat 0% 15%;
}
#lbNextLink {
right: 0;
}
#lbNextLink:hover {
background: transparent url(./images/nextlabel.gif) no-repeat 100% 15%;
}
#lbBottom {
font-family: Verdana, Arial, Geneva, Helvetica, sans-serif;
font-size: 10px;
color: #666;
line-height: 1.4em;
text-align: left;
border: 10px solid #fff;
border-top-style: none;
}
#lbCloseLink {
display: block;
float: right;
width: 113px;
height: 22px;
background: transparent url(./images/closelabel.gif) no-repeat center;
margin: 5px 0;
outline: none;
}
#lbCaption, #lbNumber {
margin-right: 71px;
}
#lbCaption {
font-weight: bold;
}
//--></style>
</head>
<body>
<div style="width:620px;margin:0px auto;text-align:left;">
<div align="center"><img src="./images/header.png" title="Um zur Startseite zu gelangen, bitte klicken" alt="Um zur Startseite zu gelangen, bitte klicken" /></div>
<div id="menu">
<?php
$link_array = array();
$link_array[0] = '<a class="menu" href="./index.php">Startseite</a> ';
$link_array[1] = '<a class="menu" href="./index.php?page=imprint">Impressum</a> ';
$link_array[2] = '<a class="menu" href="./index.php?page=contact">Kontaktformular</a> ';
$link_array[3] = '<a class="menu" href="./index.php?page=aboutme">Über Mich</a> ';
$link_array[4] = '<a class="menu" href="./index.php?page=gallery">Bildergalerie</a> ';
$link_array[5] = '<a class="menu" href="./index.php?page=media">Videoclips</a>';
switch(page) {
case 'index':
$link_array[0] = '<span class="red">Startseite</span> ';
break;
case 'imprint':
$link_array[1] = '<span class="red">Impressum</span> ';
break;
case 'contact':
$link_array[2] = '<span class="red">Kontaktformular</span> ';
break;
case 'aboutme':
$link_array[3] = '<span class="red">Über Mich</span> ';
break;
case 'gallery':
$link_array[4] = '<span class="red">Bildergalerie</span> ';
break;
case 'media':
$link_array[5] = '<span class="red">Videoclips</span>';
break;
}
for($i = 0; $i < count($link_array); $i++) {
echo $link_array[$i] . "\n";
}
?>
</div>
<div id="content">
<div id="main">
<?=$text ?>
</div>
</div>
<div align="center"><img src="./images/spacer.png" alt="" title="" /></div>
<p align="center"><font color="#999999" style="font-family:verdana;" size="1">Copyright © 2008 by Sandro Feyh. Alle Rechte vorbehalten.</font></p>
</div>
</body>
</html>
Was habe ich übersehen?
Scheinbar funktioniert die einfache integration einer .php seite nicht.
Ich möchte jedoch gerne das Kontaktformular, so wie alle anderen seiten auch in die bestehende seite einbauen. Ideen wie ich das bewerkstelligen könnte?