Comunque per non avere errori:
Index5.php
Codice PHP:
<?php
session_start();
function check($user, $password) {
include('utenti5.php');
foreach($utenti as $user_ => $password_) {
if($user == $user_ && $password == $password_) {
return true;
}
}
return false;
}
function form_login(){
echo '<form id="login" action="',$_SERVER['PHP_SELF'],'" method="post">
<div style="text-align:center;margin-left:auto;margin-right:auto;">
<p><img src="captcha5.php" alt="captcha codice" name="captcha" width="233" height="49" id="captcha" /></p>
<p class="style10"><strong><em>*Inserisci il testo che vedi nell\'immagine:</em></strong></p>
<font color="white">
<p class="style1">
<input name="txt_captcha" type="text" id="txt_captcha" style="width:174px;height:23px" class="style5" />
<a href="index5.php">
<img alt=""src="images/Refresh.png" width="25" height="19" class="style9"></a>
<span class="style28"><strong><a href="index5.php">refresh</a></strong></span></p>
</font>
<span class="style6"><strong><em>Utente</em></strong></span><font color="white">:<br>
<input type="text" name="utente" size="20" maxlength="255"><br>
</font>
<span class="style6"><strong><em>Password:</em></strong></span><font color="white"><br>
<input type="password" name="password" size="20" maxlength="255"><br><br>
<input type="submit" value="OK">
<br>
<br>
</div>
</form>';
}
$a = false;
if(isset($_POST['utente'],$_POST['password'],$_POST['txt_captcha'])){
if(check($_POST['utente'],$_POST['password'])){
$a = true;
$_SESSION['utente']=$_POST['utente'];
$_SESSION['password']=$_POST['password'];
if($_POST['txt_captcha']==$_SESSION['session_captchaText'])
{
header('Location: moneteregpay5.php');
}
else
{
unset($_SESSION['utente'],$_SESSION['password'],$_SESSION['session_captchaText']);
form_login();
}
}else{
unset($_SESSION['session_captchaText']);
form_login();
}
}else{
form_login();
}
?>
areariservata5.php
Codice PHP:
<?php
session_start();
if(isset($_SESSION['utente'],$_SESSION['password'],$_SESSION['session_captchaText'])){
echo 'arrivato a destinazione';
unset($_SESSION['utente'],$_SESSION['password'],$_SESSION['session_captchaText']);
}else{
header('Location: index5.php');
}
?>
utenti5.php
Codice PHP:
<?
$utenti["pinco"] = "prova";
?>
captcha5.php
Codice PHP:
<?php
session_start();
header('Content-type: image/png');
$captchaImage = imagecreatefrompng('captcha5.png') or die('Cannot Initialize new GD image stream');
$captchaFont = imageloadfont('font.gdf');
$captchaText = substr(md5(uniqid('')),-9,9);
$_SESSION['session_captchaText'] = $captchaText;
$captchaColor = imagecolorallocate($captchaImage,200,200,200);
imagestring($captchaImage,$captchaFont,15,5,$captchaText,$captchaColor);
imagepng($captchaImage);
imagedestroy($captchaImage);
?>
e naturalmente il file captcha5.png