niko42
Новичок
Здравствуйте.
Форма
Обработчик
Ситуация такова, к сожалению, не проверяет if($_COOKIE['test'] == 1) и не выдает нужную форму.
P.S. протестирова простенький код
2.php
index.php
В этом варианте отлично работает.=((
Форма
PHP:
<?php
if($_COOKIE['test'] == 1){ // проверяем существуют ли куки
setcookie("test","1",time()+1);
echo 'Вы зарегены';
}
else{
echo <<<EOT
<form id="formID" class="formular" method="post" action="modul/reg2.php">
<table>
<tr>
<td>login: </td>
<td><input class="validate[required,custom[noSpecialCaracters],length[4,16],custom[onlyLetter]]" type="text" name="account" maxlength="16"></td>
</tr>
<tr>
<td>password: </td>
<td><input class="validate[required,length[6,16],custom[noSpecialCaracters],custom[onlyLetter]] text-input" type="password" name="password" id="password" maxlength="16"></td>
</tr>
<tr>
<td>repeat password: </td>
<td><input class="validate[required,confirm[password]] text-input" type="password" name="password2" maxlength="16"></td>
</tr>
<tr>
<td>E-mail: </td>
<td><input class="validate[required,custom[email]] text-input" type="text" name="email" maxlength="50"></td>
</tr>
<tr>
<td>
<p>
<a href="#reg_form" onClick="document.getElementById('image').src='modul/captcha.php?sid='+Math.round(1000 * Math.random());">reload</a>
</p>
code:
</td>
<td>
<img src="modul/captcha.php?sid=<?php echo rand(10000, 99999); ?>" width="120" height="25" alt="" id='image'/>
<p><input class="validate[required]" type='text' name='captcha'></p>
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center;">
<input type=image src="images/reg_button.png" name="submit" value="Зарегестрироваться"/>
</td>
</tr>
</table>
</form>
EOT;
}
?>
PHP:
if ($page="index.php" && $_POST['account'] && strlen($_POST['account'])<=16
&& $_POST['password'] && $_POST['password2'] && $_POST['password']==$_POST['password2']
&& $_POST['email'] && strlen($_POST['email'])<=30 && $_POST['captcha']){
if(count($_POST)>0){
if ( isset($_POST['captcha']) )
{
$code = $_POST['captcha']; //--Получаем введенную пользователем капчу
session_start();
//--Сравниваем
if ( isset($_SESSION['captcha']) && strtoupper($_SESSION['captcha']) == strtoupper($code) ){
$Login = mysql_connect("$host:$port", "$user", "$pass", True);
mysql_selectdb("$db2", $Login);
mysql_query("INSERT INTO accounts (login, password, lastactive, access_level, lastIP, email, points) VALUES ('".$_POST['account']."', '". pass_encode($_POST['password']) ."', NULL, 0, NULL, '".$_POST['email']."', 0)", $Login);
switch (mysql_errno())
{
case 0:
setcookie("test","1",time()+3600); //создаем куки
header("refresh:1;url=http://test1.ru/#reg_form" );
break;
case 1062: print '<p>К сожалению, такой аккаунт уже существует.</p>';
break;
default: print 'Error '.mysql_errno().': '.mysql_error();
break;
}
}
else{
echo 'Err!';
}
//--Удаляем из сессии код капчи
unset($_SESSION['captcha']);
}
}
}
P.S. протестирова простенький код
2.php
PHP:
<?php
setcookie("test","Hello",time()+3600);
header("Refresh:5, url=http://test2.ru/index.php");
?>
PHP:
echo $_COOKIE['test'];