<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
<title>Moja strona WWW</title>
</head>
<body>
<div style="text-align:center">

<?php
/*Skrypt pochodzi z ksi±¿ki "PHP. 101 praktycznych skryptów"
  autor: Marcin Lis                    http://marcinlis.com*/

function checkPass($user, $pass)
{
  if(!$fd = @fopen("./passwords/passwords.txt", "r")) return "error.inc";
  $result = "badData.inc";
  while(!feof ($fd)){
    $line = trim(fgets($fd));
    if(($pos1 = strpos($line, ":"))===false) continue;

    $tempUser = substr($line, 0, $pos1);
    if($tempUser != $user) continue;

    if(($pos2 = strpos($line, ":", $pos1 + 1))===false) continue;
    $tempPass = substr($line, $pos1 + 1, $pos2 - $pos1 - 1);

    if($tempPass != $pass){
      $result = "badData.inc";
      break;
    }

    $tempIndex = substr($line, $pos2 + 1, strlen($line) - $pos2);
    if($tempIndex == ""){
      $result = "DefaultIndex.inc";
      break;
    }
    else{
      $result = $tempIndex;
      break;
    }
  }
  fclose($fd);
  return $result;
}

if(!isSet($_POST["haslo"]) || !isSet($_POST["nazwa"])){
  include('form.inc');
}
else{
  $strona = checkPass($_POST["nazwa"], $_POST["haslo"]);
  include($strona);
}
?>

</div>
</body>
</html>
