|
|
Модератор форума: Dimitro, LightInDarkness |
Форум » Web раздел » Web форум » PHP Код (Коррекция) |
PHP Код |
Кто может убрать регу на форум в коде и оставить только регу акков в бд,буду благодарен
/** <?php * @version $Id: default.php 20196 2011-01-09 02:40:25Z ian $ * @package Joomla.Site * @subpackage com_users * @copyright Copyright © 2005 - 2011 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt * @since 1.6 */ defined('_JEXEC') or die; /* JHtml::_('behavior.keepalive'); JHtml::_('behavior.tooltip'); JHtml::_('behavior.formvalidation'); require_once(JPATH_LIBRARIES.'/gantry/gantry.php'); $gantry->init(); gantry_import('core.utilities.gantryjformfieldaccessor'); ?> <div class="registration<?php echo $this->pageclass_sfx?>"> <?php if ($this->params->get('show_page_heading')) : ?> <h1><?php echo $this->escape($this->params->get('page_heading')); ?></h1> <?php endif; ?> <form id="member-registration" action="<?php echo JRoute::_('index.php?option=com_users&task=registration.register'); ?>" method="post" class="form-validate"> <?php foreach ($this->form->getFieldsets() as $fieldset): // Iterate through the form fieldsets and display each one.?> <?php $fields = $this->form->getFieldset($fieldset->name);?> <?php if (count($fields)):?> <fieldset> <?php if (isset($fieldset->label)):// If the fieldset has a label set, display it as the legend.?> <legend><?php echo JText::_($fieldset->label);?></legend> <?php endif;?> <dl> <?php foreach($fields as $field): $fa = new GantryJFormFieldAccessor($field); if ($fa->getType() == "text" || $fa->getType() == "password" || $fa->getType() == "email") $fa->addClass('inputbox'); ?> <?php if ($field->hidden):// If the field is hidden, just display the input.?> <?php echo $field->input;?> <?php else:?> <dt> <?php echo $field->label; ?> <?php if (!$field->required && (!$field->type == "spacer")): ?> <span class="optional"><?php echo JText::_('COM_USERS_OPTIONAL');?></span> <?php endif; ?> </dt> <dd><?php echo $field->input;?></dd> <?php endif;?> <?php endforeach;?> </dl> </fieldset> <?php endif;?> <?php endforeach;?> <div class="register-buttons"> <div class="readon"><button type="submit" class="validate button"><?php echo JText::_('JREGISTER');?></button></div> <a href="<?php echo JRoute::_('');?>" class="readon" title="<?php echo JText::_('JCANCEL');?>"><span><?php echo JText::_('JCANCEL');?></span></a> <input type="hidden" name="option" value="com_users" /> <input type="hidden" name="task" value="registration.register" /> <?php echo JHtml::_('form.token');?> <div class="clear"></div> </div> </form> </div> */ //<?php // Database Status const AUTH = 0; const FORUM = 1; // Type //const NULL = 0; const BOOL = 2; const INT = 4; const INTEGER = 8; const FLOAT = 16; const DOUBLE = 32; const NUMERIC = 64; const LONG = 128; const REAL = 256; const INFINITE = 512; const STRING = 1024; const ARRAY_CONST = 2048; //const NAN = 4096; // MYSQL Coding const MYSQL_CODING = 'SET NAMES utf8'; const MYSQL_CODING_DB = 'SET character_set_database = utf8'; // Symbol const // Latin const LOGIN = 0; const PASSWORD = 1; // Kirill const SURNAME = 2; const NAME = 3; const PATRONYMIC = 4; const EMAIL = 5; // Birth const BIRTH = 6; // Numeric const // Date const JOIN_DATE = 30; const LAST_LOGIN = 31; const BIRTHDAY = 32; // Double const PHONE = 33; const GLOBAL_ID = 99; class DBase { public $dbase; function __construct($database) { $this->dbase = $this->Connect($database); } function __destruct() { $this->Disconnect($this->dbase); unset($this->dbase); } public function Connect($database) { $config = array ( /*Auth*/ "auth" => "-", "host_ip_auth" => "-", "login_db_auth" => "-", "passw_db_auth" => "-", "port_db_auth" => "-", /*Forum*/ "forum" => "-", "host_ip_forum" => "-", "login_db_forum" => "-", "passw_db_forum" => "-", "port_db_forum" => "-" ); switch ($database): case AUTH: $db = $config['auth']; $host_ip = $config['host_ip_auth']; $login = $config['login_db_auth']; $password = $config['passw_db_auth']; $port = $config['port_db_auth']; break; case FORUM: $db = $config['forum']; $host_ip = $config['host_ip_forum']; $login = $config['login_db_forum']; $password = $config['passw_db_forum']; $port = $config['port_db_forum']; break; endswitch; $mysqli = new mysqli('p:'.$host_ip, $login, $password, $db, $port); if (mysqli_connect_errno()) { printf("Ошибка подключения Рє БД: %s\n", mysqli_connect_error()); exit(); } $mysqli->select_db($db); $mysqli->query(MYSQL_CODING); $mysqli->query(MYSQL_CODING_DB); return $mysqli; } public function Disconnect($mysqli) { if (empty($mysqli) || !$mysqli->ping()) if (!$mysqli->close()) return false; return true; } } class Kernel { public $layer_auth; public $layer_forum; function __construct() { $num = (func_num_args() == 0) ? 2 : func_num_args(); $array = ($num == 2) ? array( AUTH, FORUM ) : func_get_args(); for ($i = 0; $i < $num; $i++) switch ($array[$i]) { case AUTH: $this->layer_auth = new Auth; break; case FORUM: $this->layer_forum = new Forum; break; } } function __destruct() { unset($this->layer_auth); unset($this->layer_forum); } } class Basic { public function isChecked($typo, $const = GLOBAL_ID) { if (preg_match($this->GetRegular($const), trim($typo))) return true; return false; } public function isTrue($type) { if (isset($type) && $type != NULL && $type != 0) return true; return false; } public function checkPost($post) { if (preg_match("/script|http|<|>|<|>|SELECT|UNION|UPDATE|exe|exec|INSERT|tmp/i",$post)) return false; return true; } public function GetRegular($const) { $str = ""; switch ($const) { case LOGIN: case PASSWORD: $str = "/^[a-zA-Z0-9_-]+$/"; break; case SURNAME: case NAME: case PATRONYMIC: $str = "/^[Р°-СЏРђ-РЇa-zA-Z]+$/ui"; break; case PHONE: case GLOBAL_ID: $str = "/^[0-9]+$/"; break; case EMAIL: $str = "/^(?:[a-z0-9]+(?:[-_]?[.]?[a-z0-9]+)?@[a-z0-9]+(?:\.?[a-z0-9]+)?\.[a-z]{2,5})$/i"; break; case BIRTH: $str = "/^[0-9-]+$/"; break; default: break; } return $str; } } class PreparedLibrary { public function GetQuery($id) { $prepared = array ( "0" => "SELECT id FROM account WHERE username = ?", "1" => "INSERT INTO account (username, sha_pass_hash, email, expansion) VALUES ( ?, SHA1(CONCAT(UPPER( ? ),':',UPPER( ? ))), ?, 3)", "2" => "SELECT userid FROM user WHERE username = ?", "3" => "INSERT INTO user (username, password, passworddate, email, joindate, salt) VALUES ( ?, ?, NOW(), ?, unix_timestamp(NOW()), ?)", ); return $prepared[$id]; } public function setBindParamsType($value) { $count = count($value); $type = ''; for ($i = 0; $i < $count; $i++) $type = $type.($this->getSymbolType($this->getTypeValue($value[$i]))); return $type; } public function bindParams(&$stmt, $array) { $bind_names[] = $this->setBindParamsType($array); for ($i = 0; $i < count($array); $i++) { $bind_name = 'bind'.$i; $$bind_name = $array[$i]; $bind_names[] = &$$bind_name; } call_user_func_array(array($stmt, 'bind_param'), $bind_names); } public function bindResult(&$stmt) { $meta = $stmt->result_metadata(); while ($field = $meta->fetch_field()) { $var = $field->name; $$var = null; $fields[$var] = &$$var; } call_user_func_array(array($stmt, 'bind_result'), $fields); return $fields; } public function getTypeValue($value) { if (is_null($value)) return NULL; else if (is_bool($value)) return BOOL; else if (is_numeric($value)) { if (is_int($value)) return INT; else if (is_integer($value)) return INTEGER; else if (is_float($value)) return FLOAT; else if (is_double($value)) return DOUBLE; else return NUMERIC; } else if (is_string($value)) return STRING; else if (is_array($value)) return ARRAY_CONST; } public function getSymbolType($type) { $symbol = ''; switch ($type) { case BOOL: $symbol = 'b'; break; case INT: case INTEGER: $symbol = 'i'; break; case FLOAT: $symbol = 'f'; break; case DOUBLE: case NUMERIC: case LONG: case REAL: case INFINITE: $symbol = 'd'; break; case STRING: $symbol = 's'; break; case ARRAY_CONST: $symbol = 'a'; break; default: $symbol = NULL; break; } return $symbol; } } class Auth extends Basic { private $prepared; private $auth; function __construct() { $this->auth = new DBase(AUTH); $this->prepared = new PreparedLibrary(); } function __destruct() { $this->auth->Disconnect($this->auth->dbase); unset($this->auth); unset($this->prepared); } public function isExistedAccount($username) { $result = 0; $stmt = $this->auth->dbase->stmt_init(); $stmt->prepare($this->prepared->GetQuery(0)); $stmt->bind_param($this->prepared->getSymbolType($this->prepared->getTypeValue($username)), $username); if (!$stmt->execute()) echo $stmt->error; $stmt->bind_result($result); $stmt->fetch(); $stmt->close(); return (isset($result) && $result != NULL && $result != 0) ? false : true; } public function registerAccount($username, $email, $password) { $temp_array = array($username, $username, $password, $email); $stmt = $this->auth->dbase->stmt_init(); $stmt->prepare($this->prepared->GetQuery(1)); $this->prepared->bindParams($stmt, $temp_array); if (!$stmt->execute()) { echo $stmt->error; return false; } $stmt->close(); return true; } } class Forum extends Basic { private $prepared; private $forum; function __construct() { $this->forum = new DBase(FORUM); $this->prepared = new PreparedLibrary(); } function __destruct() { $this->forum->Disconnect($this->forum->dbase); unset($this->forum); unset($this->prepared); } public function isExistedAccount($username) { $result = 0; $stmt = $this->forum->dbase->stmt_init(); $stmt->prepare($this->prepared->GetQuery(2)); $stmt->bind_param($this->prepared->getSymbolType($this->prepared->getTypeValue($username)), $username); if (!$stmt->execute()) echo $stmt->error; $stmt->bind_result($result); $stmt->fetch(); $stmt->close(); return (isset($result) && $result != NULL && $result != 0) ? false : true; } public function registerAccount($username, $email, $password) { $salt = $this->createSalt(); $hash = $this->createPassword($password, $salt); $temp_array = array($username, $hash, $email, $salt); $stmt = $this->forum->dbase->stmt_init(); $stmt->prepare($this->prepared->GetQuery(3)); $this->prepared->bindParams($stmt, $temp_array); if (!$stmt->execute()) { echo $stmt->error; return false; } $stmt->close(); return true; } function createSalt() { $salt = ''; for ($i = 0; $i < 30; $i++) $salt .= chr(rand(33, 126)); return $salt; } function createPassword($password, $salt) { return md5(md5($password).$salt); } } $kernel = new Kernel; $auth = $kernel->layer_auth; $forum = $kernel->layer_forum; $captcha = false; $message = ''; if (isset($_SESSION['captcha'])) $captcha = $_SESSION['captcha']; if (isset($_POST['code']) && $_POST['code'] == $captcha && $_POST['code'] != false) { if (isset($_POST['account']) && $auth->checkPost($_POST['account']) && $auth->isChecked($_POST['account'], LOGIN) && strlen($_POST['account']) < 16 && strlen($_POST['account']) > 2) { if ($auth->isExistedAccount($_POST['account']) && $forum->isExistedAccount($_POST['account'])) { if (isset($_POST['email']) && $auth->checkPost($_POST['email']) && $auth->isChecked($_POST['email'], EMAIL)) { if (isset($_POST['password']) && $auth->checkPost($_POST['password']) && $auth->isChecked($_POST['password'], PASSWORD) && strlen($_POST['password']) > 5 && strlen($_POST['password']) < 16) { if (isset($_POST['password2']) && $_POST['password'] == $_POST['password2']) { if ($auth->registerAccount($_POST['account'], $_POST['email'], $_POST['password']) && $forum->registerAccount($_POST['account'], $_POST['email'], $_POST['password'])) $message .= 'Aккаунт успешно зарегистрирован! <br />'; else $message .= 'Ошибка. Обратитесь Рє Администратору! <br />'; } else $message .= 'Неверно заполнено поле "Повторите пароль" <br />'; } else $message .= 'Неверно заполнено поле "Пароль" <br />'; } else $message .= 'Неверно заполнено поле "РР». почта" <br />'; } else $message .= 'Аккаунт СЃ таким именем уже существует, попробуйте РґСЂСѓРіРѕР№ <br />'; } else $message .= 'Неверно заполнено поле "Аккаунт" <br />'; } else { session_unset(); $message .= ($captcha != false) ? 'Неверно введен РєРѕРґ СЃ картинки <br />' : ''; } $captcha = array(); $coordx = array('10', '40', '70'); $myImage = imagecreate(103,40); $color[0] = imagecolorallocate($myImage, 0, 0, 0); $color[1] = imagecolorallocate($myImage, 255, 102, 102); $color[2] = imagecolorallocate($myImage, 0, 255, 102); $color[3] = imagecolorallocate($myImage, 51, 255, 204); $color[4] = imagecolorallocate($myImage, 0, 0, 255); $color[5] = imagecolorallocate($myImage, 255, 255, 0); $color[6] = imagecolorallocate($myImage, 255, 0, 102); $color[7] = imagecolorallocate($myImage, 255, 255, 255); $num = array( '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'); for ($i = 0; $i < 3; $i++) $captcha[$i] = $num[rand(0, 34)]; $_SESSION['captcha'] = implode($captcha); for ($i = 0; $i < 3; $i++) imagefttext($myImage, 20, rand(-10, 15), $coordx[$i], rand(25,30), $color[rand(1, 7)], "./comic.ttf", $captcha[$i]); $file= '/captcha/'.md5($_SESSION['captcha'].rand(0, 256)).'.png'; $png = $_SERVER['DOCUMENT_ROOT'].$file; imagepng($myImage, $png); echo " <script type=\"text/javascript\"> function isAlphaNumeric(value) { if (value.match(/^[a-zA-Z0-9_]+$/)) return true; return false; } function checkform(f) { if (f.account.value == \"\") { alert(\"Введите логин\"); return false; } if (!isAlphaNumeric(f.account.value)) { alert(\"Запрещенные символы РІ логине\"); return false; } if (f.password.value==\"\") { alert(\"Введите пароль\"); return false; } if (!isAlphaNumeric(f.password.value)) { alert(\"Запрещенные символы РІ пароле\"); return false; } if (f.password2.value==\"\") { alert(\"Р’С‹ РЅРµ ввели повтор пароля\"); return false; } if (f.password.value != f.password2.value) { alert(\"Пароли РЅРµ совпадают\"); return false; } if (f.email.value==\"\") { alert(\"Р’С‹ РЅРµ ввели e-mail\"); return false; } } </script>"; echo ' <div id="rt-mainbody"> <div class="component-content"> <div class="registration"> <form id="member-registration" method="post" class="form-validate" onsubmit=\"return checkform(this)\"> <fieldset> <legend>Регистрация аккаунта:</legend> <dl> <dt> <label id="jform_username-lbl" for="jform_username" class="hasTip required" title="">Логин<span class="star"> *</span></label> </dt> <dd> <input type="text" name="account" id="jform_username" value="" class="validate-username required inputbox" size="30" aria-required="true" required="required"> </dd> <dt> <label id="jform_password1-lbl" for="jform_password1" class="hasTip required" title="">Пароль<span class="star"> *</span></label> </dt> <dd> <input type="password" name="password" id="jform_password1" value="" autocomplete="off" class="validate-password required inputbox" size="30" aria-required="true" required="required"> </dd> <dt> <label id="jform_password2-lbl" for="jform_password2" class="hasTip required" title="">Повтор пароля<span class="star"> *</span></label> </dt> <dd> <input type="password" name="password2" id="jform_password2" value="" autocomplete="off" class="validate-password required inputbox" size="30" aria-required="true" required="required"> </dd> <dt> <label id="jform_email1-lbl" for="jform_email1" class="hasTip required" title="">Адрес электронной почты<span class="star"> *</span></label> </dt> <dd> <input type="email" name="email" class="validate-email required inputbox" id="jform_email1" value="" size="30" aria-required="true" required="required"> </dd> <dt> <label id="jform_captcha-lb1" for="jform_captcha" class="hasTip required" title="">РљРѕРґ СЃ картинки<span class="star"> *</span></label> </dt> <dd> <img src="'.$file.'"><br /><input type="text" name="code" class="validate-username required inputbox" id="jform_captcha" value="" size="30" aria-required="true" required="required"> </dd> </dl> </fieldset> <p align="center">'.$message.'</p> <div class="register-buttons"> <div class="readon"> <button type="submit" class="validate button">Регистрация</button> </div> <div class="clear"></div> </div>
YOU CAN DO IT
|
| |||
| |||