.htaccess - Limited users and passwords in . htpasswd and hide form in the php website -
i have secret login page (useradmin.php) users can add , delete users have access secret website (listmembers.php). want limit users adding more users 8 in useradmin site. if there 8 users want hide add form on page , show users message in order add user need first delete current users.
can in php file not connected database or have in .htaccess or .htpasswd file?
here php useradmin.php
<?php // list users $filename = ".htpasswd"; if (!empty($_get["usr"])) { $usr = $_get["usr"]; } else { $usr = ""; } if (!empty($_get["pw"])) $pw = $_get["pw"]; if (!empty($_get["radera"])) { $radera = $_get["radera"]; } else { $radera = 0; } echo "<h2>administration av användare och lösenord</h2>"; if (strlen($usr)>2) { //append new user end of file $handle = fopen($filename, "a"); $userdata = $usr.":"; $userdata = $userdata.crypt($pw)."\n"; fputs($handle,$userdata); fclose($handle); } if ($radera>0) { // delete user $rad = 1; //read old file $handle = fopen($filename, "r"); $buffer[$rad] = fgets($handle, 4096); while (!feof($handle)) { $rad++; $buffer[$rad] = fgets($handle, 4096); } $maxrad = $rad; fclose($handle); //write data buffer exept deleted user $handle = fopen($filename, "w"); $rad = 1; while ($rad < $maxrad) { if ($rad != $radera) { fputs($handle,$buffer[$rad]); } $rad++; } fclose($handle); } //list users $handle = fopen($filename, "r"); $rad = 1; echo "<table border=1 >"; $buffer[$rad] = fgets($handle, 4096); while (!feof($handle)) { echo "<tr><td>"; $user[$rad] = substr($buffer[$rad], 0, strpos($buffer[$rad],":")); echo $user[$rad]; echo "</td><td>"; echo "<a href=\"useradmin.php?radera=$rad\">radera</a>"; echo "</td></tr>"; $rad++; $buffer[$rad] = fgets($handle, 4096); } echo "</table>"; fclose($handle); // limit users 8 ?> <h2>lägg till ny användare</h2> <h3 style="color:red">obs! antalet användare är begränsat till max 8!<br>du måste ta bort en användare för att kunna lägga till en ny.</h3> <form action="useradmin.php" method="get" > login: <input type=text name="usr"><br> lösenord: <input type="text" name="pw"><br> <input type=submit value="uppdatera"> </form>
Comments
Post a Comment