Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: hasla dospetu do plikow i katalogow na serwerze
Forum PHP.pl > Forum > Przedszkole
mateopl
Witam serdecznie
Znalazlem w sieci pewien skrypt ktory wyswietla katalogi i pliki na serwerze z mozliwoscia zabezpieczenia haslem dany katalog.
Z tym ze mozna tam podac tylko jedno haslo do jednego katalogu a ja chcialbym np do tego jedenego katalogu przydzielic 3-4 rozne hasla.. Nie wiem w jaki sposob to zrobic:(
(
Bardzo prosze o pomoc:(

Z gory bardzo dziekuje za odpowiedzi

Plik glowny skryptu (index.php)

  1. <?php
  2. $ImagesPath = '../images/'; // cieka dostpu do katalogu plikw graficznych
  3. $Hidden = array ('haslo.php'); // hide
  4. function file_type ($Name) {
  5.          $Ext = explode ('.', $Name);
  6.          $Ext = strtolower (end ($Ext));
  7.          if (in_array ($Ext, array ('html', 'htm', 'shtml'))) $FileExt = 'html';
  8.          else if (in_array ($Ext, array ('php', 'php3', 'phtml'))) $FileExt = 'php';
  9.          else if (in_array ($Ext, array ('zip', 'rar', 'tar', 'gz', 'bz2', 'tgz'))) $FileExt = 'archive';
  10.          else if (in_array ($Ext, array ('avi', 'mpg', 'mpeg'))) $FileExt = 'movie';
  11.          else if (in_array ($Ext, array ('vaw', 'mp3', 'ogg'))) $FileExt = 'sound';
  12.          else if (in_array ($Ext, array ('bmp', 'gif', 'png', 'jpg', 'jpeg'))) $FileExt = 'image';
  13.          else if (in_array ($Ext, array ('txt', 'css', 'js', 'sql'))) $FileExt = 'txt';
  14.          else if (in_array ($Ext, array ('doc', 'rtf'))) $FileExt = 'document';
  15.          else if (in_array ($Ext, array ('xls', 'xlw', 'sxc'))) $FileExt = 'spreadsheet';
  16.          else if (in_array ($Ext, array ('ppt', 'pps', 'sxi'))) $FileExt = 'presentation';
  17.          else if (in_array ($Ext, array ('mid', 'midi'))) $FileExt = 'midi';
  18.          else if (in_array ($Ext, array ('iso', 'img'))) $FileExt = 'cdimage';
  19.          else if ($Ext == 'pdf') $FileExt = 'pdf';
  20.          else if ($Ext == 'exe') $FileExt = 'exe';
  21.          else if ($Ext == 'swf') $FileExt = 'swf';
  22.          else if ($Ext == 'svg') $FileExt = 'svg';
  23.          else if ($Ext == 'deb') $FileExt = 'deb';
  24.          else if ($Ext == 'rpm') $FileExt = 'rpm';
  25.          return ($FileExt?$FileExt:'unknown');
  26.          }
  27. if ($_GET['id']) {
  28.    $Path = substr ($_SERVER['PATH_INFO'], 1);
  29.    include (pathinfo ($Path, PATHINFO_DIRNAME).'/haslo.php');
  30.    if ($_GET['id'] == $ID) {
  31.       header ('Content-Type: application/force-download');
  32.       readfile ($Path);
  33.       }
  34.    else echo 'Access Denied!';
  35.    exit ();
  36.    }
  37. $_GET['path'] = str_replace (array ('../', './', '//'), '', $_GET['path']);
  38. if ($_GET['path']{0} == '/') $_GET['path'] = substr ($_GET['path'], 1);
  39. $Path = explode ('/', $_GET['path']);
  40. unset ($Path[count ($Path) - 1]);
  41. if (!file_exists ('./'.$_GET['path'])) $Page = '<div>Unsuitable path of access!</div>'."\n";
  42. else {
  43.      @include ($_GET['path'].'/haslo.php');
  44.      if ($HiddenFiles) $Hidden = array_merge ($Hidden, $HiddenFiles);
  45.      for ($i = 0; $i < (count ($Path) - 1); $i++) $Up.= $Path[$i].'/';
  46.      foreach ($Path as $Dir) {
  47.              $Link.= $Dir.'/';
  48.              $Menu.= ' <a href="?path='.$Link.'">'.$Dir.'</a> /'."\n";
  49.              }
  50.      if ($_GET['path']) $Up = '<div class="link"><a href="'.($Up?'?path='.$Up:$_SERVER['PHP_SELF']).'"><img src="'.$ImagesPath.'up.png" alt="up" />Level up</a></div>';
  51.      $Page = '<div class="file"><b>File name<div>Last update</div><div>Size</div></b></div>';
  52.      foreach (glob ($_GET['path'].'*') as $File) if (is_dir ($File) && !in_array (basename ($File), $Hidden)) $Page.= '<div class="file"><div class="link">'.date ('d.m.Y H:i:s', filemtime ($File)).'</div><div class="link">-</div><a href="'.$_SERVER['PHP_SELF'].'?path='.$File.'/"><img src="'.$ImagesPath.'dir.png" alt="dir" /> '.basename ($File).'</a></div>'."\n";
  53.      foreach (glob ($_GET['path'].'*') as $File) if (is_file ($File) && $File !== basename ($_SERVER['PHP_SELF']) && !in_array (basename ($File), $Hidden)) $Page.= '<div class="file"><div class="link">'.date ('d.m.Y H:i:s', filemtime ($File)).'</div><div class="link">'.((filesize ($File) > 1024)?((filesize ($File) > 1048576)?round (filesize ($File) / 1048576, 2).' MB':round (filesize ($File) / 1024, 2).' KB'):filesize ($File).' B').'</div><a href="'.($ID?basename ($_SERVER['PHP_SELF']).'/'.$File.'?id='.$ID:$File).'"><img src="'.$ImagesPath.file_type ($File).'.png" alt="'.file_type ($File).'" /> '.basename ($File).'</a></div>'."\n";
  54.      if (!$Page) $Page = '<div class="link">No files.</div>'."\n";
  55.      if ($AccessDenied) {
  56.         if ($_POST['password']) $_SESSION[$ID.'_password'] = $_POST['password'];
  57.         if ($_GET['logout']) unset ($_SESSION[$ID.'_password']);
  58.         if ($Password && $_SESSION[$ID.'_password'] !== $Password) $Page = '<form method="post" action="" id="login"><div>Input password.<br /><br /><label for="password">Password</label> <input type="password" name="password" id="password" /><br /><label for="submit">Submit</label> <input type="submit" value="Submit" id="submit" /></div></form>'."\n";
  59.         else if (!$Password) $Page = '<div>Permission denied!</div>'."\n";
  60.         else $Page = '<a id="logout" href="?path='.$_GET['path'].'&amp;logout=1">Logout</a>'."\n".$Page;
  61.         }
  62.      }
  63. $Menu = '<div class="menu">'."\n".'<a href="'.$_SERVER['PHP_SELF'].'">Home</a> /'.$Menu.'</div>'."\n";
  64. ?>


Plik z haslem (haslo.php)

  1. <?php
  2. $AccessDenied = 1;
  3. $Password = '1';
  4. $ID = '2';
  5. ?>
grzemach
nie wiem dalczego tak bardzo kombinujesz, jeśli chcesz zrobić przeglądanie folderów na serwerze hasłami, poszukaj o htaccess, można stworzyć dowolną ilość kont, można zrobić wszystko to co opisałeś w tym poście.
mateopl
Wiem o takiej mozliwosci ale mi chodzi o taki system zeby pliki byly wyswietlane w jakiejs skorce a nie standardowo..sad.gif
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.