1. ---------- login.html ------------------
<html>
<head>
<title>Login Page</title>
</head>
<body>
<form method=post action=login.php>
User:
<input type=text name=user>
<br>
Password:
<input type=password name=pwd>
<br>
<input type=submit value="Login!">
</form>
</body>
</html>
2. ----------- login.php ------------------
<?php
session_start();
$user=$_POST"user";
$pwd=$_POST"pwd";
if (($user == "Chacal") && ($pwd == "admin"))
{
$_SESSION['nombre']="Victor Cuevas D.";
$_SESSION['logged']="Si";
header("Location: index.php");
} else
header("Location: login.html");
?>
3. ------------ index.php ----------------
<?php
session_start();
include_once("control.php");
if (!is_logged())
{
header("Location: login.html");
exit(0);
}
echo "Hola we'on.." . $_SESSION"nombre" ."<br>\n";
echo "<hr>\n";
echo "<a href='page2.php'>Vamos a la otra páginas</a><br>\n";
echo "<a href='salir.php'>A salgamos de esta weá</a><br>\n";
?>
4. ---------- control.php ---------------------
<?php
function is_logged(){
if ((!isset($_SESSION"logged")) || ($_SESSION"logged"!="Si"))
return FALSE;
else
return TRUE;
}
?>
5. ------------ page2.php ------------------
<?php
session_start();
include_once("control.php");
if (!is_logged())
{
header("Location: login.html");
exit(0);
}
echo "Hola we'on..<br>\n";
echo "<hr>\n";
echo "<a href='index.php'>Vamos a la página 1</a><br>\n";
echo "<a href='salir.php'>A salgamos de esta weá</a><br>\n";
?>
6. -------------- salir.php (get_out.php inenglish)----
<?php
session_start();
$_SESSION[]=array();
session_destroy();
header("Location: login.html");
?>
I going to put you an example I made to undestarnd -time ago- the sessions (no DB, sorry, but you can modify it).
1. ---------- login.html ------------------
<html>
<head>
<title>Login Page</title>
</head>
<body>
<form method=post action=login.php>
User:
<input type=text name=user>
<br>
Password:
<input type=password name=pwd>
<br>
<input type=submit value="Login!">
</form>
</body>
</html>
2. ----------- login.php ------------------
<?php
session_start();
$user=$_POST"user";
$pwd=$_POST"pwd";
if (($user == "Chacal") && ($pwd == "admin"))
{
$_SESSION['nombre']="Victor Cuevas D.";
$_SESSION['logged']="Si";
header("Location: index.php");
} else
header("Location: login.html");
?>
3. ------------ index.php ----------------
<?php
session_start();
include_once("control.php");
if (!is_logged())
{
header("Location: login.html");
exit(0);
}
echo "Hola we'on.." . $_SESSION"nombre" ."<br>\n";
echo "<hr>\n";
echo "<a href='page2.php'>Vamos a la otra páginas</a><br>\n";
echo "<a href='salir.php'>A salgamos de esta weá</a><br>\n";
?>
4. ---------- control.php ---------------------
<?php
function is_logged(){
if ((!isset($_SESSION"logged")) || ($_SESSION"logged"!="Si"))
return FALSE;
else
return TRUE;
}
?>
5. ------------ page2.php ------------------
<?php
session_start();
include_once("control.php");
if (!is_logged())
{
header("Location: login.html");
exit(0);
}
echo "Hola we'on..<br>\n";
echo "<hr>\n";
echo "<a href='index.php'>Vamos a la página 1</a><br>\n";
echo "<a href='salir.php'>A salgamos de esta weá</a><br>\n";
?>
6. -------------- salir.php (get_out.php inenglish)----
<?php
session_start();
$_SESSION[]=array();
session_destroy();
header("Location: login.html");
?>