ciao , scusate la lunghezza del codice ma serve per capire meglio , ho letto di tutto su questo argomento a me da sempre questo errore:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at I:\Inetpub\wwwroot\cgi-bin\registercomplete.php:2) in I:\Inetpub\wwwroot\cgi-bin\registercomplete.php on line 3
praticamete ho un form in una pagina che richiama un file captcha dove viene aperta una sessione , premendo submit il file php che fa il controllo mi da l 'errore sopra .
file form :
---------------------<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<title>Photography Website Template</title>
<link rel="StyleSheet" href="coolstyle.css" type="text/css">
</head>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<script language="JavaScript" type="text/javascript" src="pop-closeup.js"></script>
<script language="JavaScript" type="text/javascript" src="javascripts.js"></script>
<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td align="center" valign="top">
<script language="JavaScript" type="text/javascript" src="header.js"></script>
<script language="JavaScript" type="text/javascript" src="menu.js"></script>
<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td align="center" valign="top" class="sidebarwidth">
<script language="JavaScript" type="text/javascript" src="sidebar.js"></script>
</td><td align="center" valign="top">
<table cellpadding="0" cellspacing="10" border="0" width="450">
<tr><td align="left" valign="top" class="just">
<span class="title">Register</span>
Se sei su questa pagina confermi di essere d'accordo con le politiche di etica del sito e hai letto l'informativa sulla Privacy. Inserendo i dati nel form sottostante ti sara' inviata un email per completare la registrazione.
<center>
<TABLE BORDER="0" cellpadding="0" cellspacing="0" width="80%"><TR><TD>
<form method="POST" action="cgi-bin/registercomplete.php" target="_top">
<INPUT TYPE="HIDDEN" NAME="recipient" VALUE="info@your-web-domain.com">
<INPUT TYPE="HIDDEN" NAME="subject" VALUE="WebSite Contact">
<INPUT TYPE="HIDDEN" NAME="redirect" VALUE="http://your-web-domain.com/thanks.htm">
<INPUT TYPE="HIDDEN" NAME="required" VALUE="email,email_confirm,your_name">
<INPUT TYPE="HIDDEN" name="sort" value="your_name,phone,company_name,email,email_co nfirm,comments">
<TABLE BORDER="0" cellpadding="1" cellspacing="0" width="100%">
<TR><TD>
User:
</TD></TR><TR><TD>
<INPUT TYPE="TEXT" NAME="your_name" SIZE="30" class="shadeform">
</TD></TR><TR><TD>
Password:
</TD></TR><TR><TD>
<INPUT TYPE="password" NAME="company_name" SIZE="30" class="shadeform">
</TD></TR><TR><TD>
Email:
</TD></TR><TR><TD>
<INPUT TYPE="TEXT" NAME="email" SIZE="30" class="shadeform">
</TD></TR><TR><TD>
Please confirm your e-Mail:
</TD></TR><TR><TD>
<INPUT TYPE="TEXT" NAME="email_confirm" SIZE="30" class="shadeform">
</TD></TR><TR><TD>
Security Code :[img]cgi-bin/CaptchaImages.php?width=100&height=40&characters=5[/img]
</TD></TR><TR><TD>
confirm Security Code :
<input id="security_code" name="security_code" type="text" SIZE="30" class="shadeform">
<input type="submit" value="submit" class="submitbutton"><input type="reset" value="Clear Form" class="submitbutton">
</td></tr></table>
</FORM>
</td></tr></table>
</center>
<center>
<TABLE BORDER="0" cellpadding="0" cellspacing="0" width="80%"><TR><TD>
<script language="JavaScript" type="text/javascript" src="contact.js"></script>
</td></tr></table>
</center>
</td><td width="5">
[img]picts/spacer.gif[/img]
</td></tr></table>
</td><td valign="top" width="40">
[img]picts/spacer.gif[/img]
</td></tr></table>
<span class ="footer"><script language="JavaScript" type="text/javascript" src="footer.js"></script>
</span>
</td></tr></table>
</BODY>
</HTML>
file register complete.php
-------------------<?php
session_start();
if( isset($_POST['submit'])) {
if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) {
// Insert you code for processing the form here, e.g emailing the submission, entering it into a database.
echo 'Thank you. Your message said "'.$_POST['message'].'"';
unset($_SESSION['security_code']);
} else {
// Insert your code for showing an error message here
echo 'Sorry, you have provided an invalid security code';
}
} else {
?>
<?php
}
?>
file captchaimmage.php
<?php
session_start();
class CaptchaSecurityImages {
var $font = 'monofont.ttf';
function generateCode($characters) {
/* list all possible characters, similar looking characters and vowels have been removed */
$possible = '23456789bcdfghjkmnpqrstvwxyz';
$code = '';
$i = 0;
while ($i < $characters) {
$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
return $code;
}
function CaptchaSecurityImages($width='120',$height='40',$c haracters='6') {
$code = $this->generateCode($characters);
/* font size will be 75% of the image height */
$font_size = $height * 0.75;
$image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
/* set the colours */
$background_color = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 20, 40, 100);
$noise_color = imagecolorallocate($image, 100, 120, 180);
/* generate random dots in background */
for( $i=0; $i<($width*$height)/3; $i++ ) {
imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
}
/* generate random lines in background */
for( $i=0; $i<($width*$height)/150; $i++ ) {
imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
}
/* create textbox and add text */
$textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
/* output captcha image to browser */
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
$_SESSION['security_code'] = $code;
}
}
$width = isset($_GET['width']) ? $_GET['width'] : '120';
$height = isset($_GET['height']) ? $_GET['height'] : '40';
$characters = isset($_GET['characters']) && $_GET['characters'] > 1 ? $_GET['characters'] : '6';
$captcha = new CaptchaSecurityImages($width,$height,$characters);
?>