Во общим вот скрипт!
Файл: index.php
Корневой!
<?php
require_once 'library/access.php';
require_once 'library/config.php';
require_once 'library/functions.php';
$user = new stdClass();
foreach( $_REQUEST as $key=>$val ) $user->$key = sanitize($val);
?>
<HTML>
<HEAD>
<title>Панель управления</title>
<meta charset="utf-8">
<link href="css/trontastic/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="js/jquery.js"></script>
<script src="js/jquery-ui.js"></script>
</HEAD>
<BODY style='background:transparent url(css/trontastic/images/ui-bg_diagonals-small_50_262626_40x40.png) repeat 0 0 scroll;'>
<div>
<div style="float: left; padding: 10px; margin-top: 50px;">
<script>
$(function() {
$( "#menu" ).menu();
});
</script>
<style>
.ui-menu { width: 200px; }
p {padding: 10px;}
</style>
<ul id="menu">
<li><a href="index.php">Панель управления</a></li>
<li>
<a href="#"><span class="ui-icon ui-icon-person"></span>Пользователи</a>
<ul>
<li><a href="index.php?p=affeliates">Партнеры</a></li>
<li><a href="#">Клиенты</a></li>
<li><a href="#">Менеджеры</a></li>
</ul>
</li>
<li><a href="<?php echo $logoutAction ?>"><span class="ui-icon ui-icon-power"></span>Выход</a></li>
</ul>
</div>
<div style="float: left" class="ui-widget-content" style="width:90%; max-width:1200px; min-width:900px;" >
<div style="width: 900px; height: 700px; ">
<?php
switch ($_GET['p']) {
case "panel": require_once 'pages/panel.php'; break;
case "affeliates": require_once 'pages/affeliates.php'; break;
default: require_once 'pages/panel.php'; break;
}
?>
</div>
</div>
</BODY>
</HTML>
---------------------------------------------------------------------------------------------------- -------------------
Подключаем файл: access.php
<?php
session_start();
require_once('config.php');
require_once('functions.php');
$AuthorizedUsers = "Менеджер,Партнер,Клиент";
$MainURL = "../";
$logoutAction = "index.php?doLogout=true";
if ($_SERVER['QUERY_STRING'] != "") $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
if ($_GET['doLogout'] == "true"){
unset($_SESSION['MM_Username']);
unset($_SESSION['MM_UserGroup']);
unset($_SESSION['PrevUrl']);
header("Location: $MainURL");
exit;
}
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$AuthorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$qsChar = "?";
$Referrer = $_SERVER['PHP_SELF'];
if (strpos($MainURL, "?")) $qsChar = "&";
if (strlen($_SERVER['QUERY_STRING']) > 0)
$Referrer .= "?" . $_SERVER['QUERY_STRING'];
$MainURL = $MainURL. $qsChar . "accesscheck=" . urlencode($Referrer);
header("Location: ". $MainURL);
exit;
}
$CurrentLogin=$_SESSION['MM_Username'];
Подключаем файл: config.php
<?php
$hostname_connect = "localhost";
$database_connect = "masterphp";
$username_connect = "root";
$password_connect = "";
$connect = mysql_pconnect($hostname_connect, $username_connect, $password_connect) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database_connect);
@mysql_query ("set character_set_client='utf8'");
@mysql_query ("set character_set_results='utf8'");
@mysql_query ("set collation_connection='utf8_unicode_ci'");
Подключаем файл: functions.php
<?php
function cleanInput($input) {
$search = array(
'@<script[^>]*?>.*?</script>@si',
'@<[\/\!]*?[^<>]*?>@si',
'@<style[^>]*?>.*?</style>@siU',
'@<![\s\S]*?--[ \t\n\r]*>@'
);
$output = preg_replace($search, '', $input);
return $output;
}
function sanitize($input) {
if (is_array($input)) {
foreach($input as $var=>$val) {
$output[$var] = sanitize($val);
}
}
else {
if (get_magic_quotes_gpc()) {
$input = stripslashes($input);
}
$input = cleanInput($input);
$output = mysql_real_escape_string($input);
}
return $output;
}
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
$isValid = False;
if (!empty($UserName)) {
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && false) {
$isValid = true;
}
}
return $isValid;
}
function alert($head, $body) {
echo '<div align="left" class="ui-widget" style="margin: 20px; ">
<div class="ui-state-highlight ui-corner-all" style="margin-top: 20px; padding: 1.7em;">
<span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>
<strong >'.$head.' </strong> '.$body.'
</div>
</div>';
return true;
}
function alert_animated($head, $body) {
echo "<script>";
echo '$("';
echo"<div align='left' id='info_message'>";
echo "<div class='ui-widget' style='width: 90%; max-width:1200px; margin: 20px auto; padding: 10px;'><div class='ui-state-highlight ui-corner-all' style='width: 90%; max-width:1200px; margin: 0px auto; padding: 10 .7em;'><p><span class='ui-icon ui-icon-info' style='float: left; margin-right: .3em;'></span><strong>";
echo $head;
echo "</strong>";
echo $body;
echo'</p></div></div></div>").appendTo("#place_to_message");';
echo "$('#info_message').hide();";
echo "$('#info_message')";
echo " .fadeIn(3000,";
echo " function(){})";
echo " .fadeOut(6000, ";
echo " function(){";
echo " $(this).remove();";
echo " });";
echo "</script>";
return true;
}
function say_error($head, $body) {
echo "<div align='left' id='error_message'><div class='ui-widget' style='width: 90%; max-width:1200px; margin: 20px auto; padding: 10px;'><div class='ui-state-error ui-corner-all' style='width: 90%; max-width:1200px; margin: 0px auto; padding: 10 .7em;'><p><span class='ui-icon ui-icon-alert' style='float: left; margin-right: .3em;'></span><strong>".$head."</strong>".$body."</p></div></div></div>";
return true;
}
function say_error_animated($head, $body) {
echo "<script>";
echo '$("';
echo"<div align='left' id='error_message'>";
echo "<div class='ui-widget' style='width: 90%; max-width:1200px; margin: 20px auto; padding: 10px;'><div class='ui-state-error ui-corner-all' style='width: 90%; max-width:1200px; margin: 0px auto; padding: 10 .7em;'><p><span class='ui-icon ui-icon-alert' style='float: left; margin-right: .3em;'></span><strong>";
echo $head;
echo "</strong>";
echo $body;
echo'</p></div></div></div>").appendTo("#place_to_message");';
echo "$('#error_message').hide();";
echo "$('#error_message')";
echo " .fadeIn(3000,";
echo " function(){})";
echo " .fadeOut(6000, ";
echo " function(){";
echo " $(this).remove();";
echo " });";
echo "</script>";
return true;
}
function get_data_affeliate($id,$data) {
$ResultQuery=mysql_query ("SELECT
$data
FROM
affeliates
WHERE
id_user='$id'");
return mysql_result($ResultQuery,0,$data);
}
function is_email($email) {
if (isset($email))
if(filter_var($email, FILTER_VALIDATE_EMAIL))
return true;
else
return false;
}
Ну а это страница регистрации: _register.php
<?php
require_once 'config.php';
require_once 'functions.php';
$user = new stdClass();
foreach( $_REQUEST as $key=>$val ) $user->$key = sanitize($val);
if (strlen($user->login)<5) {
say_error_animated("Ошибка: ", "Логин меньше 5 символов!");
exit();
}
if (strlen($user->password)<5) {
say_error_animated("Ошибка: ", "Пароль меньше 5 символов!");
exit();
}
if (!is_email($user->email)) {
say_error_animated("Ошибка: ", "Email введен не верно!");
exit();
}
if (strlen($user->firstname)<2) {
say_error_animated("Ошибка: ", "Имя меньше 2 символов!");
exit();
}
if (strlen($user->lastname)<2) {
say_error_animated("Ошибка: ", "Фамилия меньше 2 символов!");
exit();
}
if (strlen($user->city)<2) {
say_error_animated("Ошибка: ", "Город меньше 2 символов!");
exit();
}
$sql="SELECT
*
FROM
users
WHERE
(login='$user->login') OR (email='$user->email')";
$result = mysql_query($sql);
if (mysql_num_rows($result)){
say_error_animated("Ошибка: ", "Такой партнер уже зарегистрирован!");
exit();
}
$user->password=md5($user->password);
$sql="INSERT INTO
users
VALUES(
NULL,
'$user->login',
'$user->password',
'$user->email',
'Партнер'
)";
$result = mysql_query($sql) or die(say_error_animated("Ошибка: ", mysql_error()));
$sql="SELECT
*
FROM
users
WHERE
(login='$user->login') AND (email='$user->email')";
$result = mysql_query($sql);
$user->id_user=mysql_result($result ,0,'id');
$sql="INSERT INTO
affeliates
VALUES(
NULL,
'$user->id_user',
'$user->firstname',
'$user->lastname',
'$user->city',
'$user->url',
'$user->description_site',
'$user->subscribers'
)";
$result = mysql_query($sql) or die(say_error_animated("Ошибка: ", mysql_error()));
if ($result)
alert("Внимание! ",$user->firstname.", Вы успешно зарегистрированы!<br> Используйте свой логин и пароль для входа в партнерскую программу: <a href='index.php?p=login'><u>Войти.</u></a>");
Это страница авторизации: authorization.php
<?php
session_start();
require_once('config.php');
require_once('functions.php');
$level = "level";
$url_success = "/engine/";
if (isset($_GET['accesscheck'])) $_SESSION['PrevUrl'] = $_GET['accesscheck'];
if (isset($_POST['login'])) {
$login= sanitize($_POST['login']);
$password=md5(sanitize($_POST['password']));
$query=sprintf(
"SELECT
login, password, level
FROM
users
WHERE
login=%s AND password=%s",
GetSQLValueString($login, "text"),
GetSQLValueString($password, "text")
);
$result = mysql_query($query) or die(mysql_error());
$count = mysql_num_rows($result);
if ($count===1) {
if (PHP_VERSION >= 5.1) session_regenerate_id(true); else session_regenerate_id();
$_SESSION['MM_Username'] = $login;
$ResultQuery = mysql_query ("SELECT * FROM `users` WHERE (login='$login') ");
while($Result=mysql_fetch_array($ResultQuery)){
$level=$Result[4];
}
$_SESSION['MM_UserGroup'] = $level;
if (isset($_SESSION['PrevUrl']))
$url_success = $_SESSION['PrevUrl'];
header("Location: " . $url_success );
} else
say_error("Ошибка: ","Неправильно введена пара логин/пароль.");
}
Вот из этого хочу создать форму регистрации и авторизации как описсал в теме!!!