Snazim se napsat nektery scripty pro svuj web . Kvuli zjednoduseni a zamezeno chyb jsem pouzil hotovy scripty na registraci a prihlasovani. Registrace funguje bez problemu, ale prihlasovani ani omylem. Obvykle kdyz skusim zadat jmeno a heslo, tak se script bez niceho vrati zpet . Kod prikladam.
<?php
require("config.php") ;
$connection = mysql_connect($dbhost, $dbuser, $dbpass)or die ("Nemohu otevrit server");
$db = mysql_select_db("$dbname", $connection) or die ("Nemohu otevrit vybrat datab?zi");
$_SESSION['login'] = 'login';
$_SESSION['password'] = 'password';
$_SESSION['opravneni'] = 'opravneni';
if (isset($_POST['submit'])) {
$select = mysql_query("SELECT `login`,`password`,`opravneni` FROM `uzivatel` WHERE `login`='".addslashes($_POST['login'])."' AND
`password`='".md5(trim($_POST['password'])."'")) or die (mysql_error());
$udaje = mysql_fetch_assoc($select);
if (mysql_num_rows($select)==1) {
session_regenerate_id();
$_SESSION['login'] = $_POST['login'];
$_SESSION['password'] = md5($_POST['password']);
$_SESSION['opravneni'] = $udaje['opravneni'];
if($udaje == 1){
header("Location:admin/index.php");}
elseif($udaje == 2){
header("Location:index.php");}
}
}
/*odhlaseni*/
if (isset($_GET['logout'])) {
unset($_SESSION['login']);
unset($_SESSION['password']);
unset($_SESSION['opravneni']);
session_destroy();
}
isset($_GET['code']) && $_GET['code']=="401" ?
$title = "Neautorizovaný přístup (Chyba 401)" :
$title = "Přihlášení";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title><?php echo $title ?></title>
</head>
<body>
<form action="#" method="post">
<fieldset>
<legend><b><?php echo $title ?></b></legend>
<p><input name="login" size="20" tabindex="1" type="text" /> <label>Jmeno</label></p>
<p><input name="password" size="20" tabindex="2" type="password" /> <label>Heslo</label></p>
<p><input name="submit" type="submit" tabindex="3" value="Odeslat" /></p>
</fieldset>
</form>
<?php if (isset($_GET['logout'])) { ?>
<p>Byli jste odhlášeni ze systému.</p>
<?php } ?>
<p><a href="./register.php">Zaregistrovat</a></p>
</body>
</html>