Ir para conteúdo
Fórum Script Brasil
  • 0

[Pedido]Sistema de login e cadastro


Leonardo.j.

Pergunta

Bom pessoal eu to montando o site da minha escola mais já rodei a internet toda e não achei queria asim:

Sistema de login e cadastro feito só pra mim cria as tabelas no sql

eu achei sistema de cadastro tah 100% mais não sei faze sistema de login já tentei de tudo e não consegui

queria a ajuda de vocês pra isso vo ficar esperando

se eu errei a area por favor me descupe so novato ainda!

Link para o comentário
Compartilhar em outros sites

15 respostass a esta questão

Posts Recomendados

  • 0

Bom não sei vo postar aqui e ve se alguém me ajuda faze sistema de login

cadastro.php

<?php

if(file_exists("init.php")) {

require "init.php";

} else {

echo "Arquivo init.php não foi encontrado";

exit;

}

if(!function_exists("Abre_Conexao")) {

echo "Erro o arquivo init.php foi auterado, não existe a função Abre_Conexao";

exit;

}

Abre_Conexao();

$re = mysql_query("select * from estados order by estado");

if(mysql_errno() != 0) {

if(!isset($erros)) {

echo "Erro o arquivo init.php foi auterado, não existe \$erros";

exit;

}

echo $erros[mysql_errno()];

exit;

}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns=http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Cadastro</title>

<style>

<!--

.textBox { border:1px solid gray; width:200px;}

-->

</style>

</head>

<body>

<form id="form1" name="form1" method="post" action="salvar.php">

<table width="400" border="0" align="center">

<tr>

<td width="145">Nome</td>

<td width="245"><input name="nome" type="text" id="nome" maxlength="45" class="textBox" /></td>

</tr>

<tr>

<td>Email</td>

<td><input name="email" type="text" id="email" maxlength="64" class="textBox" /></td>

</tr>

<tr>

<td>Data Nascimento</td>

<td>

<?php

echo monta_select("dia", 1, 31);

echo monta_select("mes", 1, 12);

echo monta_select("ano", 1940, 1988);

?>

</td>

</tr>

<tr>

<td>Sexo</td>

<td><input name="sexo" type="radio" value="M" checked="checked" /><label>Masculino</label>

<input name="sexo" type="radio" value="F" /> <label>Feminino</label></td>

</tr>

<tr>

<td>Preferencias de Filmes </td>

<td><select name="preferencias[]" class="textBox" multiple="multiple" id="preferencias">

<option value="R">Romance</option>

<option value="S">Suspense</option>

<option value="P">Policial</option>

<option value="F">Ficção</option>

</select>

</td>

</tr>

<tr>

<td>Salario</td>

<td><input name="salario" type="text" id="salario" maxlength="5" class="textBox" /></td>

</tr>

<tr>

<td>Endereco</td>

<td><input name="endereco" type="text" id="endereco" maxlength="30" class="textBox" /></td>

</tr>

<tr>

<td>Bairro</td>

<td><input name="bairro" type="text" id="bairro" maxlength="20" class="textBox" /></td>

</tr>

<tr>

<td>Cidade</td>

<td><input name="cidade" type="text" id="cidade" maxlength="45" class="textBox" /></td>

</tr>

<tr>

<td>Estado</td>

<td><select name="estados" id="estados" class="textBox" >

<?php

while($l = mysql_fetch_array($re)) {

$id = $l["id_estado];

$estado = $l["estado"];

$uf = $l["uf"];

echo "<option value=\"$id\">$uf - $estado</option>\n";

}

@mysql_close();

?>

</select> </td>

</tr>

<tr>

<td>Login</td>

<td><input name=login" type="text" id="login" maxlength="40" class="textBox" /></td>

</tr>

<tr>

<td>Senha</td>

<td><input name="senha" type="password" id="senha" maxlength="10" class="textBox" /></td>

</tr>

<tr>

<td>&nbsp;</td>

<td><input type="submit" name="Submit" value="Salvar" style="cursor:pointer;" /></td>

</tr>

</table>

</form>

</body>

</html>

config.php

<?php

define("SERVIDOR", "localhost");

define("USUARIO", "root");

define("SENHA", "");

define("BANCO", "cadastro");

?>

editar.php

<?php

if(file_exists("init.php")) {

require "init.php";

} else {

echo "Arquivo init.php não foi encontrado";

exit;

}

if(!function_exists("Abre_Conexao")) {

echo "Erro o arquivo init.php foi auterado, não existe a função Abre_Conexao";

exit;

}

$id = $_GET["id];

Abre_Conexao();

$re = mysql_query("select count(*) as total from usuarios where id_usuario = $id");

$total = mysql_result($re, 0, "total");

if($total == 1) {

$re = mysql_query("select * from usuarios, estados where estados.id_estado = usuarios.fk_estado and usuarios.id_usuario = $id");

$dados = mysql_fetch_array($re);

}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Cadastro</title>

<style>

<!--

.textBox { border:1px solid gray; width:200px;}

-->

</style>

</head>

<body>

<form id="form1" name="form1" method="post" action="salvar_edicao.php">

<input type="hidden" name="id" value="<?php echo $id; ?>" />

<table width="400" border="0" align="center">

<tr>

<td width="145">Nome</td>

<td width="245"><input name="nome" type="text" id="nome" maxlength="45" class="textBox" value="<?php echo $dados["nome"]; ?>" /></td>

</tr>

<tr>

<td>Email</td>

<td><input name=email" type="text" id="email" maxlength="64" class="textBox" value="<?php echo $dados["email]; ?>" /></td>

</tr>

<tr>

<td>Data Nascimento</td>

<td>

<?php

$arr = explode("-", $dados["data_nascimento"]);

echo Seleciona_Item($arr[2], monta_select("dia", 1, 31));

echo Seleciona_Item($arr[1], monta_select("mes", 1, 12));

echo Seleciona_Item($arr[0], monta_select("ano", 1940, 1988));

?>

</td>

</tr>

<tr>

<td>Sexo</td>

<td><input name=sexo" type="radio" value="M" <?php echo $dados["sexo] == "M" ? "checked=\"checked\"" : ""; ?> /><label>Masculino</label>

<input name="sexo" type="radio" value="F" <?php echo $dados["sexo"] == "F" ? "checked=\"checked\"" : ""; ?> /> <label>Feminino</label></td>

</tr>

<tr>

<td>Preferencias de Filmes </td>

<td><select name=preferencias[]" class="textBox" multiple="multiple" id="preferencias">

<?php

$combo = "<option value=\"R\">Romance</option>

<option value=\"S\">Suspense</option>

<option value=\"P\">Policial</option>

<option value=\"F\">Ficção</option>";

$arr = explode(",", $dados["preferencias]);

for($i = 0; $i < count($arr); $i++) {

$combo = preg_replace("#<option value=\"{$arr[$i]}\">#is", "<option value=\"{$arr[$i]}\" selected=\"selected\">", $combo);

}

echo $combo;

?>

</select>

</td>

</tr>

<tr>

<td>Salario</td>

<td><input name=salario" type="text" id="salario" maxlength="5" class="textBox" /></td>

</tr>

<tr>

<td>Endereco</td>

<td><input name="endereco" type="text" id="endereco" maxlength="30" class="textBox" /></td>

</tr>

<tr>

<td>Bairro</td>

<td><input name="bairro" type="text" id="bairro" maxlength="20" class="textBox" /></td>

</tr>

<tr>

<td>Cidade</td>

<td><input name="cidade" type="text" id="cidade" maxlength="45" class="textBox" /></td>

</tr>

<tr>

<td>Estado</td>

<td><select name="estados" id="estados" class="textBox" >

<option value="0">Selecione</option>

<?php

$re = mysql_query("select * from estados order by estado");

if(mysql_errno() != 0) {

if(!isset($erros)) {

echo "Erro o arquivo init.php foi auterado, não existe $erros";

exit;

}

echo $erros[mysql_errno()];

exit;

}

while($l = mysql_fetch_array($re)) {

$id = $l["id_estado];

$estado = $l["estado"];

$uf = $l["uf"];

echo Seleciona_Item($dados["id_estado"], "<option value=\"$id\">$uf - $estado</option>");

}

@mysql_close();

?>

</select> </td>

</tr>

<tr>

<td>Login</td>

<td><input name=login" type="text" id="login" maxlength="40" class="textBox" /></td>

</tr>

<tr>

<td>Senha</td>

<td><input name="senha" type="password" id="senha" maxlength="10" class="textBox" /></td>

</tr>

<tr>

<td>&nbsp;</td>

<td><input type="submit" name="Submit" value="Salvar" style="cursor:pointer;" /></td>

</tr>

</table>

</form>

</body>

</html>

excluir.php

<?php

if($_SERVER["REQUEST_METHOD]== "GET") {

if(file_exists("init.php")) {

require "init.php";

} else {

echo "Arquivo init.php não foi encontrado";

exit;

}

if(!function_exists("Abre_Conexao")) {

echo "Erro o arquivo init.php foi auterado, não existe a função Abre_Conexao";

exit;

}

$id = $_GET["id"];

Abre_Conexao();

if(mysql_query("delete from usuarios where id_usuario = $id")) {

if(mysql_affected_rows() == 1){

echo "Registro deletado com sucesso<br />";

}

}

}

?>

<a href=listar.php">Voltar</a>

funcoes.php

<?php

function monta_select($campo, $start, $end) {

$select = "<select name=\"$campo\" id=\"$campo\">\n";

for($i = $start; $i <= $end; $i++) {

$select .= "\t<option value=\"". sprintf("%02d", $i) ."\">".sprintf("%02d", $i)."</option>\n";

}

$select .= "</select>\n";

return $select;

}

function monta_combo($campo) {

if($campo == "") {

return false;

}

$select = "<select name=\"campo\">\n";

for($i = 0; $i < count($campo); $i++) {

$select .= "\t<option value=\"$i\">{$campo[$i]}</option>\n";

}

$select .= "</select>\n";

return $select;

}

function Pega_Preferencia($campo) {

$campo = explode(",", $campo);

for($i = 0; $i < count($campo); $i++) {

switch ($campo[$i]) {

case "R":

$preferencia[] = "Romantico";

break;

case "S":

$preferencia[] = "Suspense";

break;

case "P":

$preferencia[] = "Policial";

break;

case "F":

$preferencia[] = "Ficção";

break;

}

}

return isset($preferencia) ? $preferencia : false;

}

function Seleciona_Item($valor, $campo) {

return preg_replace("#<option value=\"$valor\">#is", "<option value=\"$valor\" selected=\"selected\">", $campo);

}

?>

index.html

<a href="cadastro.php">Cadastrar Usuarios</a><br />

<a href="listar.php">Listar Usuarios</a><br />

init.php

<?php

error_reporting(E_ALL);

@ini_set('display_errors', '1');

@ini_set('register_globals', '0');

if (version_compare(phpversion(), "4", ">")) {

if (!extension_loaded('mysql')) {

echo( "não esta habilitada a dll Mysql" );

exit;

}

}

if(file_exists("funcoes.php")) {

include "funcoes.php";

} else {

echo "Arquivo funcoes.php não encontrado";

exit;

}

if(file_exists("config.php")) {

include "config.php";

if (!defined("SERVIDOR") or !defined("USUARIO") or !defined("SENHA") or !defined("BANCO")){

echo "Variaveis de conexao não definidas, configure corretamente o arquivo config.php";

exit;

}

}

$erros[2005] = "Esse servidor não existe";

$erros[2003] = "Servidor Mysql desligado";

$erros[1045] = "Usuario ou senha invalido";

$erros[1049] = "Banco de dados não encontrado";

$erros[1146] = "Erro de sql a tabela não existe";

$erros[1062] = "Erro campo unico na tabela, não pode cadastrar pois ele já existe";

function Abre_Conexao() {

global $erros;

@mysql_connect(SERVIDOR, USUARIO, SENHA);

if(mysql_errno() != 0) {

echo $erros[mysql_errno()];

exit;

}

@mysql_select_db(BANCO);

if(mysql_errno() != 0) {

echo $erros[mysql_errno()];

exit;

}

}

?>

listar.php

<a href="index.html">Voltar</a>

<?php

if(file_exists("init.php")) {

require "init.php";

} else {

echo "Arquivo init.php não foi encontrado";

exit;

}

if(!function_exists("Abre_Conexao")) {

echo "Erro o arquivo init.php foi auterado, não existe a função Abre_Conexao";

exit;

}

Abre_Conexao();

$re = mysql_query("SELECT * FROM usuarios INNER JOIN estados ON usuarios.fk_estado = estados.id_estado ORDER BY usuarios.nome;");

if(mysql_errno() != 0) {

if(!isset($erros)) {

echo "Erro o arquivo init.php foi auterado, não existe $erros";

exit;

}

echo $erros[mysql_errno()];

exit;

}

?>

<table width="100%" border="1">

<tr>

<td>Ações</td>

<td>Nome</td>

<td>Email</td>

<td>Data Nasc.</td>

<td>Sexo</td>

<td>Preferencias</td>

<td>salario</td>

<td>Endere&ccedil;o</td>

<td>Bairro</td>

<td>Cidade</td>

<td>Estado</td>

<td>Login</td>

</tr>

<?php

while($l = mysql_fetch_array($re)) {

$id = $l["id_usuario];

$nome = $l["nome"];

$email = $l["email"];

$data = implode("/", array_reverse(explode("-", $l["data_nascimento"])));

$sexo = $l["sexo"] == "M" ? "Masculino" : "Feminino";

$preferencia = Pega_Preferencia($l["preferencias"]);

$salario = $l["salario"];

$endereco = $l["endereco"];

$bairro = $l["bairro"];

$cidade = $l["cidade"];

$estado = $l["estado"];

$login = $l["login"];

echo "

<tr>

<td><a href=\"editar.php?id=$id\">[Editar]</a> <a href=\"excluir.php?id=$id\">[Excluir]</a></td>

<td>&nbsp;$nome</td>

<td>&nbsp;$email</td>

<td>&nbsp;$data</td>

<td>&nbsp;$sexo</td>

<td>&nbsp;". monta_combo($preferencia). "</td>

<td>&nbsp;". number_format($salario, 2, ",", "."). "</td>

<td>&nbsp;$endereco</td>

<td>&nbsp;$bairro</td>

<td>&nbsp;$cidade</td>

<td>&nbsp;$estado</td>

<td>&nbsp;$login</td>

</tr>\n";

}

@mysql_close();

?>

</table>

salvar.php

<?php

if($_SERVER["REQUEST_METHOD]== "POST") {

$nome = $_POST["nome"];

$email = $_POST["email"];

$data = "{$_POST["ano"]}-{$_POST["mes"]}-{$_POST["dia"]}";

$sexo = $_POST["sexo"];

$preferencias = isset($_POST["preferencias"]) ? implode(",", $_POST["preferencias"]) : "";

$salario = $_POST["salario"];

$endereco = $_POST["endereco"];

$bairro = $_POST["bairro"];

$cidade = $_POST["cidade"];

$estados = $_POST["estados"];

$login = $_POST["login"];

$senha = $_POST["senha"];

if(file_exists("init.php")) {

require "init.php";

} else {

echo "Arquivo init.php não foi encontrado";

exit;

}

if(!function_exists("Abre_Conexao")) {

echo "Erro o arquivo init.php foi auterado, não existe a função Abre_Conexao";

exit;

}

Abre_Conexao();

if(@mysql_query("INSERT INTO usuarios VALUES ( NULL , '$nome', '$email', '$data' , '$sexo',

'$preferencias', '$salario', '$endereco', '$bairro', '$cidade', '$estados', '$login', MD5( '$senha' ) )")) {

if(mysql_affected_rows() == 1){

echo "Registro efetuado com sucesso<br />";

}

} else {

if(mysql_errno() == 1062) {

echo $erros[mysql_errno()];

exit;

} else {

echo "Erro não foi possivel efetuar o cadastro";

exit;

}

@mysql_close();

}

}

?>

<a href=index.html">Voltar</a>

salvar_edicao.php

<?php

if($_SERVER["REQUEST_METHOD]== "POST") {

$id = $_POST["id"];

$nome = $_POST["nome"];

$email = $_POST["email"];

$data = "{$_POST["ano"]}-{$_POST["mes"]}-{$_POST["dia"]}";

$sexo = $_POST["sexo"];

$preferencias = isset($_POST["preferencias"]) ? implode(",", $_POST["preferencias"]) : "";

$salario = $_POST["salario"];

$endereco = $_POST["endereco"];

$bairro = $_POST["bairro"];

$cidade = $_POST["cidade"];

$estados = $_POST["estados"];

$login = $_POST["login"];

$senha = $_POST["senha"];

if(file_exists("init.php")) {

require "init.php";

} else {

echo "Arquivo init.php não foi encontrado";

exit;

}

if(!function_exists("Abre_Conexao")) {

echo "Erro o arquivo init.php foi auterado, não existe a função Abre_Conexao";

exit;

}

Abre_Conexao();

if(@mysql_query("UPDATE usuarios SET nome = '$nome',

email = '$email',

sexo = '$sexo',

preferencias = '$preferencias',

salario = '$salario',

endereco = '$endereco',

bairro = '$bairro',

cidade = '$cidade',

fk_estado = '$estados',

login = '$login',

senha = MD5( '$senha' ) WHERE id_usuario = $id")) {

if(mysql_affected_rows() == 1){

echo "Registro atualizado com sucesso";

}

} else {

if(mysql_errno() == 1062) {

echo $erros[mysql_errno()];

exit;

} else {

echo "Erro não foi possivel efetuar a edição";

exit;

}

@mysql_close();

}

}

?>

<a href="listar.php">Voltar</a>

tabela.sql

CREATE TABLE usuarios (

id_usuario SMALLINT ( 5 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,

nome VARCHAR ( 45 ) NOT NULL,

email VARCHAR ( 64 ) NOT NULL UNIQUE,

data_nascimento DATE NOT NULL,

sexo ENUM ( 'M', 'F' ) NOT NULL,

preferencias SET ( 'R', 'S', 'P', 'F' ) NOT NULL COMMENT 'R=Romance;S=Suspense;P=Policial;F=Ficção',

salario DECIMAL ( 10,2 ) NOT NULL,

endereco VARCHAR ( 30 ) NOT NULL,

bairro VARCHAR ( 20 ) NOT NULL,

cidade VARCHAR ( 45 ) NOT NULL,

fk_estado SMALLINT ( 5 ) UNSIGNED NOT NULL,

login VARCHAR ( 40 ) NOT NULL,

senha CHAR ( 32 ) NOT NULL

);

CREATE TABLE estados (

id_estado SMALLINT ( 5 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,

uf CHAR ( 2 ) NOT NULL,

estado VARCHAR ( 19 ) NOT NULL UNIQUE

);

INSERT INTO estados VALUES ( NULL , "AC", "Acre");

INSERT INTO estados VALUES ( NULL , "AL", "Alagoas");

INSERT INTO estados VALUES ( NULL , "AP", "Amapá");

INSERT INTO estados VALUES ( NULL , "AM", "Amazonas");

INSERT INTO estados VALUES ( NULL , "BA", "Bahia");

INSERT INTO estados VALUES ( NULL , "CE", "Ceará");

INSERT INTO estados VALUES ( NULL , "DF", "Distrito Federal");

INSERT INTO estados VALUES ( NULL , "ES", "Espirito Santo");

INSERT INTO estados VALUES ( NULL , "GO", "Goiás");

INSERT INTO estados VALUES ( NULL , "MA", "Maranhão");

INSERT INTO estados VALUES ( NULL , "MT", "Mato Grosso");

INSERT INTO estados VALUES ( NULL , "MS", "Mato Grosso do Sul");

INSERT INTO estados VALUES ( NULL , "MG", "Minas Gerais");

INSERT INTO estados VALUES ( NULL , "PA", "Pará");

INSERT INTO estados VALUES ( NULL , "PB", "Paraíba");

INSERT INTO estados VALUES ( NULL , "PR", "Paraná");

INSERT INTO estados VALUES ( NULL , "PE", "Pernambuco");

INSERT INTO estados VALUES ( NULL , "PI", "Piauí");

INSERT INTO estados VALUES ( NULL , "RN", "Rio Grande do Norte");

INSERT INTO estados VALUES ( NULL , "RS", "Rio Grande do Sul");

INSERT INTO estados VALUES ( NULL , "RJ", "Rio de Janeiro");

INSERT INTO estados VALUES ( NULL , "RO", "Rondônia");

INSERT INTO estados VALUES ( NULL , "RR", "Roraima");

INSERT INTO estados VALUES ( NULL , "SC", "Santa Catarina");

INSERT INTO estados VALUES ( NULL , "SP", "São Paulo");

INSERT INTO estados VALUES ( NULL , "SE", "Sergipe");

INSERT INTO estados VALUES ( NULL , "TO", "Tocantins");

Link para o comentário
Compartilhar em outros sites

  • 0

Bom tenho os 2 quero deixa os 2 1 só tipo

Mu sistema de login ele tah pegando otra tabela e o sistema de cadastro ele tah gravando os cadastros em otra tabela alguma coisa asim

queria que quando cadastra-se o cadastro vai pro lado de login ou o login procura o lado do cadastro sei lá queria dos 2 faze um

pro pessoal logar no meu site eu já aprendi blokiar pagina pra deixa só pra cadastrados bom acho que é isso vo postar os arquivos pra download

Arquivos.rar

Link para o comentário
Compartilhar em outros sites

  • 0

Não é por nada, mas nesse seu outro tópico eu coloquei o seguinte link:

http://www.linhadecodigo.com.br/Artigo.aspx?id=258

Se você tivesse lido teria visto isso

4 - Verificando se usuário está logado no sistema

Agora, o script "verifica.php" que verifica a sessão do usuário se ele está logado ou não. Caso não esteja logado, o redireciona para a página de login.

<?php

// Inicia sessões

session_start();

// Verifica se existe os dados da sessão de login

if(!isset($_SESSION["id_usuario"]) || !isset($_SESSION["nome_usuario"]))

{

// Usuário não logado! Redireciona para a página de login

header("Location: login.html");

exit;

}

?>

No caso ele redireciona para a página login.html, no seu caso basta trocar:

header("Location: login.html");

Por

echo "Pagina bloqueada apenas membros logados pode ver";

Link para o comentário
Compartilhar em outros sites

  • 0
Leonardo.j., acho que já é o quarto tópico que você abre sobre o mesmo assunto, é sempre bom ter um bom senso, centraliza tudo em um tópico apenas, e aproveita e dá uma lida nas regras, espero realmente que você queira fazer parte da comunidade, mas que o faça de modo correto.
Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152k
    • Posts
      651,7k
×
×
  • Criar Novo...