Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

ModsHolandez

Sistema de Login

Recommended Posts

Galera, criei um Sistema de Login (Básico). Quando eu clico no botão entrar, ele é redirecionado para a página index.php. Porém eu queria que ele fosse redirecionado para a página "index.php?exemplo=1". O "1" seria o ID do usuário, tipo, se o usuário de ID "2" entrasse, fosse para a página "index.php?exemplo=2", se o "3" entrasse, fosse para "index.php?exemplo=3". Alguém sabe fazer?

Ou então alguém pode me passar um outro sistema de login ?

Compartilhar este post


Link para o post
Compartilhar em outros sites

KD o código??

 

 

Galera, criei um Sistema de Login (Básico). Quando eu clico no botão entrar, ele é redirecionado para a página index.php. Porém eu queria que ele fosse redirecionado para a página "index.php?exemplo=1". O "1" seria o ID do usuário, tipo, se o usuário de ID "2" entrasse, fosse para a página "index.php?exemplo=2", se o "3" entrasse, fosse para "index.php?exemplo=3". Alguém sabe fazer?

Ou então alguém pode me passar um outro sistema de login ?

Compartilhar este post


Link para o post
Compartilhar em outros sites

KD o código??

 

login.php

<?php require_once('Connections/boletim.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
 if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
 }

 $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

 switch ($theType) {
case "text":
 	$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
 	break;	
case "long":
case "int":
 	$theValue = ($theValue != "") ? intval($theValue) : "NULL";
 	break;
case "double":
 	$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
 	break;
case "date":
 	$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
 	break;
case "defined":
 	$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
 	break;
 }
 return $theValue;
}
}

mysql_select_db($database_boletim, $boletim);
$query_Serie_Login = "SELECT * FROM usuarios";
$Serie_Login = mysql_query($query_Serie_Login, $boletim) or die(mysql_error());
$row_Serie_Login = mysql_fetch_assoc($Serie_Login);
$totalRows_Serie_Login = mysql_num_rows($Serie_Login);
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
 session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
 $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['login'])) {
 $loginUsername=$_POST['login'];
 $password=$_POST['senha'];
 $MM_fldUserAuthorization = "id_serie_usuario";
 $MM_redirectLoginSuccess = "index.php?boletim=";
 $MM_redirectLoginFailed = "login.php";
 $MM_redirecttoReferrer = false;
 mysql_select_db($database_boletim, $boletim);

 $LoginRS__query=sprintf("SELECT login_usuario, senha_usuario, id_serie_usuario FROM usuarios WHERE login_usuario=%s AND senha_usuario=%s",
 GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 

 $LoginRS = mysql_query($LoginRS__query, $boletim) or die(mysql_error());
 $loginFoundUser = mysql_num_rows($LoginRS);
 if ($loginFoundUser) {

$loginStrGroup  = mysql_result($LoginRS,0,'id_serie_usuario');

if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;  		

if (isset($_SESSION['PrevUrl']) && false) {
 	$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
}
header("Location: " . $MM_redirectLoginSuccess );
 }
 else {
header("Location: ". $MM_redirectLoginFailed );
 }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Login</title>
</head>

<body>
<form action="<?php echo $loginFormAction; ?>" method="POST" name="login" id="login">
 <table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
 	<td width="40">Login:</td>
 	<td width="460"><label for="login"></label>
 	<input type="text" name="login" id="login"></td>
</tr>
<tr>
 	<td>Senha:</td>
 	<td><label for="senha"></label>
 	<input type="password" name="senha" id="senha"></td>
</tr>
<tr>
 	<td> </td>
 	<td><input type="submit" name="entrar" id="entrar" value="Entrar"></td>
</tr>
 </table>
</form>
</body>
</html>
<?php
mysql_free_result($Serie_Login);
?>

Compartilhar este post


Link para o post
Compartilhar em outros sites

é só pegar a id do usuario e jogar em uma variavel e passar via get.

$login = $_POST[login];
$senha = $_POST[senha];

$sql = mysql_query("select id from usuario where login = '$login' ");
$array = mysql_fetch_object($sql); 
$id = $array->id;

if (mysql_num_rows($sql) > 0 ){

header ("location:index.php?exemplo=$id");

}

Compartilhar este post


Link para o post
Compartilhar em outros sites

Aqui você acha a id do usuário

<?php
$sql = mysql_query("SELECT id_usuario from usuarios")
or die(mysql_error());
if (@mysql_num_rows($sql) == 0){
echo 'Nenhum usuario encontrado!';}
while($res=mysql_fetch_array($sql)){

$id = $res[0];
}
?>

 

Aqui voce vai linkar, na validação que redireciona a pagina

<a href="index.php?id=<?php echo $id; ?>">

Compartilhar este post


Link para o post
Compartilhar em outros sites

é só pegar a id do usuario e jogar em uma variavel e passar via get.

$login = $_POST[login];
$senha = $_POST[senha];

$sql = mysql_query("select id from usuario where login = '$login' ");
$array = mysql_fetch_object($sql); 
$id = $array->id;

if (mysql_num_rows($sql) > 0 ){

header ("location:index.php?exemplo=$id");

}

 

assim... você poderia substituir ou colocar esse código no código da página? porque eu sempre me confundo aonde colocar ou só substituiu

Compartilhar este post


Link para o post
Compartilhar em outros sites

Não sei se estou cegueta por causa do horário mas você não usou criptografia para a senha??

Compartilhar este post


Link para o post
Compartilhar em outros sites

Deixa eu explicar melhor:

 

Existe um BANCO DE DADOS chamado "BOLETIM".

Dentro dele tem uma TABELA chamada "USUARIOS" com 6 Campos:

1. id_usuario

2. nome_usuario

3. email_usuario

4. id_serie_usuario

5. login_usuario

6. senha_usuario

Existe uma página chamada "LOGIN.PHP". Dentro dele existe 2 Campos:

1. login

2. senha

Quando eu digito o login e a senha corretamente, e depois clico no botao "ENTRAR", ele vai para a página "INDEX.PHP". Porém como eu quero que cada usuário "tenha" uma página, quando clicasse em "ENTRAR" fosse para a página de acordo com a ID do Usuário, exemplo: se a ID dele fosse 1, fosse para a página "INDEX.PHP?BOLETIM=1", se fosse ID 2, fosse para a página "INDEX.PHP?BOLETIM=2".

 

Código da Página LOGIN.PHP

<?php require_once('Connections/boletim.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
 if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
 }

 $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

 switch ($theType) {
case "text":
 	$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
 	break;	
case "long":
case "int":
 	$theValue = ($theValue != "") ? intval($theValue) : "NULL";
 	break;
case "double":
 	$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
 	break;
case "date":
 	$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
 	break;
case "defined":
 	$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
 	break;
 }
 return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
 session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
 $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['login'])) {
 $loginUsername=$_POST['login'];
 $password=$_POST['senha'];
 $MM_fldUserAuthorization = "";
 $MM_redirectLoginSuccess = "index.php";
 $MM_redirectLoginFailed = "login.php";
 $MM_redirecttoReferrer = false;
 mysql_select_db($database_boletim, $boletim);

 $LoginRS__query=sprintf("SELECT login_usuario, senha_usuario FROM usuarios WHERE login_usuario=%s AND senha_usuario=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 

 $LoginRS = mysql_query($LoginRS__query, $boletim) or die(mysql_error());
 $loginFoundUser = mysql_num_rows($LoginRS);
 if ($loginFoundUser) {
	$loginStrGroup = "";

if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;  		

if (isset($_SESSION['PrevUrl']) && false) {
 	$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
}
header("Location: " . $MM_redirectLoginSuccess );
 }
 else {
header("Location: ". $MM_redirectLoginFailed );
 }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>

<body>
<form action="<?php echo $loginFormAction; ?>" method="POST" name="login" id="login">
 <table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
 	<td width="40">Login:</td>
 	<td width="460"><label for="login"></label>
 	<input type="text" name="login" id="login"></td>
</tr>
<tr>
 	<td>Senha:</td>
 	<td><label for="senha"></label>
 	<input type="password" name="senha" id="senha"></td>
</tr>
<tr>
 	<td> </td>
 	<td><input type="submit" name="entrar" id="entrar" value="Entrar"></td>
</tr>
 </table>
</form>
</body>
</html>

 

Então gostaria de saber como eu faço, modificando ou acrescentado, para fazer isso!

Agradeço a Compreenção, e abraços!

Compartilhar este post


Link para o post
Compartilhar em outros sites

cuidado com os sql injection.. no seu script nao tem criptografia de senha...

 

<?php 
require_once('Connections/boletim.php');

if (!function_exists("GetSQLValueString")) { 
	function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")  
	{ 
 if (PHP_VERSION < 6) {   
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; 
 	} 
		$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); 
		switch ($theType) { 
			case "text": 
			$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
			break;   
			case "long": 
			case "int": 
			$theValue = ($theValue != "") ? intval($theValue) : "NULL"; 
			break; 
			case "double": 
			$theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; 
			break; 
			case "date": 
			$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
			break; 
			case "defined": 
			$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; 
			break; 
 				} 
		  return $theValue; 
	} 
} 

if (!isset($_SESSION)) { 
 session_start(); 
} 

$loginFormAction = $_SERVER['PHP_SELF']; 
if (isset($_GET['accesscheck'])) { 
 $_SESSION['PrevUrl'] = $_GET['accesscheck']; 
} 

if (isset($_POST['login'])) { 
 $loginUsername=$_POST['login']; 
 $password=$_POST['senha']; 
 $MM_fldUserAuthorization = ""; 
 $MM_redirecttoReferrer = false; 
 mysql_select_db($database_boletim, $boletim); 

 $LoginRS__query=sprintf("SELECT id,login_usuario,senha_usuario FROM usuarios WHERE login_usuario=%s AND senha_usuario=%s", 
       GetSQLValueString($ID, "text"), GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));  

 $LoginRS = mysql_query($LoginRS__query, $boletim) or die(mysql_error()); 
 $loginFoundUser = mysql_num_rows($LoginRS); 
 if ($loginFoundUser) { 
       $loginStrGroup = ""; 
       $_SESSION['id'] = $ID; 
	$_SESSION['MM_Username'] = $loginUsername; 
	$_SESSION['MM_Username'] = $loginUsername; 
       $_SESSION['MM_UserGroup'] = $loginStrGroup;              

       if (!isset($_SESSION['PrevUrl'])) { 
       header("Location:index.php?id=".$SESSION['id']);
	}else{ 
       header("Location:login.php"); 
	}
 	} 
} 
?> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
<title>Untitled Document</title> 
</head> 

<body> 
<form action="<?php echo $loginFormAction; ?>" method="POST" name="login" id="login"> 
 <table width="500" border="0" cellspacing="0" cellpadding="0"> 
       <tr> 
       <td width="40">Login:</td> 
       <td width="460"><label for="login"></label> 
       <input type="text" name="login" id="login"></td> 
       </tr> 
       <tr> 
       <td>Senha:</td> 
       <td><label for="senha"></label> 
       <input type="password" name="senha" id="senha"></td> 
       </tr> 
       <tr> 
       <td> </td> 
       <td><input type="submit" name="entrar" id="entrar" value="Entrar"></td> 
       </tr> 
 </table> 
</form> 
</body> 
</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

cuidado com os sql injection.. no seu script nao tem criptografia de senha...

 

<?php 
require_once('Connections/boletim.php');

if (!function_exists("GetSQLValueString")) { 
	function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")  
	{ 
 if (PHP_VERSION < 6) {   
   	$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; 
 	} 
		$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); 
		switch ($theType) { 
			case "text": 
			$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
			break;   
			case "long": 
			case "int": 
			$theValue = ($theValue != "") ? intval($theValue) : "NULL"; 
			break; 
			case "double": 
			$theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; 
			break; 
			case "date": 
			$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
			break; 
			case "defined": 
			$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; 
			break; 
 				} 
 			return $theValue; 
	} 
} 

if (!isset($_SESSION)) { 
 session_start(); 
} 

$loginFormAction = $_SERVER['PHP_SELF']; 
if (isset($_GET['accesscheck'])) { 
 $_SESSION['PrevUrl'] = $_GET['accesscheck']; 
} 

if (isset($_POST['login'])) { 
 $loginUsername=$_POST['login']; 
 $password=$_POST['senha']; 
 $MM_fldUserAuthorization = ""; 
 $MM_redirecttoReferrer = false; 
 mysql_select_db($database_boletim, $boletim); 

 $LoginRS__query=sprintf("SELECT id,login_usuario,senha_usuario FROM usuarios WHERE login_usuario=%s AND senha_usuario=%s", 
       GetSQLValueString($ID, "text"), GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));  

 $LoginRS = mysql_query($LoginRS__query, $boletim) or die(mysql_error()); 
 $loginFoundUser = mysql_num_rows($LoginRS); 
 if ($loginFoundUser) { 
       $loginStrGroup = ""; 
       $_SESSION['id'] = $ID; 
	$_SESSION['MM_Username'] = $loginUsername; 
	$_SESSION['MM_Username'] = $loginUsername; 
       $_SESSION['MM_UserGroup'] = $loginStrGroup;              

       if (!isset($_SESSION['PrevUrl'])) { 
       header("Location:index.php?id=".$SESSION['id']);
	}else{ 
       header("Location:login.php"); 
	}
 	} 
} 
?> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
<title>Untitled Document</title> 
</head> 

<body> 
<form action="<?php echo $loginFormAction; ?>" method="POST" name="login" id="login"> 
 <table width="500" border="0" cellspacing="0" cellpadding="0"> 
       <tr> 
       <td width="40">Login:</td> 
       <td width="460"><label for="login"></label> 
       <input type="text" name="login" id="login"></td> 
       </tr> 
       <tr> 
       <td>Senha:</td> 
       <td><label for="senha"></label> 
       <input type="password" name="senha" id="senha"></td> 
       </tr> 
       <tr> 
       <td> </td> 
       <td><input type="submit" name="entrar" id="entrar" value="Entrar"></td> 
       </tr> 
 </table> 
</form> 
</body> 
</html>

 

Amigo, está quase perfeito, só que está faltando declarar a varíavel $ID. Pode me dizer qual é e onde colocar? ou ja colocar no código?

 

E também:

$LoginRS__query=sprintf("SELECT id,login_usuario,senha_usuario FROM usuarios WHERE login_usuario=%s AND senha_usuario=%s", .....

$_SESSION['id'] = $ID;

header("Location:index.php?id=".$SESSION['id']);

O "id" não temos que substituir por "id_usuário"?

 

Abraços!

Compartilhar este post


Link para o post
Compartilhar em outros sites

só trocar o id pelo id da sua tabela, nao sei como deve estar o nome dos campos.. ei nao foi você que fez esse script de login né .

 

 

Amigo, está quase perfeito, só que está faltando declarar a varíavel $ID. Pode me dizer qual é e onde colocar? ou ja colocar no código?

 

E também:

$LoginRS__query=sprintf("SELECT id,login_usuario,senha_usuario FROM usuarios WHERE login_usuario=%s AND senha_usuario=%s", .....

$_SESSION['id'] = $ID;

header("Location:index.php?id=".$SESSION['id']);

O "id" não temos que substituir por "id_usuário"?

 

Abraços!

Compartilhar este post


Link para o post
Compartilhar em outros sites

nada melhor que refazer tudo de forma organizada, e não esquece de criptografar as senhas com algo forte nada de base64, md5 ou sha1 ..

 

att..

 

qualquer dúvida msn fabianobrandt@hot

 

 

Galera, valeu pelas respotas, que podem até estarem certas, só que não consegui organizar no código, então vou procurar um tutorial iniciando do zero. Valeu e abraços!

Compartilhar este post


Link para o post
Compartilhar em outros sites

nada melhor que refazer tudo de forma organizada, e não esquece de criptografar as senhas com algo forte nada de base64, md5 ou sha1 ..

 

att..

 

qualquer dúvida msn fabianobrandt@hot

 

 

 

beleza, vou procurar um bem bom! E valeu por tudo....

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.