Prøv med:
index.php:
<?php
session_start();
if(!isset($_SESSION["loggedin"]))
{
header("Location: ./login.php");
} else {
header("Location: ./beskyttet.php");
}
?>
login.php:
<?php
session_start();
//her kan man forbinde til en database, eller skrive brugernavn og password
ind
$legaluser = "karlos";
$legalpass = "tester";
if($_REQUEST["user"] == $legaluser && $_REQUEST["pass"] == $legalpass)
{
$_SESSION["test"] = "OK";
header("Location: ./beskyttet.php");
} else {
?>
<center>
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="POST">
<table cols="2" border="0">
<tr>
<td>
Brugernavn: (karlos)
</td>
<td>
<input type="text" name="user">
</td>
</tr>
<tr>
<td>
Adgangskode: (tester)
</td>
<td>
<input type="password" name="pass">
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="knap" value="Login">
</td>
</tr>
</table>
</form>
<?php
}
?>
beskyttet.php:
<?php
session_start();
echo $_SESSION["test"] . " du er logget ind!";
?>
//karlosDK
"Kristian Thy" <thy@it.edu> skrev i en meddelelse
news:2sbe7sF1imlsoU2@uni-berlin.de...
> Unsafe uttered:
>> Simon [2700] wrote in dk.edb.internet.webdesign.serverside.php:
>>> se evt min post 8/9-2004 kl 17:56 "login med session"
>>>
>>> mvh.Simon
>>>
>>>
>>
>> Hvilken post mener du præcist :O? Giv mig venligst et link
>
> Google er (som altid) din ven:
> <URL:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&safe=off&th=3fe5c17bd150e7db&rnum=1>
>
> \\kristian
> --
>
http://lpf.ai.mit.edu/Patents/knuth-to-pto.txt
>
http://home.att.net/~jbcole/humor/Microsoft_patents.htm