|
|
|
|
|
для: cheops
(06.11.2005 в 23:44)
| | 1) А для чего вы глушите ошибки в первой строке кода? Соответственно вы не увидите их вывода...
2)Что вы подразумеваете под админкой? Привиденный код до того нечитаем, что разбираться кому-либо будет сложно...
Почему бы не сделать так, как это МУДРО описано в книге Л. Веллинга и Л. Томсон, за исключением того, что показана на примере работа с базой данных:
Файл authmain.php
<?php
session_start();
if (isset($HTTP_POST_VARS['userid']) && isset($HTTP_POST_VARS['password']))
{
// if the user has just tried to log in
$userid = $HTTP_POST_VARS['userid'];
$password = $HTTP_POST_VARS['password'];
$db_conn = mysql_connect('localhost', 'webauth', 'webauth');
mysql_select_db('auth', $db_conn);
$query = 'select * from auth '
."where name='$userid' "
." and pass=password('$password')";
$result = mysql_query($query, $db_conn);
if (mysql_num_rows($result) >0 )
{
// if they are in the database register the user id
$HTTP_SESSION_VARS['valid_user'] = $userid;
}
}
?>
<html>
<body>
<h1>Home page</h1>
<?
if (isset($HTTP_SESSION_VARS['valid_user']))
{
echo 'You are logged in as: '.$HTTP_SESSION_VARS['valid_user'].' <br />';
echo '<a href="logout.php">Log out</a><br />';
}
else
{
if (isset($userid))
{
// if they've tried and failed to log in
echo 'Could not log you in';
}
else
{
// they have not tried to log in yet or have logged out
echo 'You are not logged in.<br />';
}
// provide form to log in
echo '<form method="post" action="authmain.php">';
echo '<table>';
echo '<tr><td>Userid:</td>';
echo '<td><input type="text" name="userid"></td></tr>';
echo '<tr><td>Password:</td>';
echo '<td><input type="password" name="password"></td></tr>';
echo '<tr><td colspan="2" align="center">';
echo '<input type="submit" value="Log in"></td></tr>';
echo '</table></form>';
}
?>
<br>
<a href="members_only.php">Members section</a>
</body>
</html>
|
Файл logout.php
<?php
session_start();
$old_user = $HTTP_SESSION_VARS['valid_user']; // store to test if they *were*
logged in
unset($HTTP_SESSION_VARS['valid_user']);
session_destroy();
?>
<html>
<body>
<h1>Log out</h1>
<?php
if (!empty($old_user))
{
echo 'Logged out.<br />';
}
else
{
// if they weren't logged in but came to this page somehow
echo 'You were not logged in, and so have not been logged out.<br />';
}
?>
<a href="authmain.php">Back to main page</a>
</body>
</html>
|
Файл members_only.php
<?php
session_start();
echo '<h1>Members only</h1>';
// check session variable
if (isset($HTTP_SESSION_VARS['valid_user']))
{
echo '<p>You are logged in as '.$HTTP_SESSION_VARS['valid_user'].'</p>';
echo '<p>Members only content goes here</p>';
}
else
{
echo '<p>You are not logged in.</p>';
echo '<p>Only logged in members may see this page.</p>';
}
echo '<a href="authmain.php">Back to main page</a>';
?>
|
Спасибо книгам...
Файлы в прикрепленном архиве. | |
|
|
|
|
|
|
|
для: Irbis
(06.11.2005 в 22:25)
| | >Вот написал я код для админки...но вот проблема одна..когда я захожу на неё он сразу
>показывает чтобы я ввёл пароль в сразу всё для администрирование!!!что делать ??
А что нужно? | |
|
|
|
|
|
|
| Вот написал я код для админки...но вот проблема одна..когда я захожу на неё он сразу показывает чтобы я ввёл пароль в сразу всё для администрирование!!!что делать ??
Вот код admin.php
<?
error_reporting(0);
if (file_exists("passwd.dat") && $QUERY_STRING != ""):
require ("passwd.dat");
if (!isset($alogin) || md5($pass) != $Password[$alogin] || !isset($Password[$alogin])):
$logined = 0;
$error = "Неверный логин или пароль!<br>";
setcookie("alogin","",0);
setcookie("pass","",0);
else:
$logined = 1;
setcookie("alogin",$alogin);
setcookie("pass",$pass);
endif;
endif;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Администрирование</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
</head>
<style>
A:hover {COLOR: #FF0066}
a {text-decoration : none}
</style>
<body link="#000000" vlink="#000000" bgcolor="#ffffe6">
<table width=600 border=0 cellspacing=1 cellpadding=3 bgcolor=#CCCCCC>
<tr>
<td align=center class=p bgcolor=#E8E8FF>
<b>Администрирование</b>
</td>
</tr>
</table>
<?
if (!file_exists("passwd.dat") && $QUERY_STRING == "login"):
echo "</td></tr><tr><td><table border=0 cellpadding=0 cellspacing=0 width=600 height=4><tr><td height=4></td></tr></table><table width=600 border=0 cellspacing=1 cellpadding=3 bgcolor=#CCCCCC><tr><td align=center class=p bgcolor=#FFFFFF>Сейчас будет создан файл с паролем...</b></td></tr></table>";
if (isset($alogin) and $alogin != "" and isset($pass) and $pass != ""):
$file = fopen("passwd.dat","w");
fputs($file,"<?php\r\n\$Password['$alogin'] = \"".md5($pass)."\";\r\n?>");
fclose($file);
echo "</td></tr><tr><td><table border=0 cellpadding=0 cellspacing=0 width=600 height=4><tr><td height=4></td></tr></table><table width=600 border=0 cellspacing=1 cellpadding=3 bgcolor=#CCCCCC><tr><td align=center class=p bgcolor=#FFFFFF>Файл с паролем создан успешно!</b></td></tr></table>";
echo "</td></tr><tr><td><table border=0 cellpadding=0 cellspacing=0 width=600 height=4><tr><td height=4></td></tr></table><table width=600 border=0 cellspacing=1 cellpadding=3 bgcolor=#CCCCCC><tr><td align=center class=p bgcolor=#FFFFFF><b>Теперь можете смело входить в админ.центр! Удачи!</b></td></tr></table>";
else: echo "</td></tr><tr><td><table border=0 cellpadding=0 cellspacing=0 width=600 height=4><tr><td height=4></td></tr></table><table width=600 border=0 cellspacing=1 cellpadding=3 bgcolor=#CCCCCC><tr><td align=center class=p style=\"color:#FFFFFF\" bgcolor=#FF0000><b>Файл с паролем не создан! Недостаточно параметров!</b></td></tr></table>";
endif;
endif;
if ($logined):
include("config.inc.php");
function cut($string)
{
$string = ereg_replace('\\\"',""",$string);
$string = ereg_replace("\\\'",""",$string);
$string = str_replace(":",":",$string);
$string = str_replace("\r","",$string);
$string = str_replace("\n","<br>",$string);
$string = str_replace("%","%",$string);
$string = str_replace("^ +","",$string);
$string = str_replace(" +$","",$string);
$string = str_replace(" +"," ",$string);
return ($string);
}
else:
if($error!="") echo "</td></tr><tr><td><table border=0 cellpadding=0 cellspacing=0 width=600 height=4><tr><td height=4></td></tr></table><table width=600 border=0 cellspacing=1 cellpadding=3 bgcolor=#CCCCCC><tr><td align=center class=p style=\"color:#FFFFFF\" bgcolor=#FF0000><b>$error</b></td></tr></table>";
?>
<table width=600 border=0 cellspacing=1 cellpadding=3 bgcolor=#CCCCCC>
<form action=../../admin.php?login method=post>
<tr>
<td bgcolor=#E8E8FF align=center>
<b>Вход в админ.центр:</b>
</td>
</tr>
<tr>
<td bgcolor=#FFFFFF>
<table>
<tr>
<td width=210 align=right>
Логин:
</td>
<td class=p width=390 align=left>
<input type=text name=alogin size=30>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor=#FFFFFF>
<table>
<tr>
<td width=210 align=right>
Пароль:
</td>
<td width=390 align=left>
<input type=password name=pass size=30>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align=center bgcolor=#FFFFFF>
<input type=submit value="Войти" style="width:100px;cursor:hand;" onmouseover="this.style.backgroundColor='#E8E8FF';" onmouseout="this.style.backgroundColor='#FFFFFF';">
</td>
</tr>
</form>
</table>
<?php
if (!file_exists("passwd.dat"))
echo "</td></tr><tr><td><table border=0 cellpadding=0 cellspacing=0 width=600 height=4><tr><td height=4></td></tr></table><table width=600 border=0 cellspacing=1 cellpadding=3 bgcolor=#CCCCCC><tr><td align=center class=p bgcolor=#FFFFFF>Вы входите в админ.центр в первый раз!<br>Введите любой логин и пароль (они будут использоваться и в будущем).</td></tr></table>";
endif;
?>
<h2 align="center">Удаление фотографий</h2>
<?
$directory ="..";
$readfolder = opendir($directory);
while($file = readdir($readfolder))
{
if($file != ".." && $file != ".") $files[] = $file;
}
closedir($readfolder);
for($n=0;$n<count($files);$n++)
{
?>
<table border="1">
<tr>
<td>
<?
if (substr($files[$n],-4) == ".jpg") echo "<a href=delete.php?filename=$directory/"."$files[$n]>$files[$n]</a><br>";
?>
</td>
<td>X</td>
</tr>
</table>
<?
}
?>
<h2 align="center">Новости</h2>
<form action="../../msg.php" method="get">
<textarea name="msg" cols="" rows="" >
<? $fp = fopen ("../msg.dat", "r");
$buffer = fread($fp, 200);
fclose ($fp);
print $buffer;
?>
</textarea><br>
<input name="Изменить" type="submit">
</form>
<h2 align="center">Сообщение между админами</h2>
<font size="-1">В разработке.........</font>
</body>
</html> | |
|
|
|
|