login forum / site and session sharing

0

I have a website and a forum, and I would like users to use the same login and password in both. and if possible I'd also like you both to share the same session, so you do not have to sign in 2 times.

    
asked by anonymous 09.10.2017 / 15:09

1 answer

0

Doing this using session is not possible, the session remains active only in the domain that created it, at most what could be done would be to share this session for use in the subdomains of the domain in question. To make them use the same Login and Password you can use cookies. An example of this usage follows below:

ob_start (); // using this command will not have problems if the page contains html content,

if($acao==logar){
include "config.php";

$usuario = $_POST["usuario"];
$senha = $_POST["senha"];

$sql = mysql_query("select * from tabela where usuario='$usuario' AND    senha=MD5('$senha')"); /* verifico se o usuário e a senha estão corretos */
$sql2 = mysql_query("select 'usuario', 'senha', 'nivel' from tabela where 
usuario='$usuario' LIMIT 0,1", $conexao); /* verifico o nivel do usuário 
logado */
$busca = mysql_num_rows($sql); /*verifico se ocorreu resultado*/
$array = mysql_fetch_array($sql2);/*se ocorreu crio um array para os dados 
recebidos */
$usuario = $array["usuario"];
$senha = $array["senha"];
$nivel = $array["nivel"];


if(($busca > 0) && ($array > 0)){ /* crio os cookies */
setcookie("usuario", $usuario);
setcookie("senha", $senha);
setcookie("nivel", $nivel);
header("location: admin.php");
}
else{
echo"Erro ao se logar.";
}
}

I hope I have helped! Hugs!

    
09.10.2017 / 21:44