Hier werden die Unterschiede zwischen zwei Versionen gezeigt.
| Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
|
php:htaccess [2016/04/21 21:05] webproducer angelegt |
php:htaccess [2023/03/23 10:42] (aktuell) webproducer auf Datei hinter .htaccess Verzeichnisschutz zugreifen |
||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| - | ====== Verzeichnisschutz durch htaccess ====== | + | ====== Verzeichnisschutz durch .htaccess-Datei ====== |
| + | |||
| + | ===== Verzeichnisschutz mit PHP erstellen ===== | ||
| <code ini .htaccess> | <code ini .htaccess> | ||
| Zeile 17: | Zeile 19: | ||
| private $write = false; | private $write = false; | ||
| - | public function __construct( $filename ) { | + | public function __construct( $filename ) |
| - | + | { | |
| - | if( !empty( $filename ) ) { | + | if( !empty( $filename ) ) |
| + | { | ||
| $this->filename = $filename; | $this->filename = $filename; | ||
| - | if( file_exists( $filename ) ) { | + | if( file_exists( $filename ) ) |
| - | + | { | |
| - | $fp = fopen( $filename, 'r' ); | + | $this->lines = file( $filename ); |
| - | + | ||
| - | while( !feof ( $fp ) ) { | + | |
| - | + | ||
| - | $line = fgets( $fp ); | + | |
| - | + | ||
| - | if( !empty( $line ) ) | + | |
| - | $this->lines[] = $line; | + | |
| - | } | + | |
| - | + | ||
| - | fclose( $fp ); | + | |
| } | } | ||
| + | | ||
| } | } | ||
| else | else | ||
| + | { | ||
| throw new Exception( "filename is empty" ); | throw new Exception( "filename is empty" ); | ||
| + | } | ||
| } | } | ||
| - | public function addUser( $username, $password ) { | + | public function addUser( $username, $password ) |
| - | + | { | |
| - | if( !empty( $username ) ) { | + | if( !empty( $username ) ) |
| - | + | { | |
| - | if( $this->getIndex( $username ) == -1 ) { | + | if( $this->getIndex( $username ) == -1 ) |
| + | { | ||
| $line[0] = $username; | $line[0] = $username; | ||
| $line[1] = password_hash( $password, PASSWORD_BCRYPT ); | $line[1] = password_hash( $password, PASSWORD_BCRYPT ); | ||
| Zeile 56: | Zeile 51: | ||
| } | } | ||
| else | else | ||
| + | { | ||
| return false; | return false; | ||
| + | } | ||
| } | } | ||
| else | else | ||
| + | { | ||
| return false; | return false; | ||
| + | } | ||
| } | } | ||
| Zeile 121: | Zeile 120: | ||
| $htaccess->delUser( "Hubert" ); | $htaccess->delUser( "Hubert" ); | ||
| </code> | </code> | ||
| + | |||
| + | ===== Auf eine Datei hinter .htaccess Verzeichnisschutz zugreifen ===== | ||
| + | |||
| + | <code php> | ||
| + | $url = 'https://wissensarchiv.org/geheimes-verzeichnis/'; | ||
| + | $username = 'test'; | ||
| + | $password = 'test'; | ||
| + | |||
| + | $splitUrl = explode( '//', $url ); | ||
| + | $realUrl = sprintf( '%s//%s:%s@%s', $splitUrl[0], $username, $password, $splitUrl[1] ); | ||
| + | $content = file_get_contents( $realUrl ); | ||
| + | |||
| + | echo $content; | ||
| + | </code> | ||
| + | |||
| + | |||