Çäðàâñòâóéòå, îïûòà ó ìåíÿ ìàëî - ïðîøó áîëüíî íå ïèíàòü. Âîçíèêëà íåîáõîäèìîñòü âíåäðèòü Ðåãèñòðàöèþ/àâòîðèçàöèþ. íà ñàéò. Íàøåë ïîäõîäÿùèé
ñêðèïò, íî âîçíèêëè ïðîáëåìû ñ åãî âíåäðåíèåì. Êàê âïèõíóòü åãî íà èíäåêñíóþ è äðóãèå ñòðàíè÷êè, ñîîòâåòñòâåííî çàïðåòèâ ïðîñìîòð íåàâòîðèçîâàííûì ïîëüçîâàòåëÿì?
âîò êîä
ñêðèïòà:
PHP |
<? mysql_connect("localhost", "user", "12345"); mysql_select_db("users"); if(isset($_POST['submit'])) { $err = array(); if(!preg_match("/^[a-zA-Z0-9]+$/",$_POST['login'])) { $err[] = "Ëîãèí ìîæåò ñîñòîÿòü òîëüêî èç áóêâ àíãëèéñêîãî àëôàâèòà è öèôð"; } if(strlen($_POST['login']) < 3 or strlen($_POST['login']) > 30) { $err[] = "Ëîãèí äîëæåí áûòü íå ìåíüøå 3-õ ñèìâîëîâ è íå áîëüøå 30"; } $query = mysql_query("SELECT COUNT(user_id) FROM users WHERE user_login='".mysql_real_escape_string($_POST['login'])."'"); if(mysql_result($query, 0) > 0) { $err[] = "Ïîëüçîâàòåëü ñ òàêèì ëîãèíîì óæå ñóùåñòâóåò â áàçå äàííûõ"; } if(count($err) == 0) { $login = $_POST['login']; $password = md5(md5(trim($_POST['password']))); mysql_query("INSERT INTO users SET user_login='".$login."', user_password='".$password."'"); header("Location: login.php"); exit(); } else { print "<b>Ïðè ðåãèñòðàöèè ïðîèçîøëè ñëåäóþùèå îøèáêè:</b><br>"; foreach($err AS $error) { print $error."<br>"; } } } ?> <form method="POST"> Ëîãèí <input name="login" type="text"><br> Ïàðîëü <input name="password" type="password"><br> <i |
PHP |
mysql_select_db("users");
if(isset($_POST['submit'])) { $query = mysql_query("SELECT user_id, user_password FROM users WHERE user_login='".mysql_real_escape_string($_POST['login'])."' LIMIT 1"); $data = mysql_fetch_assoc($query); if($data['user_password'] === md5(md5($_POST['password']))) { $hash = md5(generateCode(10)); if(!@$_POST['not_attach_ip']) { $insip = ", user_ip=INET_ATON('".$_SERVER['REMOTE_ADDR']."')"; } mysql_query("UPDATE users SET user_hash='".$hash."' ".$insip." WHERE user_id='".$data['user_id']."'"); setcookie("id", $data['user_id'], time()+60*60*24*30); setcookie("hash", $hash, time()+60*60*24*30); header("Location: check.php"); exit(); } else { print "Âû ââåëè íåïðàâèëüíûé ëîãèí/ïàðîëü"; } } ?> <form method="POST"> Ëîãèí <input name="login" type="text"><br> Ïàðîëü <input name="password" type="password"><br> Íå ïðèêðåïëÿòü ê IP(íå áåçîïàñíî) <input type="checkbox" name="not_attach_ip"><br> <input name="submit" type="submit" value="Âîéòè"> </form> <?Location: check.php"); exit(); } else { print "Âû ââåëè íåïðàâèëüíûé ëîãèí/ïàðîëü"; } } ?> <form method="POST"> Ëîãèí <input name="login" type="text"><br> Ïàðîëü <input name="password" type="password"><br> Íå ïðèêðåïëÿòü ê IP(íå áåçîïàñíî) <input type="checkbox" name="not_attach_ip"><br> <input name="submit" type="submit" value="Âîéòè |
PHP |
<? mysql_connect("localhost", "user", "12345"); mysql_select_db("users");
if (isset($_COOKIE['id']) and isset($_COOKIE['hash'])) { $query = mysql_query("SELECT *,INET_NTOA(user_ip) FROM users WHERE user_id = '".intval($_COOKIE['id'])."' LIMIT 1"); $userdata = mysql_fetch_assoc($query);
if(($userdata['user_hash'] !== $_COOKIE['hash']) or ($userdata['user_id'] !== $_COOKIE['id']) or (($userdata['user_ip'] !== $_SERVER['REMOTE_ADDR']) and ($userdata['user_ip'] !== "0"))) { setcookie("id", "", time() - 3600*24*30*12, "/"); setcookie("hash", "", time() - 3600*24*30*12, "/"); print "Õì, ÷òî-òî íå ïîëó÷èëîñü"; } else { print "Ïðèâåò, ".$userdata['user_login'].". Âñ¸ ðàáîòàåò!"; } } else { print "Âêëþ÷èòå êóêè"; }< |
p.s. Õîòåëîñü áû åù¸ ðåàëèçîâàòü âîçìîæíîñòü ïîëüçîâàòåëþ ðåäàêòèðîâàòü ñâîé ïðîôèëü. Äà, è íàïîìèíàíèå ïàðîëÿ íà email.
Ñïóñòÿ 6 äíåé, 11 ÷àñîâ, 10 ìèíóò, 26 ñåêóíä (29.08.2009 - 00:18) ira2013 íàïèñàë(à):
Óâàæàåìûå Àäìèíû, îòâåòüòå ïîæàëóéñòà! ó ìåíÿ òà æå ïðîáëåìà. Óæå öåëóþ íåäåëþ ïðîáóþ ðàçíûå ñïîñîáû è íèêàê íå ïîëó÷àåòñÿ
Ñïóñòÿ 7 ÷àñîâ, 46 ìèíóò, 11 ñåêóíä (29.08.2009 - 08:04) twin íàïèñàë(à):