Просмотр файла register.php

Размер файла: 4.44Kb
<?php
// This is main page;

require './config.php';
tmp_page (to_utf('Регистрация'));
echo '<p>';

if (!isset($_GET['rules']) && $accept!='reg')
	{

		echo to_utf ('Прежде чем регистрироваться, ознакомтесь с '). utf_url($this_uri.'?rules', 'правилами!').'<br/><br/>';

		echo to_utf ('*Имя:<br/>') . '<input type="text" name="name" maxlength="25"/><br/>';
		echo to_utf ('*Ник:<br/>') . '<input type="text" name="nick" maxlength="25"/><br/>';
		echo to_utf ('*Пароль:<br/>') .'<input type="password" name="pass" maxlength="12"/><br/>';
		echo to_utf ('*Возраст:<br/>').'<input type="text" name="age" format="*N" maxlength="2"/><br/>';
		echo to_utf ('*День рождения:<br/>') . '<input type="text" name="birth" format="*N" maxlength="2"/><br/>';
		echo to_utf ('*Месяц рождения:<br/>'). '<input type="text" name="bmonth" format="*N" maxlength="2"/><br/>';
		echo to_utf ('E-Mail:<br/>') .'<input type="text" name="mail" maxlength="25"/><br/>';
		echo to_utf ('*Пол: ') . 	  '<select name="pol">
									  <option value="j">'. to_utf ('Ж') . '</option>
									  <option value="m">'. to_utf ('М') . '</option>
									  </select>
									  <br/>
									  ';
		echo to_utf ('О себе:<br/>') . '<input type="text" name="about" maxlength="100"/><br/>';
									  
echo utf_url ($this_uri,'Регистрация',2,array('name','nick','pass','age','mail','pol','about','birth','bmonth', 'accept'=>'reg'));
echo '<br/><br/>? *'.to_utf('помечены поля обязательные для заполнения!'); 
	}
	
	elseif (!isset($_GET['rules']) && $accept=='reg')
		{
		
		  function checkmail ($address) 
			{
			   $return = false;
			   if (preg_match ('/^[\w.-]+@([\w.-]+)\.[a-z]{2,6}$/i', $address, $domain)) {
				 $domain = explode ('.', $domain[0]);
				 foreach ($domain as $part) { 
					 if (substr ($part, 0, 1) == '_' || substr ($part, strlen ($part) - 1, 1) == '_')
					   $return = false; 
					 else
					   $return = true; 
				 }
			   }
			   return $return;
			};

			$name=stripslashes(htmlspecialchars(substr($_POST['name'],0,25), ENT_QUOTES));
			$nick=stripslashes(htmlspecialchars(substr($_POST['nick'],0,25), ENT_QUOTES));
			$about=stripslashes(htmlspecialchars(substr($_POST['about'],0,25), ENT_QUOTES));
			$pass=substr($_POST['pass'],0,25);
			$age=(int)$_POST['age'];
			$birth=(int)substr($_POST['birth'],0,2);
			$bmonth=(int)substr($_POST['bmonth'],0,2);
			$pol=substr($_POST['pol'],0,1);
			
				$useragent = htmlentities(getenv('HTTP_USER_AGENT'));
				$userip = $_SERVER['REMOTE_ADDR'];
				$userhost = gethostbyaddr(getenv('REMOTE_ADDR'));
				
				$error = '';
				
				$clone = sql("select `nick` from `users` where `nick`='$nick';");
				
				if ($clone[0]==$nick)$error.='Пользователь с таким логином уже есть!<br/>';
				if (empty($name)) $error.= 'Не указано Ваше имя<br/>';
				if (empty($pass)) $error.= 'Не указан пароль<br/>';
				if (!preg_match('/([0-9a-z_]+)/i',$pass)) $error.= 'В пароле обнаружены запрещенные символы<br/>';
				if (empty($pol)) $error.= 'Не указан Ваш пол<br/>';
				if (!empty($mail) && !checkmail($mail)) $error.= 'Формат эл. почты неверный<br/>';
				if (empty($birth))$error .= 'Не указан день рождения<br/>';
				if (empty($bmonth))$error .='Не указан месяц рождения<br/>';
				if ($birth < 1 || $birth > 31) $error .= 'Неверный формат дня рождения<br/>';
				if ($bmonth <1 || $bmonth >12) $error .= 'Неверный формат месяца рождения<br/>';
				
					if ($error==false)
						{
						$sql="insert into `users` Values('','$nick','$name','".md5($pass)."','$birth', '$bmonth',
														 '$age','$pol','$mail','$about', '$useragent', '$userip', 
														 '$userhots','0','','','','');";
						mysql_query($sql);
						
						$cr_dir=sql("select `id` from `users` where `nick`='$nick' && `name`='$name' && pass='".md5($pass)."';");
												
						echo to_utf (
							"Регистрация прошла успешно!<br/>Дождитесь пока модераторы проверят Ваши данные,".
							"и вы сможете добавить свои фотографии.<br/>".
							"Для перхода к редактированию анкеты, нажмите ").
							utf_url('./profile.php','Сюда',2,array('id'=>$cr_dir[0],'pass'=>$pass));

			 }
			  else {
				 	echo to_utf ('Добавление анкеты невозможно по следующим причинам:<br/>'.$error); 
					echo utf_url ($this_uri, 'Назад');
				  }
		}
			
			else
				{
					  if (file_exists($rules))
							 echo @to_utf(implode("", file($rules)));
						
						else 
							 echo to_utf('Правил фотоальбома не найдено!');
				};
				
echo '</p>';
echo '<p align="center">'. utf_url ('./', 'Фотоальбом') . '<br/>' . $copy . '<br/>';
tmp_foot();

?>