← SMF

[htaccess] Proteger um fórum com Password

Lida 2772 vezes

Offline

Carlos Faria 
Membro
Mensagens 551 Gostos 5
Feedback +2

Troféus totais: 28
Trófeus: (Ver todos)
Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5 Level 4 Level 3 Level 2

Boa noite a todos,

Gostava de saber como proteger a directoria de um fórum SMF usado o htaccess, queria algo deste género, mas que os acessos fossem baseados na Base de Dados do fórum SMF.


Desde já muito obrigado.
Offline

cenourinha 
Elite
Mensagens 4094 Gostos 21
Troféus totais: 34
Trófeus: (Ver todos)
Mobile User Apple User Level 6 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4

Offline

Carlos Faria 
Membro
Mensagens 551 Gostos 5
Feedback +2

Troféus totais: 28
Trófeus: (Ver todos)
Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5 Level 4 Level 3 Level 2

Offline

anjo2 
Membro
Mensagens 3020 Gostos 0
Troféus totais: 31
Trófeus: (Ver todos)
Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5 Level 4 Level 3 Level 2

Vê lá se dá para ti,

No fim do Settings.php (antes do "?>") adicionar:
Código: [Seleccione]
require_once("authentication.php");
.authentication.php:
Código: [Seleccione]
<?php
if (!isset(
$_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']))
{
header('WWW-Authenticate: Basic realm="Admin"');
header('HTTP/1.0 401 Unauthorized');
echo "Authorization Required.";
exit;
}
else
{
if (empty($db_persist))
$db_connection = @mysql_connect($db_server$db_user$db_passwd);
else
$db_connection = @mysql_pconnect($db_server$db_user$db_passwd);
// Show an error if the connection couldn't be made.
if (!$db_connection || !@mysql_select_db($db_name$db_connection))
db_fatal_error();
// check username and password
if (!mysql_num_rows(mysql_query(sprintf("SELECT `ID_MEMBER` from ${db_prefix}members where `memberName`='%s' and `passwd`='%s'"$_SERVER['PHP_AUTH_USER'], sha1($_SERVER['PHP_AUTH_USER'].$_SERVER['PHP_AUTH_PW'])), $db_connection)))
{
header('WWW-Authenticate: Basic realm="Admin"');
header('HTTP/1.0 401 Unauthorized');
echo "Authorization Required.";
exit;
}
}
?>

Isto é um bocado estupido... mas se for uma directoria diferente do SMF é só copiar o Settings.php com a tal alteração.
Atenção que pode nem funcionar, porque existe vários sistemas de login dentro do smf, eu apenas coloquei um deles...
Offline

Carlos Faria 
Membro
Mensagens 551 Gostos 5
Feedback +2

Troféus totais: 28
Trófeus: (Ver todos)
Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5 Level 4 Level 3 Level 2

@anjo2

É interessante o código vou ver o que faço com ele.

EDIT:

Fico com este erro:

Código: [Seleccione]
Notice: Undefined index: PHP_AUTH_USER in /home/lusonetw/public_html/foruns/authentication.php on line 2

Warning: Cannot modify header information - headers already sent by (output started at /home/lusonetw/public_html/foruns/authentication.php:2) in /home/lusonetw/public_html/foruns/authentication.php on line 4

Warning: Cannot modify header information - headers already sent by (output started at /home/lusonetw/public_html/foruns/authentication.php:2) in /home/lusonetw/public_html/foruns/authentication.php on line 5
Authorization Required.


Acho que vou usar o método tradicional...

Muito Obrigado!
Offline

anjo2 
Membro
Mensagens 3020 Gostos 0
Troféus totais: 31
Trófeus: (Ver todos)
Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5 Level 4 Level 3 Level 2

Porque não está definido, podes simplesmente mudar no index.php
Código: [Seleccione]
error_reporting(E_ALL);por
Código: [Seleccione]
error_reporting(~E_ALL);
De qualquer forma já corrigi esse erro no código acima. Era devido às variáveis não estarem definidas (no inicio não estão porque ainda ninguém deu o username e a password) e então existe um output a dizer que há um erro, e quando existe output deixa de ser possível mudar os headers.