Потребител Парола | Регистрация | Забравена парола
Меню
· Начало
· Файлове
· Форум
· Връзки
· Категории на уроците
· За контакти
· Фото галерия
· Търсене
Кажи на приятел

Вашия email:
email на приятел:
Копие за вас?
Реклама

Логин система и новини без MySQL.

PHP & MySQLТук са представени няколко файла от логин система, регистър и новини за напреднали. Останалите могат да се изтеглят от линка в края на урока.



---==[index.php]==---
Код

<?
session_start();
header(\"Cache-control: private\");
ob_start();

error_reporting (E_ALL ^ E_NOTICE);
require \"functions.php\";

$PHP_SELF = \"index.php\";

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Login/Check/Logout

// Login
if($action == \"login\")
{
$result = FALSE;
$is_loged_in = FALSE;
$md5_password = md5($password);

$full_member_db = file(\"data/users.php\");
foreach($full_member_db as $member_db_line)
{
if(!eregi(\"<?\",$member_db_line))
{
$member_db = explode(\"|\",$member_db_line);
if(strtolower($member_db[2]) == strtolower($username) && $member_db[3] == $md5_password) { $result = TRUE; break; }
}
}

if($result == TRUE)
{
$_SESSION['joined'] = \"$member_db[0]\";
$_SESSION['permission'] = \"$member_db[1]\";
$_SESSION['user'] = \"$member_db[2]\";
$_SESSION['md5_password'] = \"$member_db[3]\";
$_SESSION['email'] = \"$member_db[4]\";
$_SESSION['url'] = \"$member_db[5]\";
$_SESSION['age'] = \"$member_db[6]\";
$_SESSION['location'] = \"$member_db[7]\";
$_SESSION['lastvisit'] = \"$member_db[8]\";

// Modify Last time loged in ////////////////////
$all_users_db = file(\"data/users.php\");
$old_users_db = $all_users_db;
$modified_users = fopen(\"data/users.php\", \"w\");
foreach($old_users_db as $old_users_db_line)
{
$old_users_db_arr = explode(\"|\", $old_users_db_line);
if($member_db[0] != $old_users_db_arr[0]) { fwrite($modified_users, \"$old_users_db_line\"); }
else
{
$time = time() + ($config_date_adjust * 3600);
fwrite($modified_users, \"$old_users_db_arr[0]|$old_users_db_arr[1]|$old_users_db_arr[2]|$old_users_db_arr[3]|$old_users_db_arr[4]|$old_users_db_arr[5]|$old_users_db_arr[6]|$old_users_db_arr[7]|$time||n\");
}
}
fclose($modified_users);
/////////////////////////////////////////////////

$is_loged_in = TRUE;
header(\"location: $PHP_SELF?id=modules/online&action=add&add_ip=$_SESSION[user]\");
}
else
{
$is_loged_in = FALSE;
header(\"location: $PHP_SELF?login_failed=1\");
}
}

// Check if user is loged in
if($is_guest == TRUE) { $is_loged_in = FALSE; }
elseif($is_user == TRUE) { $is_loged_in = TRUE; }
elseif($is_moderator == TRUE) { $is_loged_in = TRUE; }
elseif($is_administrator == TRUE) { $is_loged_in = TRUE; }

// Logout
if($action == \"logout\")
{
@session_destroy();
@session_unset();

header(\"location: $PHP_SELF?id=modules/online&action=remove&remove_ip=$_SESSION[user]\");
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Check if users/guests are online and if they are write them or remove them

$users_timeout_seconds = 60;
$ip = ipCheck();
$referer = $_SERVER['HTTP_REFERER'];
$lang = @explode(\",\", @getenv(\"HTTP_ACCEPT_LANGUAGE\"));
$lang = @strtolower($lang[0]);
$file = file(\"data/online.php\");
$past = time()-$users_timeout_seconds;
$now = time();

if(isset($_SESSION[user])) { $write = \"$_SESSION[user]|$_SESSION[email]|$_SESSION[permission]|$_SESSION[joined]|$now|$ip|$_SESSION[location]|member||n\"; }
if(!isset($_SESSION[user])) { $write = \"guest|$ip|$now|$referer|$lang||n\"; }

for($i=0;$i<count($file);$i++)
{
$visitdata = explode(\"|\", $file[$i]);
if($visitdata[4] > $past && $visitdata[0] != $_SESSION[user]) { $write .= \"$visitdata[0]|$visitdata[1]|$visitdata[2]|$visitdata[3]|$visitdata[4]|$visitdata[5]|$visitdata[6]||n\"; }
if($visitdata[2] > $past && $visitdata[1] != ipCheck()) { $write .= \"$visitdata[0]|$visitdata[1]|$visitdata[2]|$visitdata[3]|$visitdata[4]||n\"; }
}
if($ofile = @fopen(\"data/online.php\",\"w\"))
{
@fputs ($ofile, $write);
@fclose($ofile);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Show number of total members

$file = file(\"data/users.php\");
$TotalMembersCount = 0;

for($line = 0; $line < sizeof($file); $line++) $TotalMembersCount++;

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Show last registered user

$file = file(\"data/users.php\");
$totalLines = sizeof($file);

for($line = 0; $line < $totalLines; $line++) $lastmember_arr = explode(\"|\", $file[$line]);

if($TotalMembersCount == 0) $LastRegisteredMemberName = '';
else
{
$LastRegisteredMemberName = $lastmember_arr[2];
$LastRegisteredMemberId = $lastmember_arr[0];
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Show number of guests/members online

$file = file(\"data/online.php\");
$OnlineGuestsCount = \"0\";
$OnlineMembersCount = \"0\";

for($line = 0; $line < sizeof($file); $line++) { if(@\"guest\" == substr($file[$line], 0, 5)) $OnlineGuestsCount++; else $OnlineMembersCount++; }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Site Design Header

echo'
<html>
<head>
<title>Register</title>
<link href=\"extra/jupiter.css\" rel=\"stylesheet\" type=\"text/css\">
</head>

<body>
<div id=\"jupiterwrapper\">

<table width=\"100%\" style=\"border: 1px dashed #606060;\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td height=\"101\" background=\"images/main_header.jpg\" align=left><img src=\"images/logo.jpg\" border=\"0\" width=\"218\" height=\"101\" alt=\"\"></td>
</tr>
<tr>
<td height=\"15\" background=\"images/message.jpg\" align=left> » '; echo message(); echo'</td>
</tr>
<tr>
<td>
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">
<tr valign=\"top\">
<td width=\"160\" bgcolor=\"#f0f0f0\">
<table width=\"100%\" cellpadding=\"2\" cellspacing=\"5\" border=\"0\">
<tr valign=\"top\">
<td class=\"sidebar\">';

if($is_loged_in == FALSE)
{
echo'
<table class=\"main\" cellspacing=\"1\" cellpadding=\"4\" style=\"table-layout:fixed;\">
<form method=\"post\" action=\"'.$PHP_SELF.'\">
<tr>
<td class=\"head\" colspan=\"2\">Login</td>
</tr>
<tr>
<td class=\"con1\" align=\"right\">Username:</td>
<td class=\"con1\"><input type=\"text\" id=\"user\" name=\"username\" style=\"width:100%\" maxlength=\"25\" class=\"box\" tabindex=\"1\"></td>
</tr>
<tr>
<td class=\"con1\" align=\"right\">Password:</td>
<td class=\"con1\"><input type=\"password\" name=\"password\" style=\"width:100%\" maxlength=\"25\" class=\"box\" tabindex = \"2\"></td>
</tr>
<tr>
<td class=\"con1\" align=\"right\"><input type=\"button\" name=\"register\" style=\"width:100%\" class=\"box\" value=\"Register\" onclick=window.location.href=\"'.$PHP_SELF.'?id=modules/register\"></td>
<td class=\"con1\" align=\"left\"><input accesskey=\"s\" type=\"submit\" name=\"submit\" style=\"width:100%\" class=\"box\" value=\"Login\" tabindex = \"3\"></td>
</tr>
<input type=\"hidden\" name=\"action\" value=\"login\">
</form>
</table>';
}

elseif($is_loged_in == TRUE)
{
echo'
<table class=\"main\" cellspacing=\"1\" cellpadding=\"4\" style=\"table-layout:fixed;\">
<tr>
<td class=\"head\">Control Panel</td>
</tr>';

if($is_user == TRUE)
{
echo'
<tr><td class=\"con1\"><a href=\"'.$PHP_SELF.'?id=modules/main\">Users HQ</a></td></tr>
<tr><td class=\"con1\"><a href=\"'.$PHP_SELF.'?id=modules/panel\">Profile</a></td></tr>
<tr><td class=\"con1\"><a href=\"'.$PHP_SELF.'?action=logout\">Logout</a></td></tr>';
}
if($is_moderator == TRUE)
{
echo'
<tr><td class=\"con1\"><a href=\"'.$PHP_SELF.'?id=modules/main\">Mods HQ</a></td></tr>
<tr><td class=\"con1\"><a href=\"'.$PHP_SELF.'?id=modules/panel\">Profile</a></td></tr>
<tr><td class=\"con1\"><a href=\"'.$PHP_SELF.'?action=logout\">Logout</a></td></tr>';
}
if($is_administrator == TRUE)
{
echo'
<tr><td class=\"con1\"><a href=\"'.$PHP_SELF.'?id=modules/main\">Admins HQ</a></td></tr>
<tr><td class=\"con1\"><a href=\"'.$PHP_SELF.'?id=modules/panel\">Profile</a></td></tr>
<tr><td class=\"con1\"><a href=\"'.$PHP_SELF.'?id=modules/users\">Users list</a></td></tr>
<tr><td class=\"con1\"><a href=\"'.$PHP_SELF.'?action=logout\">Logout</a></td></tr>';
}

echo'</table>';
}

echo'
<table><tr><td></td></tr></table>

<table class=\"main\" cellspacing=\"1\" cellpadding=\"4\" style=\"table-layout:fixed;\">
<tr>
<td class=\"head\">Statistici:</td>
</tr>
<tr>
<td class=\"con1\"><a href=\"'.$PHP_SELF.'?id=modules/users&action=view_users\">Total Members: '.$TotalMembersCount.'</a></td>
</tr>
<tr>
<td class=\"con1\"><a href=\"'.$PHP_SELF.'?id=modules/users&action=stand_alone&userid='.$LastRegisteredMemberId.'\">Last Registered: '.$LastRegisteredMemberName.'</a></td>
</tr>
<tr>
<td class=\"con1\"><a href=\"'.$PHP_SELF.'?id=modules/online&action=members\">Members Online: '.$OnlineMembersCount.'</a></td>
</tr>
<tr>
<td class=\"con1\"><a href=\"'.$PHP_SELF.'?id=modules/online&action=guests\">Guests Online: '.$OnlineGuestsCount.'</a></td>
</tr>
</table>

</td>
</tr>
</table>
</td>
<td bgcolor=\"#cccccc\" background=\"extra/line.gif\" width=\"1\"></td>
<td bgcolor=\"#f0f0f0\">
<table cellpadding=\"0\" cellspacing=\"5\" width=\"100%\">
<tr>
<td class=\"sidebar\" valign=\"top\">';

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// PHP Navigation (?id=)

if(!isset($_GET['id']))
{
include(\"news.php\");
}

if(isset($_GET['id']))
{
$id = $_GET['id'];
if(file_exists(\"$id.php\"))
{
include(\"$id.php\");
}
elseif(!file_exists(\"$id.php\"))
{
echo '
<table class=\"main\" cellspacing=\"1\" cellpadding=\"4\" width=\"100%\">
<tr><td class=\"head\">Error 404</td></tr>
<tr><td class=\"con1\">404 Error page cannot be found</tr>
</table>';
}
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Site Design Footer

echo'

</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>

</div>

</body>
</html>';

ob_end_flush();
?>






---==[functions.php]==---

Код

<?

$is_guest = TRUE;
$is_user = FALSE;
$is_moderator = FALSE;
$is_administrator = FALSE;

if($_SESSION['permission'] == 1) { $is_user = TRUE; $is_guest = FALSE; }
if($_SESSION['permission'] == 2) { $is_moderator = TRUE; $is_guest = FALSE; }
if($_SESSION['permission'] == 3) { $is_administrator = TRUE; $is_guest = FALSE; }

if ($HTTP_SESSION_VARS) {extract($HTTP_SESSION_VARS, EXTR_SKIP); }
if ($_SESSION) {extract($_SESSION, EXTR_SKIP); }
if ($HTTP_COOKIE_VARS) {extract($HTTP_COOKIE_VARS, EXTR_SKIP); }
if ($_COOKIE) {extract($_COOKIE, EXTR_SKIP); }
if ($HTTP_POST_VARS) {extract($HTTP_POST_VARS, EXTR_SKIP); }
if ($_POST) {extract($_POST, EXTR_SKIP); }
if ($HTTP_GET_VARS) {extract($HTTP_GET_VARS, EXTR_SKIP); }
if ($_GET) {extract($_GET, EXTR_SKIP); }
if ($HTTP_ENV_VARS) {extract($HTTP_ENV_VARS, EXTR_SKIP); }
if ($_ENV) {extract($_ENV, EXTR_SKIP); }

if($PHP_SELF == \"\"){ $PHP_SELF = $HTTP_SERVER_VARS[\"PHP_SELF\"]; }

////////////////////////////////////////////////////////
// Function: message
// Description: Displays the message

function message()
{
if (@$_GET[\"login_failed\"]) echo \"<span class = 'alert'>Wrong Username or Password</span>\";
elseif (@$_GET[\"no_acces\"]) echo \"<span class = 'alert'>Acces denied</span>\";
elseif (@$_GET[\"login_succes\"]) echo \"<span class = 'ok'>Welcome \".$_SESSION[\"user\"].\"</span>\";
elseif (@$_GET[\"loged_out\"]) echo \"<span class = 'ok'>You have logged-out successfuly</span>\";

elseif (@$_GET[\"no_user\"]) echo \"<span class = 'alert'>Username can not be blank</span>\";
elseif (@$_GET[\"no_pass\"]) echo \"<span class = 'alert'>Password can not be blank</span>\";
elseif (@$_GET[\"no_mach_pass\"]) echo \"<span class = 'alert'>Passwords dosen't match to confirm</span>\";
elseif (@$_GET[\"no_email\"]) echo \"<span class = 'alert'>Email can not be blank</span>\";
elseif (@$_GET[\"email_invalid\"]) echo \"<span class = 'alert'>The Email is invalid</span>\";
elseif (@$_GET[\"mach_user\"]) echo \"<span class = 'alert'>Sorry that username already exist</span>\";
elseif (@$_GET[\"allready_reg\"]) echo \"<span class = 'normal'>You are allready registered</span>\";

elseif (@$_GET[\"user_modified\"]) echo \"<span class = 'ok'>You have modified the user successfuly</span>\";
elseif (@$_GET[\"user_deleted\"]) echo \"<span class = 'ok'>You have deleted the user successfuly</span>\";

elseif (@$_GET[\"unknown_error\"]) echo \"<span class = 'alert'>Error Occured</span>\";
else echo \"<span class = 'normal'>No message</span>\";
}

////////////////////////////////////////////////////////
// Function: ipCheck
// Description: Check the ip to the roots

function ipCheck()
{
if (getenv('HTTP_CLIENT_IP')) { $ip = getenv('HTTP_CLIENT_IP'); }
elseif (getenv('HTTP_X_FORWARDED_FOR')) { $ip = getenv('HTTP_X_FORWARDED_FOR'); }
elseif (getenv('HTTP_X_FORWARDED')) { $ip = getenv('HTTP_X_FORWARDED'); }
elseif (getenv('HTTP_FORWARDED_FOR')) { $ip = getenv('HTTP_FORWARDED_FOR'); }
elseif (getenv('HTTP_FORWARDED')) { $ip = getenv('HTTP_FORWARDED'); }
else { $ip = $_SERVER['REMOTE_ADDR']; }
return $ip;
}

////////////////////////////////////////////////////////
// Function: cuttext
// Description: Cuts a string and adds ..

function cuttext($tring,$cuton)
{
$space=\" \";
if (!strstr($tring,$space)) { $tring=substr($tring,0,$cuton); }
if (substr($tring,$cuton,1)==$space) { $tring=substr($tring,0,$cuton); }
else
{
while ($teller <= $cuton)
{
if (substr($tring,$cuton-$teller,1)==$space) { $tring=substr($tring,0,$cuton-$teller); break; }
$teller++;
}
}

$nr_tring = strlen($tring);
if($nr_tring >= $cuton) { echo $tring; echo\"..\"; }
else echo $tring;
}

?>






---==[news.php]==---

Код

<table class=\"main\" cellspacing=\"1\" cellpadding=\"4\" width=\"100%\">
<tr>
<td class=\"head\">News</td>
</tr>
<tr>
<td class=\"con1\"><p>Slagaite si novinite tuka :DDD</p>
<p>bY pWneD !!!</p>
</tr>
</table>






· ko6rata на January 19 2011 10:30:38 · 0 Коментари · 1510 Прочитания · Отпечатай
Коментари
Няма добавени коментари.
Напиши коментар
Моля влезте, за да коментирате.
Оценка
Рейтингите са достъпни само за регистрирани.

Моля влезте или се регистрирайте за да гласувате.

Няма оценки.
Вход
Потребител

Парола



Не сте регистрирани?
Натиснете тук за регистрация.

Забравена парола?
Натиснете тук за нова.
Анкета
С каква операционна система работите











Трябва да влезете за да гласувате.
ЧАТ
Трябва да влезате за да пуснете съобщение.

Няма съобщения.
Статистика