mam taki skrypt logowania:
login.php
include('config.php');
//include('module/news.inc.php');
#=====================================================#
function site_main() {
main_title_open();
echo 'Panel Administratora'; main_title_close();
main_text_open();
include 'login2.php';
main_text_close();
}
#=====================================================#
include("theme/mg/index.php");
?>
auth.inc.php
<?php
if (isset($_SESSION['logged']) && $_SESSION['logged'] == 1) {
//nie rob nic
}
else
{
$redirect = $_SERVER['PHP_SELF'];
header("Refresh: 1; URL=login.php?redirect=$redirect"); echo "Brak autoryzacji. Trwa przekierowanie..."; }
?>
login2.php
$_SESSION['logged'] = 0;
if (isset($_POST['submit'])) {
if ($_POST['username'] == "a" &&
$_POST['password'] == "a")
{
$_SESSION['logged'] = 1;
header ("Refresh: 2; URL=\"test.php\""); }
else
{
?>
<html>
<head>
<title>fffff</title>
</head>
<body>
Brak autoryzacji
<form action="login.php" method="post">
<input type="hidden" name="redirect" value="
<?php echo $_POST['redirect']; ?>">
nick:<input type="text" name="username"><br>
haslo <input type="password" name="password"><br><br>
<input type="submit" name="submit" value="Zaloguj" >
</form>
<?php
}
} else {
?>
<html>
<head>
<title>fffff</title>
</head>
<body>
<?
if (isset($_GET['redirect'])) { $redirect = $_GET['redirect'];
}
else
{
$redirect = "index.php";
}
?>
<form action="login.php" method="post">
<input type="hidden" name="redirect" value="
<?php echo $_GET['redirect']; ?>">
nick:<input type="text" name="username"><br>
haslo <input type="password" name="password"><br><br>
<input type="submit" name="submit" value="Zaloguj" >
</form>
<p>
<?php
}
?>
</body>
</html>
plik auth.inc.php
<?php
if (isset($_SESSION['logged']) && $_SESSION['logged'] == 1) {
//nie rob nic
}
else
{
$redirect = $_SERVER['PHP_SELF'];
header("Refresh: 1; URL=login2.php?redirect=$redirect"); echo "<b>Brak autoryzacji.</b> Trwa przekierowanie"; }
?>
oraz jakas strone dla przykladu:
test.php
<?php include "auth.inc.php"; ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
ddddddddddddddddddd
</body>
</html>
poprawilem pliki i teraz po includowaniu pliku wszystko dziala, nawet gdy wpisze zle dane wyskakuje poprawnie blad (IMG:
http://forum.php.pl/style_emoticons/default/smile.gif)
problem w tym ze gdy zaloguje sie poprawnie wywala blad:
Cytat
Warning: Cannot modify header information - headers already sent by (output started at c:\usr\krasnal\www\kcms\theme\mg\index.php:7) in c:\usr\krasnal\www\kcms\login2.php on line 10
Zalogowano...
i niby jestem zalogowany jak wpisze w przegladarce adres test.php a powinno po zalogowaniu mnie automatycznie przeniesc (IMG:
http://forum.php.pl/style_emoticons/default/sad.gif)
dlaczego tak sie dzieje (IMG:
http://forum.php.pl/style_emoticons/default/questionmark.gif) (IMG:
http://forum.php.pl/style_emoticons/default/blink.gif) (IMG:
http://forum.php.pl/style_emoticons/default/blink.gif)
Ten post edytował trucksweb 14.02.2006, 19:27:48