freelance, web developer, web designer, hosting, domain name
AuthType Basic AuthName "Admin" AuthUserFile /home/public_html/admin/.htpasswd Require valid-user
admin:cGhg/8u3.w9r2
function htaccess($xauser, $xapasswd) { global $xamppdirconfig; global $xapasswdtxtdir; global $htpasswddir; global $htpasswddirectory; global $htxampp; global $xapfile; list($partwampp, $directorwampp) = preg_split('|\\\security\\\htdocs|', dirname(__FILE__)); $htaccess = ".htaccess"; $xapasswdtxt = "xamppdirpasswd.txt"; $htpasswd = "xampp.users"; $xapasswdtxtdir = $partwampp."\security\\".$xapasswdtxt; $curspcript = $_SERVER["SCRIPT_FILENAME"]; $htxampp = $partwampp."\htdocs\\xampp\\".$htaccess; $htpasswdexe = $partwampp."\apache\\bin\\htpasswd.exe"; if (file_exists($htpasswdexe)) { $htpasswddir = "\"".$partwampp."\security\\".$htpasswd."\""; $htpasswddirectory = $partwampp."\security\\".$htpasswd; $dir = $partwampp."\security\\"; if (!file_exists($dir)) { mkdir($dir); } $datei = fopen($htxampp, 'w+'); $insert = "AuthName \"xampp user\"\r\nAuthType Basic\r\nAuthUserFile $htpasswddir\r\nrequire valid-user"; fputs($datei,$insert); fclose($datei); $curdir=getcwd(); chdir($partwampp."\security"); // Fix by Wiedmann $htpassrealm = "start /b \"\" \"$htpasswdexe\" -c -m -b .\\xampp.users $xauser $xapasswd"; $handle = popen($htpassrealm, 'w'); pclose($handle); chdir($curdir); if ($xapfile=="yes") { $datei = fopen($xapasswdtxtdir, 'w+'); $put = "XAMPP user = $xauser\r\nXAMPP password = $xapasswd"; fputs($datei, $put); fclose($datei); } $hdir = $dir.'htdocs\\'; copy($htxampp, $dir.'htdocs\\.htaccess'); $xamppdirconfig = "ok"; } else { $xamppdirconfig = "notok"; } }
ใน .htaccess
AuthName "Admin"
AuthUserFile /home/public_html/admin/.htpasswd
Require valid-user
ใน .htpasswd
คือมันเข้ารหัส password แบบไหนไม่รู้(น่าจะเป็น DES ครับ ไม่แน่ใจ) แล้วเราต้องการเข้ารหัสแบบ md5 อ่ะครับ
ถ้าเอา password ของ md5 มาใส่เลยจะได้รึเปล่า หรือต้องกำหนดตรงไหนเพิ่มเติมเพิ่อให้ใช้แบบ md5 ได้
หรือมีวิธีไหนที่ใช้แทนกันได้ครับ
ผมยกตัวอย่างฟังก์ชั่นการสร้างรหัสผ่านของ XAMPP นะครับ
global $xamppdirconfig;
global $xapasswdtxtdir;
global $htpasswddir;
global $htpasswddirectory;
global $htxampp;
global $xapfile;
list($partwampp, $directorwampp) = preg_split('|\\\security\\\htdocs|', dirname(__FILE__));
$htaccess = ".htaccess";
$xapasswdtxt = "xamppdirpasswd.txt";
$htpasswd = "xampp.users";
$xapasswdtxtdir = $partwampp."\security\\".$xapasswdtxt;
$curspcript = $_SERVER["SCRIPT_FILENAME"];
$htxampp = $partwampp."\htdocs\\xampp\\".$htaccess;
$htpasswdexe = $partwampp."\apache\\bin\\htpasswd.exe";
if (file_exists($htpasswdexe)) {
$htpasswddir = "\"".$partwampp."\security\\".$htpasswd."\"";
$htpasswddirectory = $partwampp."\security\\".$htpasswd;
$dir = $partwampp."\security\\";
if (!file_exists($dir)) {
mkdir($dir);
}
$datei = fopen($htxampp, 'w+');
$insert = "AuthName \"xampp user\"\r\nAuthType Basic\r\nAuthUserFile $htpasswddir\r\nrequire valid-user";
fputs($datei,$insert);
fclose($datei);
$curdir=getcwd();
chdir($partwampp."\security"); // Fix by Wiedmann
$htpassrealm = "start /b \"\" \"$htpasswdexe\" -c -m -b .\\xampp.users $xauser $xapasswd";
$handle = popen($htpassrealm, 'w');
pclose($handle);
chdir($curdir);
if ($xapfile=="yes") {
$datei = fopen($xapasswdtxtdir, 'w+');
$put = "XAMPP user = $xauser\r\nXAMPP password = $xapasswd";
fputs($datei, $put);
fclose($datei);
}
$hdir = $dir.'htdocs\\';
copy($htxampp, $dir.'htdocs\\.htaccess');
$xamppdirconfig = "ok";
} else {
$xamppdirconfig = "notok";
}
}