PHP Prihlasovanie
-
jorg22
Medium Professional
- Príspevky: 1087
- Registrovaný: 12 aug 2006, 20:39
- Kontaktovať používateľa:
PHP Prihlasovanie
Zdravim pls mate nejaky osvedceny PHP script na registraciu a prihlasovanie na stranke.Potrebujem nieco co je najlepsie zabezpecene proti hackerom a keby k tomu bolo aj vysvetlenie tak by bolo dobre.
THX
THX
-
caesar1987
Addict
- Príspevky: 3001
- Registrovaný: 02 okt 2005, 0:57
- Bydlisko: Nové Zámky
- Kontaktovať používateľa:
Na zaciatok si otvor SQL (v PHPMyadmin)
a zadaj:
registracia.php
subor odosli.php
subor login.php
subor loginz.php
mysql_connect("lmysqlserver","username","heslo"); zmen si udaje podla skutocnosti
mysql_select_db("databaza"); meno databazy
V SQL dopyte (to prve) si mozes zmenit policka a dorobit vlastne napr.
mail varchar(30) NOT NULL default '',
//pricom mail znamena nazov riadku a 30 je maximalna povolena dlzka riadku
Potom si mozes upravovat subor registracia.php podla toho ako chces, pridas si tam napr.
eMail:
<input type="text" name="mail" maxlength="30">
//prisposob to udajom v riadku databazy
Nasledne upravis odosli.php tieto veci
$mail=$_POST["mail"];
//je lepsie vzdy pridat nazov riadku
$query1="insert into users values (0,'$login','$pass','$icq')";
//pridas '$mail', takze to bude vyzerat:
$query1="insert into users values (0,'$login','$pass','$icq','$mail')";
//zase si tam mozes dat ine policko napr vek, len to editni v prikaze databazy a registracia.php + odosli.php
Pokial nevies s PHP tak je ti to nanic.
thanks to fruxo and ppt
a zadaj:
Kód: Vybrať všetko
CREATE TABLE users (
id int(10) NOT NULL auto_increment,
nick varchar(12) NOT NULL default '',
pass varchar(12) NOT NULL default '',
icq varchar(12) NOT NULL default '',
PRIMARY KEY (id)
);
Kód: Vybrať všetko
<?php
mysql_connect("lmysqlserver","username","heslo");
mysql_select_db("databaza");
$result=mysql_query($query);
mysql_close();
?>
<form action="odosli.php" method="POST">
Nick:
<input type="text" name="login" maxlength="12">
<br>
Heslo:
<input type="password" name="pass" maxlength="12">
<br>
ICQ:
<input type="text" name="icq" maxlength="12">
<br><br>
<input type="submit" value="Register">
</form>Kód: Vybrať všetko
<?
$login=$_POST["login"];
$pass=$_POST["pass"];
$icq=$_POST["icq"];
$obs="1";
mysql_connect("lmysqlserver","username","heslo");
mysql_select_db("databaza");
$query1="insert into users values (0,'$login','$pass','$icq')";
$result1=mysql_query($query1);
if ($result1) {
echo "Registration complete.";
}
else { echo "Niečo zblblo";}
mysql_close();
?>Kód: Vybrať všetko
<div class="form">
<form action="loginz.php" method="post">
<input type="hidden" name="sent" value="">
<div class="formrow">
<div class="formdesc">Login</div><div class="forminput"><input type="text" name="login" size="30" value="<?php if(IsSet($login)) echo $login; ?>" maxlength="50"></div>
</div>
<div class="formrow">
<div class="formdesc">Heslo</div><div class="forminput"><input type="password" name="pass" size="30" maxlength="12"></div>
</div>
<div class="formrowsubmit">
<input type="submit" name="send" value="Prihlas" class="submit">
</div>
</div>
</form>Kód: Vybrať všetko
<?
mysql_connect("lmysqlserver","username","heslo");
mysql_select_db("databaza");
$query = mysql_query("SELECT * FROM `users` WHERE `login`='".addslashes($_POST['login'])."' AND `pass`='".addslashes($_POST['pass'])."'");
$result1=mysql_num_rows($query);
if ($result1 != 0) {
echo "<title>";
echo "Uspesne prihlasenie, transfering to the index page...";
echo "</title>";
echo "<meta http-equiv='refresh' content='2;url=http://slayter.over.cz/index.php'>";
echo "Nespravny login alebo heslo.";
}
else { echo "Chyba v skripte";}
?>mysql_select_db("databaza"); meno databazy
V SQL dopyte (to prve) si mozes zmenit policka a dorobit vlastne napr.
mail varchar(30) NOT NULL default '',
//pricom mail znamena nazov riadku a 30 je maximalna povolena dlzka riadku
Potom si mozes upravovat subor registracia.php podla toho ako chces, pridas si tam napr.
eMail:
<input type="text" name="mail" maxlength="30">
//prisposob to udajom v riadku databazy
Nasledne upravis odosli.php tieto veci
$mail=$_POST["mail"];
//je lepsie vzdy pridat nazov riadku
$query1="insert into users values (0,'$login','$pass','$icq')";
//pridas '$mail', takze to bude vyzerat:
$query1="insert into users values (0,'$login','$pass','$icq','$mail')";
//zase si tam mozes dat ine policko napr vek, len to editni v prikaze databazy a registracia.php + odosli.php
Pokial nevies s PHP tak je ti to nanic.
thanks to fruxo and ppt
-
vivaSlovakia
Guru wannabe
- Príspevky: 2119
- Registrovaný: 29 júl 2006, 10:30
-
jorg22
Medium Professional
- Príspevky: 1087
- Registrovaný: 12 aug 2006, 20:39
- Kontaktovať používateľa:
php viem ale je to na mna dost narocne spravit to by mi trvalo par dni a radsej si najdem uz hotovi skript pripadne ho upravim pre seba.Chcel som nieco osvecene, nasiel som nieco
ale dole pisu ze to nieje dostatocne zabezpecene a nadarmo zlozite.
Nechcem aby ste mi ten script robili iba ak ste nejaky nasli na nete a osvedcil sa vam.
A co to je ta captcha?
Kód: Vybrať všetko
http://interval.cz/clanky/autorizacia-v-php-s-mysql/Nechcem aby ste mi ten script robili iba ak ste nejaky nasli na nete a osvedcil sa vam.
A co to je ta captcha?
skor ako budem exportovat tabulku, tak mi schvalte tento script. robil som jednoduchu registraciu a tiez primitivny login, ktory je podla mna (znalosti o hackerstve takmer nulove) zabezpeceny 
registracia
je tam aj plno riadkov, ktore treba vymazat ak nechces mat system fungujuci na pozvanky a tak...
log.php
staci vymazat nepotrebne riadky a ide to. no bez minimalnej znalosti php to bude kapanek problem
registracia
Kód: Vybrať všetko
<?php
if (isset($_POST['reg_login']) && ($_POST['reg_pass']) && ($_POST['reg_pass2']) && ($_POST['reg_mail']))
{
$reg_login=htmlspecialchars($_POST[reg_login]);
$reg_pass=htmlspecialchars($_POST[reg_pass]);
$reg_pass2=htmlspecialchars($_POST[reg_pass2]);
$reg_mail=htmlspecialchars($_POST[reg_mail]);
$invite_code=htmlspecialchars($_POST[reg_invite_code]);
$nonmd5pass=$reg_pass;
// login
$sql = MySQL_Query("Select * FROM $tab_users WHERE user_login='$reg_login'");
$pocet=Mysql_num_rows($sql);
$sql2 = MySQL_Query("Select * FROM $tab_users WHERE user_mail='$reg_mail'");
$pocet2=Mysql_num_rows($sql2);
$sql3=mysql_query("SELECT * FROM $tab_invites WHERE invite_code='$invite_code' AND invite_status='n'");
$pocet3=Mysql_num_rows($sql3);
if ($pocet > "0")
{
$err_login_exist = "1";
}
else
{
$err_login_exist = "ok";
$login=$reg_login;
}
// pass
if (!eregi("[[:alnum:]]{5,15}",$reg_pass))
{
$err_pass_lenght = "1";
}
else
{
$err_pass_lenght = "ok";
}
if (!eregi("[[:alnum:]]{5,15}",$reg_pass2))
{
$err_pass_lenght = "1";
}
else
{
$err_pass_lenght = "ok";
}
if ($reg_pass != $reg_pass2)
{
$err_pass_same = "1";
}
else
{
$err_pass_same = "ok";
}
// mail
if( !eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*"
."@([a-z0-9]+([\.-][a-z0-9]+))*$",
$reg_mail) )
{
$err_mail_syntax = "1";
}
else
{
$err_mail_syntax = "ok";
}
if ($pocet2 > "0")
{
$err_mail_exist = "1";
}
else
{
$err_mail_exist = "ok";
}
if ($pocet3 == "0")
{
$err_invite = "1";
}
else
{
$err_invite = "ok";
}
if ($err_login_exist == "1" || $err_pass_lenght == "1" || $err_pass_same == "1" || $err_mail_syntax == "1" || $err_mail_exist == "1" || $err_invite == "1")
{
$main .= "
$start_header Registrácia $end_header
<form method='post' action='$home_site/index.php?menu=registration'>
<table width='300'>
<tr>
<td><label>meno:</label></td>
<td align='right'><input type='text'";
if ($err_login_exist != "1")
{
$main .= "value='$reg_login'";
}
$main .= "
name='reg_login' /></td>
</tr>
<tr>
<td align='left'><label>heslo:</label></td>
<td align='right'><input type='password' name='reg_pass' /></td>
</tr>
<tr>
<td align='left'><label>heslo (overenie):</label></td>
<td align='right'><input type='password' name='reg_pass2' /></td>
</tr>
<tr>
<td align='left'><label>mail:</label></td>
<td align='right'><input type='text'";
if ($err_mail_exist != "1" && $err_mail_syntax != "1")
{
$main .= " value='$reg_mail' ";
}
$main .= "
name='reg_mail' /></td>
</tr>
<tr>
<td align='left'><label>pohlavie:</label></td>
<td align='right'>Muž<input type='radio' value='muž' name='reg_sex' checked /><br />
Žena<input type='radio' value='žena' name='reg_sex' />
</td>
</tr>
<tr>
<td align='left'><label>dátum narodenia: </label></td>
<td align='right'>";
$main .= "<select name='edit_birth_day'>";
$main .= print_check(edit_birth_day,select);
$main .= "</select>";
$main .= "<select name='edit_birth_month'>";
$main .= print_check(edit_birth_month,select);
$main .= "</select>";
$main .= "<select name='edit_birth_year'>";
$main .= print_check(edit_birth_year,select);
$main .= "</select>";
$main .= "
</td>
</tr>
<tr>
<td align='left'><label>Kód pozvánky:</label></td>
<td align='right'><input type='text' value='".$_GET[invite_code]."' name='reg_invite_code' /></td>
</tr>
<tr>
<td align='center' colspan='2'><br /><input type='submit' value='OK' /></td>
</tr>";
if ($err_login_exist == "1")
{
$main .= "
<tr>
<td colspan='2'><br />Zadané meno je už obsadené</td>
</tr>";
}
if ($err_invite == "1")
{
$main .= "
<tr>
<td colspan='2'><br />Kód pozvánky je neplatný</td>
</tr>";
}
if ($err_pass_lenght == "1")
{
$main .= "
<tr>
<td colspan='2'><br />Dĺžka hesla músí byť 5-15 znakov</td>
</tr>";
}
if ($err_pass_same == "1")
{
$main .= "
<tr>
<td colspan='2'><br />Heslá sa nezhodujú</td>
</tr>";
}
if ($err_mail_syntax == "1")
{
$main .= "
<tr>
<td colspan='2'><br />mail musí byť zadaný v tvare [email protected] ([email protected])</td>
</tr>";
}
if ($err_mail_exist == "1")
{
$main .= "
<tr>
<td colspan='2'><br />Tento mail používa niekto iný</td>
</tr>";
}
$main .="
</table>
</form>
";
}
if ($err_login_exist == "ok" && $err_pass_lenght == "ok" && $err_pass_same == "ok" && $err_mail_syntax == "ok" && $err_mail_exist == "ok" && $err_invite == "ok")
{
$reg_pass=md5($reg_pass);
$reg_pass=md5($reg_pass);
$keygen1 = substr (MD5(uniqid(rand(),1)), 10, 5);
$keygen2 = substr (MD5(uniqid(rand(),1)), 12, 8);
$auth = "$keygen1-$keygen2";
$datetime = date("Y:m:d"); // 10-kovy format
$m=$_POST['edit_birth_month'];
$y=$_POST['edit_birth_year'];
$d=$_POST['edit_birth_day'];
$sex=$_POST['reg_sex'];
mysql_query("UPDATE $tab_invites SET invite_status='$reg_login' WHERE invite_code='$invite_code'");
$ok1=mysql_query("INSERT INTO $tab_users (user_login, user_pass, user_sex, user_mail, user_birth_day, user_birth_month, user_birth_year, user_reg_date, user_auth, user_status) VALUES ('$reg_login', '$reg_pass', '$sex', '$reg_mail', '$d', '$m', '$y', '$unix_time_now', '$auth', 'n')");
$subject="$home_subject - registrácia";
$body="<html>
<head></head>
<body>
Ahoj <b>$reg_login</b>,
<br><br>
pre dokončenie registrácie klikni na link <br><a href='$home_site/activate.php?hash=$auth'>$home_site/activate.php?hash=$auth</a> <br>
<br>
Tvoje registračné úudaje:<br>
<br>
meno: <b>$reg_login</b><br>
heslo: <b>$nonmd5pass</b><br>
<br>
prihlásiť sa môžeš zo stránky <a href='$home_site/index.php'>nightlife.namieru.org/index.php</a>
$mail_footer
</body>
</html>
";
send_mail($reg_mail,$subject,$body);
if ($ok1)
{
header ("Location: $home_site/index.php?menu=result&result=reg_ok&mail=$reg_mail");
}
else
{
header ("Location: $home_site/index.php?menu=result&result=system_failed");
}
}
}
else {
$main .= "
$start_header Registrácia $end_header
<form method='post' action='$home_site/index.php?menu=registration'>
<table width='300'>
<tr>
<td><label>meno:</label></td>
<td align='right'><input type='text' name='reg_login' maxlength='15' /></td>
</tr>
<tr>
<td align='left'><label>heslo:</label></td>
<td align='right'><input type='password' name='reg_pass' /></td>
</tr>
<tr>
<td align='left'><label>heslo (overenie):</label></td>
<td align='right'><input type='password' name='reg_pass2' /></td>
</tr>
<tr>
<td align='left'><label>e-mail:</label></td>
<td align='right'><input type='text' name='reg_mail' /></td>
</tr>
<tr>
<td align='left'><label>pohlavie:</label></td>
<td align='right'>Muž<input type='radio' value='muž' name='reg_sex' checked /><br />
Žena<input type='radio' value='žena' name='reg_sex' />
</td>
</tr>
<tr>
<td align='left'><label>dátum narodenia: </label></td>
<td align='right'>";
$main .= "<select name='edit_birth_day'>";
$main .= print_check(edit_birth_day,select);
$main .= "</select>";
$main .= "<select name='edit_birth_month'>";
$main .= print_check(edit_birth_month,select);
$main .= "</select>";
$main .= "<select name='edit_birth_year'>";
$main .= print_check(edit_birth_year,select);
$main .= "</select>";
$main .= "
</td>
</tr>
<tr>
<td align='left'><label>Kód pozvánky:</label></td>
<td align='right'><input type='text' value='".$_GET[invite_code]."' name='reg_invite_code' /></td>
</tr>
<tr>
<td align='center' colspan='2'><br /><input type='submit' value='OK' /></td>
</tr>
</table>
</form>
";
}
?>
log.php
Kód: Vybrať všetko
<?php
$menu = $_GET['menu'];
if (!isset($menu))
{
$menu="start";
}
include ("./common/mysql_db.php");
ob_start();
session_start();
// overenie prihlasenia a funkcie
if(isset($_SESSION['user_login']))
{
$akcia = "out";
}
else
{
$akcia = $_GET['akcia'];
}
// odhlasenie a pod.
if($akcia == 'out')
{
MySQL_Query("UPDATE $tab_users SET user_online='no' WHERE user_id='".$_SESSION['user_id']."'");
unset($_SESSION['user_login']);
unset($_SESSION['user_id']);
unset($_SESSION['user_role']);
unset($_SESSION['new_mail']);
header("Location: $home_site/index.php");
die();
}
elseif($akcia == 'in')
{
$formtyp = 'login';
$title = " Prihlásenie";
if(isset($_POST['form_login']) && isset($_POST['form_pass']))
{
$osetrene['meno'] = htmlspecialchars($_POST[form_login]);
$osetrene['heslo'] = htmlspecialchars($_POST[form_pass]);
$heslo = MD5($osetrene[heslo]);
$heslo=md5($heslo);
$zisti = mysql_query("SELECT * FROM $tab_users WHERE user_login='$osetrene[meno]' AND user_pass='$heslo' ");
$kolko = @mysql_num_rows($zisti);
if($kolko == '1')
{
$dotycny = mysql_fetch_assoc($zisti);
$stav = $dotycny['user_status'];
if($stav == 'a')
{
MySQL_Query("UPDATE $tab_users SET user_online='yes', user_lastsend='$unix_time_now' WHERE user_id='$dotycny[user_id]'");
$_SESSION['user_login'] = $dotycny[user_login];
$_SESSION['user_id'] = $dotycny[user_id];
$zisti = mysql_query("SELECT * FROM $tab_admins WHERE admin_user='$dotycny[user_id]'");
$p=mysql_num_rows($zisti);
$admin=mysql_fetch_array($zisti);
if ($p == 1)
{
if ($admin[admin_role] == "admin")
{
$_SESSION['user_role'] = "admin";
}
else
{
$_SESSION['user_role'] = "mod";
}
}
$sql_mail=mysql_query("SELECT * FROM $tab_mail WHERE mail_whom='$dotycny[user_id]' AND mail_status='n'");
$new_mails=mysql_num_rows($sql_mail);
if (($dotycny[user_sex]) == "" || ($dotycny[user_birth_day]) == "" || ($dotycny[user_birth_month]) == "" || ($dotycny[user_birth_year]) == "")
{
//echo "$dotycny[user_sex] - $dotycny[user_birth_day] - $dotycny[user_birth_month] - $dotycny[user_birth_year]";die();
ob_end_clean();
header ("Location: $home_site/index.php?menu=edit_profile_birth_sex");
exit();
}
if ($new_mails > 0)
{
ob_end_clean();
header ("Location: $home_site/index.php?menu=mail&action=inbox");
exit();
}
ob_end_clean();
header ("Location: $home_site/$dotycny[user_id]");
exit();
}
elseif($stav == 'b')
{
header ("Location: $home_site/index.php?menu=result&result=login_banned");
}
elseif($stav == 'n')
{
header ("Location: $home_site/index.php?menu=result&result=n");
}
elseif($stav == 'j')
{
$now=time();
$jail=$dotycny[user_jail];
if ($now > $jail)
{
mysql_query("UPDATE $tab_users SET user_status='a', user_jail='0' WHERE user_id='$dotycny[user_id]'");
MySQL_Query("UPDATE $tab_users SET user_online='yes', user_lastsend='$now' WHERE user_id='$dotycny[user_id]'");
$_SESSION['user_login'] = $dotycny[user_login];
$_SESSION['user_id'] = $dotycny[user_id];
ob_end_clean();
header ("Location: $home_site/index.php?menu=result&result=login_ok&user_login=$dotycny[user_login]");
exit();
}
else
{
header ("Location: $home_site/index.php?menu=result&result=user_jail&user_id=$dotycny[user_id]");
die();
}
header ("Location: $home_site/index.php?menu=result&result=n");
}
else
{
header ("Location: $home_site/index.php?menu=result&result=system_failed");
}
}
else
{
header ("Location: $home_site/index.php?menu=result&result=bad_pass_or_login");
}
}
}
?>
tak susal som to
nazov domeny si nevsimajte
ale registrujem sa ......a ked sa chcem prihlasit vypise tuto chybu:
pls poradte co tam mam urobit aby to islo
dik
Kód: Vybrať všetko
www.problemchat.tym.sk/login.phpnazov domeny si nevsimajte
ale registrujem sa ......a ked sa chcem prihlasit vypise tuto chybu:
Kód: Vybrať všetko
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/free/tym.sk/p/problemchat/root/www/loginz.php on line 7
Chyba v skripte pls poradte co tam mam urobit aby to islo
dik
-
vivaSlovakia
Guru wannabe
- Príspevky: 2119
- Registrovaný: 29 júl 2006, 10:30
Kód: Vybrať všetko
<?php
session_start();
// **** VERIFY IMAGE GENERATOR *****
function generuj_heslo($dlzka)
{
mt_srand((double)microtime()*1000000); // inicializácia generátora náhodných čísiel
$moznosti= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$heslo="";
while(strlen($heslo) < $dlzka)
{
$heslo .= substr($moznosti, mt_rand(0, strlen($moznosti) - 1), 1);
}
return($heslo);
}
Header("Content-type: image/png");
// Vytvorenie obrázku a alokacia farieb
$obr=ImageCreate(130,50);
$cierna=ImageColorAllocate ($obr, 50, 50, 120);
$biela=ImageColorAllocate ($obr, 255, 255, 255);
$heslo = generuj_heslo(8);
$defx = 10;
$defy = 10;
// Zakreslíme reťazec
for($i=0;$i<strlen($heslo);$i++)
{
$x = ($defx+($i*13));
$y = ($defy+(mt_rand(0, 9)));
ImageString($obr, 5, $x, $y, $heslo[$i], $biela);
}
$_SESSION['verifykey'] = md5($heslo);
//Obrázok vytlačíme a zrušíme
ImagePNG($obr);
ImageDestroy($obr);
?>hmm toto vyzera zaujimavo, ale este by nebolo zle napisat k tomu, ze co vsetko treba spravit, aby sa to dalo hodit aj na stranku. ked som pod to dal echo, tak mi to nezobrazilo. asi kvoli tomu ze je tam ten header. a ked som doplnil pod to header a tam plain/text tak to neslo. mi to ponuklo subor na stiahnutie. nieco tomu tusim chyba. nejaky detail asi
Kód: Vybrať všetko
Header("Content-type: image/png");iframe je posledna moznost ako by som nieco riesil. toto nestoji za to aby som si kazil nejaku stranku iframomjorg22 napísal: turtlak69: Musis to pridat na stranku cez iframe.
chrono: jj presne tento header urcuje ze je to obrazok, ale ked chcem na stranke ten obrazok a dalsi text, tak neviem ako na to. toto pisem len cisto zo zvedavosti. overenie registracie mam cez mail, ale aj tento sposob ochrany ma zaujima. v buducnosti ho urcite niekde pouzijem
Celé som si to neprečítal, takže som sa vyjadril mierne nepresne. Pred 2-3 dňami tu niekto riešil niečo podobné.
Pozri toto: http://www.hojko.com/post674545.html#674545
Pozri toto: http://www.hojko.com/post674545.html#674545
pokud mi nekdo najde bezpectnostni chybu v tomto webu : a podari se mu hacknout account má u mě zdrojáky 
Kód: Vybrať všetko
http://www.freerun.cz/-
caesar1987
Addict
- Príspevky: 3001
- Registrovaný: 02 okt 2005, 0:57
- Bydlisko: Nové Zámky
- Kontaktovať používateľa:
no tak ani hacnut sa nebudem pokusat ale skus sa regnut a nechat prazdne udajeHacky napísal:pokud mi nekdo najde bezpectnostni chybu v tomto webu :a podari se mu hacknout account má u mě zdrojákyKód: Vybrať všetko
http://www.freerun.cz/
Kód: Vybrať všetko
Error, bad form fill
Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /var/www/web5/freerun.cz/freerun.cz/createmember.php on line 85prihlasovanie.,
Taketo jednoduche mi presne staci, len mam problem ze na tie stranky na ktore by sa mal dostat len lognuty user sa da dostat aj bez prihlasenia,. nevie mi niekto poradit?
http://www.jaknaweb.com/tipy-triky/php- ... ez-cookies
http://www.jaknaweb.com/tipy-triky/php- ... ez-cookies
Kód: Vybrať všetko
Pracuje na tomto principe: ak nie je uzivatel prihlaseny, teda nieje nastavene cookie if (true != $_COOKIE['name']) {, zobrazi sa formular, inak sa nastavi cookie s menom uzivatela na urcitu hodnotu setcookie("name", $value[1], time()+3600); - prihlasenie trva hodinu. Potom sa uz na kazdej chranenej stranke kontroluje, ci sa tam nedostal navstevnik inak ako cez index if (eregi("index.php?(.*)",$pravy)){. A odhlasenie je jednoduch-e vymaze sa cookie.
index.php
if (true != $_COOKIE['name']) {
?>
<form action='login.php' method='post' name='login'>
<input type='text' name='uname'/>
<input type='password' name='pswd' />
<input type='submit' value='prihlasit' />
</form>
<?php
}
else {
echo "<a href=\"logout.php\">Odhlás</a><br><a href=\"index.php?do=prva\">Prva</a> <a href=\"index.php?do=druha\">Druha</a>";
switch($do) {
case "prva": echo "Prva stranka"; break;
case "druha": echo "Druha stranka"; break;
}
echo "Prihlásený";
}
login.php
<?php
$uname=$_POST['uname'];
$pswd=$_POST['pswd'];
$pswd=md5($pswd);
$nick="nick";
$heslo="heslo";
$heslo=md5($heslo);
if (isset ($uname) && isset($pswd)&&($uname==$nick)&&($pswd==$heslo)) {
setcookie("name", $value[1], time()+3600); /* expire in 1 hour */
header('location:index.php');
}
else {echo 'login je v cudu<br />';
echo $uname." / ".$pswd;}
?>
a potom kazda stranka by mala obsahovat takuto kontrolu:
$adresa=$REQUEST_URI;
list($lavy,$pravy)=explode("/rs/",$adresa);
// /rs/ treba napisat adresar, kde su
//chranene stranky umiestnene
if (eregi("index.php?(.*)",$pravy)){
echo "Chranena stranka";
}
logout.php
$cookie=setcookie ('name','', time());
if ($cookie){
header ("location:index.php");
}