Hej!
Er der nogen, der ved, om det er muligt at få noget PHP til at tilføje noget i .htaccess filen?
Hilsen
Kristian W. Jakobsen
ICQ: 31707979
MSN Messenger: kwj47@hotmail.com
Mail:kristianw@kristianw.dk
;-)
Det er et lidt ældre script som jeg lavede engang og stadig bruger. Cut/paste og gem den som htadmin.php i den skuffe din .htaccess fil er i. Ikke smukt men virker ;-)
---------------- klip ----------------------------------------------
<?
// htpasswd-admin
function display_htpasswd()
{
$linie = file("htpasswd");
$antal = sizeof ($linie);
$t = 0;
?>
<table border="0" width="100%">
<tr>
<td width="*%" bgcolor="#909FEF"><p align="center"><small><font face="Verdana">htpasswd</font></small></td>
</tr></table>
<table border="0" width="100%">
<td width="40%" bgcolor="#A0AFFF"><p align="center"><small><font face="Verdana">Bruger</font></small></td>
<td width="40%" bgcolor="#A0AFFF"><p align="center"><small><font face="Verdana">Adgangskode</font></small></td>
<td width="10%" bgcolor="#A0AFFF"><p align="center"><small><font face="Verdana"></font></small></td>
<td width="10%" bgcolor="#A0AFFF"><p align="center"><small><font face="Verdana"></font></small></td>
</tr>
<?
while ($t<$antal)
{
$bruger = explode(":", $linie[$t]);
print("<tr>");
if($color == "#D8DBFE") {$color = "#E6ECFD";} else {$color = "#D8DBFE";}
print("<td bgcolor=\\"$color\\"><center><small><font face=\\"Verdana\\">$bruger[0]</font></small></center></td>");
print("<td bgcolor=\\"$color\\"><center><small><font face=\\"Verdana\\">$bruger[1]</font></small></center></td>");
print("<td bgcolor=\\"$color\\"><small><small><font face=\\"Verdana\\">");
?><p><a href="htadmin.php?PMode=ret&i=<?echo $t?>">ret</a></p><?
print("</font></small></small></td>");
print("<td bgcolor=\\"$color\\"><small><small><font face=\\"Verdana\\">");
?><p><a href="htadmin.php?PMode=slet&i=<?echo $t?>">slet</a></p><?
print("</font></small></small></td>");
print("</tr>");
$t++;
}
print("</table>");
display_form();
}
function display_ret()
{
global $i;
global $bruger;
$linie = file("htpasswd");
$antal = sizeof ($linie);
$newfile= fopen("htpasswd","r");
$t=0;
while ($t<=$antal){if($i==$t){$bruger=explode(":",$linie[$t]);}$t++;}
fclose($newfile);
}
function slet_user()
{
global $i;
$linie = file("htpasswd");
$antal = sizeof ($linie);
if ($antal==1){die ("<br/>Den sidste bruger kan ikke slettes");}
$newfile= fopen("htpasswd", "w");
$t=0;
while ($t<=$antal){if($i!=$t){fputs($newfile,$linie[$t]);}$t++;}
fclose($newfile);
$i='';
}
function add_user()
{
global $Navn;
global $Pass;
$Pass = crypt ($Pass);
$linie=$Navn.":".$Pass."\\n";
$newfile= fopen("htpasswd", "a");
fputs($newfile, $linie);
fclose($newfile);
$i='';
}
function ret_user()
{
global $Navn;
global $Pass;
global $i;
$Pass = crypt ($Pass);
$linie = file("htpasswd");
$antal = sizeof ($linie);
$newfile= fopen("htpasswd", "w");
$bruger=$Navn.":".$Pass."\\n";
$t=0;
while ($t<=$antal){if($i!=$t){fputs($newfile,$linie[$t]);}else{fputs($newfile,$bruger);}$t++;}
fclose($newfile);
$i='';
}
function display_form()
{
global $i;
global $bruger;
$Navn =$bruger[0];
$Pass =$bruger[1];
?>
<table border="0" width="100%"><tr><td width="*%" bgcolor="#F0FFEF"><p align="center"></td> </tr></table>
<p><small><small><font face="Times New Roman">
<FORM METHOD="POST" ACTION="htadmin.php">
<table border="0" width="100%">
<tr>
<td width="50%" bgcolor="#E8EBFE">Brugernavn</td><td width="*" bgcolor="#E8EBFE"><INPUT TYPE="text" NAME="Navn" VALUE="<?echo $Navn?>"></td>
<td width="50%" bgcolor="#E8EBFE">Adgangskode</td><td width="*" bgcolor="#E8EBFE"><INPUT TYPE="text" NAME="Pass"></td>
</tr>
<tr>
<INPUT TYPE="hidden" NAME="i" VALUE="<?echo $i?>">
<td width="50%"><input type="submit" value="gem"></td>
<td width="50%"></center><a href="htadmin.php">reset</a></td>
</tr>
</FORM>
</font></small></small>
<?
}
if (empty($PMode) and empty($i) and !empty($Navn)){add_user();}
if (empty($PMode) and !empty($i)){ret_user();}
if ($PMode=='ret'){display_ret();}
if ($PMode=='slet'){slet_user();}
$PMode='';
display_htpasswd();
?>