Система за регистрация.
Това е система за регистрация,вход,изход,промяна на профил и показване на всички регистрирани потребители.
За този скрипт трябва база с данни, затова влезте в phpmyadmin-a си и направете база данни по ваше желание (в скрипта е „register“).
След като направите базата данни може да затворите phpmyadmin-a си
и слагате този код:
CREATE TABLE `users` (
`id` int(11) NOT NULL auto_increment,
`username` varchar(30) NOT NULL default '',
`password` varchar(255) NOT NULL default '',
`email` varchar(40) NOT NULL default '',
`msn` varchar(250) NOT NULL default 'Not Specified',
`aim` varchar(250) NOT NULL default 'Not Specified',
`location` varchar(36) NOT NULL default 'Not Specified',
PRIMARY KEY (`id`)
) TYPE=MyISAM;Записвате и може да затворите PhpMyAdmin-a.
Сега следват кодовете:
Отворете някой текстов редактор (Notaped).
След това сложете в него следния код:
config.php
<?
ob_start(); // allows you to use cookies
$conn = mysql_connect("localhost","root","");
mysql_select_db(register) or die(mysql_error());
//fill in the above lines where there are capital letters.
$logged = MYSQL_QUERY("SELECT * from users WHERE id='$_COOKIE[id]' AND password = '$_COOKIE[pass]'");
$logged = mysql_fetch_array($logged);
//the above lines get the user's information from the database.
?>Текста в червено е името на базата данни. Ако искате да е друга базата данни сменете червения текст с базата данни която искате да е.
След това направете нов файл:
Login.php
<?
oB_start();
// allows you to use cookies.
include("config.php");
if (!$logged[username])
{
if (!$_POST[login])
{
echo("
<center><form method=\"POST\">
<table>
<tr>
<td align=\"right\">
Потребител: <input type=\"text\" size=\"15\" maxlength=\"25\" name=\"username\">
</td>
</tr>
<tr>
<td align=\"right\">
Парола: <input type=\"password\" size=\"15\" maxlength=\"25\" name=\"password\">
</td></tr><tr>
<td align=\"center\">
<input type=\"submit\" name=\"login\" value=\"Влез\">
</td></tr><tr>
<td align=\"center\">
<a href=\"register.php\">Регистрирай се</a>
</td></tr></table></form></center>");
}
if ($_POST[login]) {
// the form has been submitted. We continue...
$username=$_POST['username'];
$password = md5($_POST[password]);
// the above lines set variables with the submitted information.
$info = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error());
$data = mysql_fetch_array($info);
if($data[password] != $password) {
// the password was not the user's password!
echo "Грешен потребител или парола!";
}else{
// the password was right!
$query = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error());
$user = mysql_fetch_array($query);
// gets the user's information
setcookie("id", $user[id],time()+(60*60*24*5), "/", "");
setcookie("pass", $user[password],time()+(60*60*24*5), "/", "");
// the above lines set 2 cookies. 1 with the user's id and another with his/her password.
echo ("<meta http-equiv=\"Refresh\" content=\"0; URL=http://localhost/test\"/>Вие успешно влязохте в акаунта си.");
// modify the above line...add in your site url instead of yoursite.com
}
}
}
else
{
// we now display the user controls.
echo ("<center>Добре дошли <b>$logged[username]</b><br /></center>
<a href=\"editprofile.php\">Промени профила си</a><br />
<a href=\"members.php\">Виж всички регистрирани потребители</a><br />
<a href=\"logout.php\">Излез от акаунта си</a>");
}
?>В този код сменете само линка в червено с линка къв сайта Ви.
Logout.php
<?
ob_start();
setcookie("id", 2132421,time()+(60*60*24*5), "/", "");
setcookie("pass", loggedout,time()+(60*60*24*5), "/", "");
echo ("Вие успешно излязохте от акаунта си");
?>Тук няма какво да се сменя.
Members.php
<?
ob_start();
include("config.php");
if (!$_GET[user])
{
$getuser = mysql_query("SELECT * from users order by id asc");
while ($user = mysql_fetch_array($getuser))
{
// gets all the users information.
echo ("<a href=\"members.php?user=$user[username]\">$user[username]</a><br />\n");
// links to a page to view the user's profile.
}
}
ELSE
{
$getuser = mysql_query("SELECT * from users where username = '$_GET[user]'");
$usernum = mysql_num_rows($getuser);
if ($usernum == 0)
{
echo ("Няма потребители");
}
else
{
$profile = mysql_fetch_array($getuser);
echo ("<center><b>Профила на: $profile[username]</b><br /></center>
MSN Messenger: $profile[msn]<br />
AIM Messebger: $profile[aim]<br />
Location: $profile[location]<br />
Email адрес: $profile[email]");
// in the above code, we display the user's information.
}
}
?>Тук също няма какво да се променя.
Register.php
<?php
ob_start();
// allows you to use cookies
include("config.php");
//gets the config page
if ($_POST[register]) {
// the above line checks to see if the html form has been submitted
$username = $_POST[username];
$password = $_POST[pass];
$cpassword = $_POST[cpass];
$email = $_POST[emai1];
//the above lines set variables with the user submitted information
if($username==NULL|$password==NULL|$cpassword==NULL|$email==NULL) {
//checks to make sure no fields were left blank
echo "A field was left blank.";
}else{
//none were left blank! We continue...
if($password != $cpassword) {
// the passwords are not the same!
echo "Passwords do not match";
}else{
// the passwords are the same! we continue...
$password = md5($password);
// encrypts the password
$checkname = mysql_query("SELECT username FROM users WHERE username='$username'");
$checkname= mysql_num_rows($checkname);
$checkemail = mysql_query("SELECT email FROM users WHERE email='$email'");
$checkemail = mysql_num_rows($checkemail);
if ($checkemail>0|$checkname>0) {
// oops...someone has already registered with that username or email!
echo "The username or email is already in use";
}else{
// noone is using that email or username! We continue...
$username = htmlspecialchars($username);
$password = htmlspecialchars($password);
$email = htmlspecialchars($email);
// the above lines make it so that there is no html in the user submitted information.
//Everything seems good, lets insert.
$query = mysql_query("INSERT INTO users (username, password, email) VALUES('$username','$password','$email')");
// inserts the information into the database.
echo "You have successfully registered!";
}
}
}
}
else
{
// the form has not been submitted...so now we display it.
echo ("
<center>
<form method=\"POST\">
Потребителско име: <input type=\"text\" size=\"15\" maxlength=\"25\" name=\"username\"><br />
Парола: <input type=\"password\" size=\"15\" maxlength=\"25\" name=\"pass\"><br />
Повторете паролата: <input type=\"password\" size=\"15\" maxlength=\"25\" name=\"cpass\"><br />
Email адрес: <input type=\"text\" size=\"15\" maxlength=\"25\" name=\"emai1\"><br />
<input name=\"register\" type=\"submit\" value=\"Регистрирай се\">
</form>
</center>
");
}
?>И тук няма какво да променяте.
editprofile.php
<?
ob_start();
include("config.php");
if ($logged[username])
{
// the user is logged in! We continue...
if (!$_POST[update])
{
// the form hasn't been submitted. We continue...
$profile = mysql_query("SELECT * from users where username = '$logged[username]'");
$profile = mysql_fetch_array($profile);
// the above lines get the information so that it can be displayed in the html form.
echo("
<center><form method=\"POST\">
<table width=\"100%\">
<tr>
<td align=\"right\" width=\"25%\">
Location
</td>
<td align=\"left\">
<input type=\"text\" size=\"25\" maxlength=\"25\" name=\"locate\" value=\"$profile[location]\"></td>
</tr>
<tr>
<td align=\"right\" width=\"25%\">
MSN Messenger
</td>
<td align=\"left\">
<input size=\"25\" name=\"msn\" value=\"$profile[msn]\"></td>
</tr>
<tr>
<td align=\"right\" width=\"25%\">
AOL Messenger</td>
<td align=\"left\">
<input size=\"25\" name=\"aim\" value=\"$profile[aim]\"></td>
</tr>
<tr>
<td align=\"right\" width=\"25%\">
Email адрес</td>
<td align=\"left\">
<input size=\"25\" name=\"email\" value=\"$profile[email]\"></td>
</tr>
<tr>
<td align=\"center\">
</td>
<td align=\"left\">
<input type=\"submit\" name=\"update\" value=\"Обнови\"></td>
</tr>
</table>
</form>
</center>");
}
else
{
$email = htmlspecialchars($_POST[email]);
$aim = htmlspecialchars($_POST[aim]);
$msn = htmlspecialchars($_POST[msn]);
$locate = htmlspecialchars($_POST[locate]);
// the above lines get rid of all html.
echo ("Вашия профил е успешно обновен.");
$update = mysql_query("Update users set email = '$email',
msn = '$msn', aim = '$aim', location = '$locate' where username = '$logged[username]'");
// updates the information in the database.
}
}
else
{
// They aren't logged in!
echo ("<a href=\"login.php\">Не сте логнат</a>");
}
?>Това е.
Надявам се да Ви хареса 🙂
Демо няма защото се изисква MySQL, phpmyadmin и database.


