Det kunne se sådan ud med et hyper-simpelt login:
<?
session_start();
include("myFavorites.php");
if (isset($_POST["contxt"]) && $_POST["contxt"]=="login") {
$passCheck = "kodeord"; // Dit password
if ($_POST["pass"]===$passCheck) {
$_SESSION["loggedIn"] = "OK";
}
header("Location: ".$_SERVER["PHP_SELF"]);
exit;
}
if (isset($_POST["contxt"]) && $_POST["contxt"]=="insFav" && $_SESSION["loggedIn"]==="OK") {
$myFavorites[] = array($_POST["favName"], $_POST["favUrl"]);
$fp = fopen("myfavorites.php", "w");
$aArr = array();
for ($i=0,$j=count($myFavorites); $i<$j; $i++) {
$aArr[] = "array('".$myFavorites[$i][0]."', '".$myFavorites[$i][1]."')";
}
fwrite($fp, "<?\r\n\$myFavorites = array(\r\n\t".implode(",\r\n\t", $aArr)."\r\n);\r\n?>");
fclose($fp);
header("Location: ".$_SERVER["PHP_SELF"]);
exit;
}
function getFavorites() {
global $myFavorites;
$aArr = array();
for ($i=0,$j=count($myFavorites); $i<$j; $i++) {
$aArr[$i] = "<div><a href='".$myFavorites[$i][0]."' target='_blank'>".$myFavorites[$i][1]."</a> > <b>".$myFavorites[$i][0]."</b></div>";
}
return implode("\r\n", $aArr);
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
http://www.w3.org/TR/html4/loose.dtd"><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Mine Favoriter</title>
<style type="text/css">
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#favDispl {
width: 500px;
height: 500px;
border: 1px solid #999999;
overflow: auto;
}
#favDispl div {
padding: 0 10px;
}
#favDispl a, #favDispl a:visited {
color: black;
text-decoration: none;
}
#favDispl a:hover {
color: red;
text-decoration: underline;
}
</style>
</head>
<body>
<div id="favDispl">
<?=getFavorites()?>
</div>
<?
if ($_SESSION["loggedIn"]==="OK") { // Du er logget ind
?>
<form action="<?=$_SERVER["PHP_SELF"]?>" method="post">
<input type="hidden" name="contxt" value="insFav">
<table>
<tbody>
<tr>
<td>Navn:</td>
<td><input name="favName" type="text"></td>
</tr>
<tr>
<td>URL:</td>
<td><input name="favUrl" type="text"></td>
</tr>
<tr>
<td colspan="2" style="text-align:center"><button type="submit">Opret</button></td>
</tr>
</tbody>
</table>
</form>
<?
} else { // Du er ikke logget ind
?>
<form action="<?=$_SERVER["PHP_SELF"]?>" method="post">
<input type="hidden" name="contxt" value="login">
<div>Log ind:</div>
<input name="pass" type="password">
<p><button type="submit">Login</button></p>
<?
}
?>
</body>
</html>