Created
January 30, 2019 18:41
-
-
Save SpookNyan/bfa4bd0ccfd9c1937159752e6f2d34e3 to your computer and use it in GitHub Desktop.
(MySQL)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// inclui o arquivo de configura��o do sistema | |
include "config_sistema.php"; | |
// recebe dados do formulario | |
$nome = $_POST['nome']; | |
$login = $_POST['login']; | |
$senha = $_POST['senha']; | |
$rep_senha = $_POST['rep_senha']; | |
$email = $_POST['email']; | |
// verifica se o usuario digitou o login | |
if($login == "") { | |
echo "Digite seu login!"; | |
exit; | |
} else { | |
// se o usuario digitou o login ele verifica | |
// se esta disponivel | |
$consulta = mysql_query("select * from cadastro where login = '$login'"); | |
$linha = mysql_num_rows($consulta); | |
if($linha != 0) { | |
echo "O nome de usu�rio que voc�<br> | |
digitou j� existe tente outro!"; | |
exit; | |
} | |
} | |
// verifica se o usuario digitou a senha | |
if($senha == "") { | |
echo "Digite sua senha!"; | |
exit; | |
} else { | |
// se o usuario digitou a senha | |
// vamos comparar com a contra senha | |
if($senha != $rep_senha) { | |
echo "Senha invalida!"; | |
exit; | |
} | |
} | |
// verifica se o usuario digitou o nome | |
if($nome == "") { | |
echo "Digite seu nome!"; | |
exit; | |
} | |
// verifica o email | |
if($email == "") { | |
echo "Digite o seu e-mail!"; | |
exit; | |
} | |
// verifica se o usuario digitou o login | |
if($login== "") { | |
echo "Digite seu login!"; | |
exit; | |
} else { | |
// se o usuario digitou a matricula ele verifica | |
// se esta j� foi cadastrada | |
$consulta = mysql_query("select * from cadastro where login = '$login'"); | |
$linha = mysql_num_rows($consulta); | |
if($linha != 0) { | |
echo "ERRO: O login informado j� est� cadastrado.<br> | |
Verifique se voc� digitou corretamente!"; | |
exit; | |
} | |
} | |
// faz consulta no banco para inserir os dados do usuario | |
$sql = "insert into cadastro (nome,login,senha,rep_senha,email) values ('$nome','$login','$senha','$rep_senha','$email')"; | |
$consulta = mysql_query($sql); | |
// verifica se o usuario foi cadastrado | |
if($consulta) { | |
echo "<font color=green><b> | |
Voc� foi cadastrado com sucesso!<br> | |
Click <a href=index.php>aqui</a> para efetuar o login. | |
</font></b>"; | |
exit; | |
} else { | |
echo "N�o foi possivel efetuar o seu cadastro<br> | |
tente mais tarde pode ser um problema no servidor!<br> | |
Click <a href=index.php>aqui</a> para ir ate a home page do sistema."; | |
exit; | |
} | |
?> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$nome = $_POST(nome); | |
if($nome == "") { | |
echo "Digite um nome!"; | |
exit; | |
} else { | |
print $nome; | |
exit;} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<form name="media" method="post" action="media.php"> | |
<table width="625" border="0"> | |
<tr> | |
<td>Nota 1:</td> | |
<td><input name="n1" type="text" id="n1" size="4" maxlength="4" /> | |
</tr> | |
<tr> | |
<td>Nota 2:</td> | |
<td><input name="n2" type="text" id="n2" size="4" maxlength="4" /> | |
</tr> | |
<tr> | |
<td>Nota 3:</td> | |
<td><input name="n3" type="text" id="n3" size="4" maxlength="4" /> | |
</tr> | |
<td>Nota 4:</td> | |
<td><input name="n4" type="text" id="n4" size="4" maxlength="4" /> | |
</tr> | |
<tr> | |
<td> | |
<input type="submit" value="Calcular" name="submit"> | |
</td> | |
</tr> | |
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<form name="media" method="post" action="media.php"> | |
<table width="625" border="0"> | |
<tr> | |
<td width="69">Nome:</td> | |
<td width="546"><input name="nome" type="text" id="nome" size="70" maxlength="60" /> | |
<span class="style1">*</span></td> | |
</tr> | |
<td>Login:</td> | |
<td><input name="login" type="text" id="login" maxlength="12" /> | |
<span class="style1">*</span></td> | |
</tr> | |
<tr> | |
<td>Senha:</td> | |
<td><input name="senha" type="password" id="senha" maxlength="12" /> | |
<span class="style1">*</span></td> | |
</tr> | |
<tr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// faz conex�o com o servidor MySQL | |
$local_serve = "localhost"; // local do servidor | |
$usuario_serve = "root"; // nome do usuario | |
$senha_serve = ""; // senha | |
$banco_de_dados = "cadastros"; // nome do banco de dados | |
$conn = @mysql_connect($local_serve,$usuario_serve,$senha_serve) or die ("O servidor n�o responde!"); | |
// conecta-se ao banco de dados | |
$db = @mysql_select_db($banco_de_dados,$conn) | |
or die ("N�o foi possivel conectar-se ao banco de dados!"); | |
// dados do administrador s�o de estrema importancia que sem eles | |
// o adminstrador n�o tera acesso as paginas de administra��o | |
$login_admin = "root"; // nome do administrador | |
$senha_admin = ""; // senha administrador | |
$email_admin = ""; // email do administrador | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<form name="cadastrar" method="post" action="cadastra_usuario.php"> | |
<table width="625" border="0"> | |
<tr> | |
<td width="69">Nome:</td> | |
<td width="546"><input name="nome" type="text" id="nome" size="70" maxlength="60" /> | |
<span class="style1">*</span></td> | |
</tr> | |
<td>Login:</td> | |
<td><input name="login" type="text" id="login" maxlength="12" /> | |
<span class="style1">*</span></td> | |
</tr> | |
<tr> | |
<td>Senha:</td> | |
<td><input name="senha" type="password" id="senha" maxlength="12" /> | |
<span class="style1">*</span></td> | |
</tr> | |
<tr> | |
<tr> | |
<td>Repita a Senha:</td> | |
<td><input name="rep_senha" type="password" id="rep_senha" maxlength="12" /> | |
<span class="style1">*</span></td> | |
</tr> | |
<td>Email:</td> | |
<td><input name="email" type="text" id="email" size="70" maxlength="60" /> | |
<span class="style1">*</span></td> | |
</tr> | |
<tr> | |
<td colspan="2"><p> | |
<input name="cadastrar" type="submit" id="cadastrar" value="cadastra_usuario" /> | |
<input name="limpar" type="reset" id="limpar" value="Limpar" /> | |
<p> </p></td> | |
</tr> | |
</table> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Teste PHP</title> | |
</head> | |
<body> | |
<?php echo '<p> imprimir um texto qualquer </p>'; ?> | |
<h5> | |
1- <a href="pagina2.html"> mais exemplos </a> | |
</h5><br> | |
<h5> | |
2- <a href="mediasimples.php"> Media s� php </a> | |
</h5> <br> | |
<h5> | |
3- <a href="calcularmedia.html"> Calcular a media com formul�rio </a> | |
</h5> <br> | |
<h5> | |
4- <a href="formulario.html"> Formul�rio para cadastro </a> | |
</h5> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// inclui o arquivo de configura��o do sistema | |
include "config_sistema.php"; | |
// recebe dados do formulario | |
$login = $_POST['login']; | |
$senha = $_POST['senha']; | |
// verifica se o usuario existe | |
$consulta = mysql_query("select * from dados_usuarios where Login='$login'"); | |
$campos = mysql_num_rows($consulta); | |
if($campos != 0) { | |
// se o usuario existi verifica a senha dele | |
if($senha != mysql_result($consulta,0,"Senha")) { | |
echo "<font color=red><b> | |
Senha incorreta! | |
</font></b>"; | |
exit; | |
} else { | |
// estiver tudo certo vamos ver se ele � o administrador | |
if($login == $login_admin) { | |
// se for o login do administrador vamos verificar a senha dele | |
// se � igual a do administrado | |
if($senha == $senha_admin) { | |
// se for o administrador vomos criar a sess�o | |
session_start(); | |
$_SESSION['login_usuario'] = $login; | |
$_SESSION['senha_usuario'] = $senha; | |
// redireciona o link para uma outra pagina | |
header("Location: Admin/listar_usuarios.php"); | |
} | |
} else { | |
// se o login n�o for do administrado vamos criar a sess�o dele | |
session_start(); | |
$_SESSION['login_usuario'] = $login; | |
$_SESSION['senha_usuario'] = $senha; | |
// redireciona o link para uma outra pagina | |
header("Location: home.php"); | |
} | |
} | |
} else { | |
echo "<font color=red><b> | |
O usuario n�o existe! | |
</font></b>"; | |
exit; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// inicializa a sess�o | |
session_start(); | |
// limpa a sess�o | |
$_SESSION = array(); // colocando a session com um array vazio faz com ela | |
// fique vazia sem nenhuma variavel nela, liberando o espa�o | |
// destroy a sess�o | |
session_destroy(); | |
// redireciona o link para a home page a pagina "index.php" | |
header("Location: login.php"); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$nota1 = 7.5; | |
$nota2 = 6; | |
$nota3 = 8; | |
$nota4 = 3 | |
$media = ($nota1 + $nota2 + $nota3 + $nota4)/4; | |
if ($media >= 7){ | |
echo "<p> A media � igual a .$media. Aluno Aprovado"; | |
} else if($media >= 4){ | |
echo "<p> A media � igual a .$media. Aluno na Final"; | |
}else{ | |
"<p> A media � igual a $media.Aluno j� era t� REPROVADO"; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html lang="pt-br"> | |
<?php | |
$nota1 = $_POST['n1']; | |
$nota2 = $_POST['n2']; | |
$nota3 = $_POST['n3']; | |
$nota4 = $_POST['n4']; | |
$media = ($nota1 + $nota2 + $nota3 + $nota4)/4; | |
if ($media >= 7){ | |
echo "<p> A media do aluno igual a $media. Aluno APROVADO</p>"; | |
} else if($media < 4){ | |
echo "<p> A media do aluno igual a $media. Aluno ja era ta REPROVADO</p>"; | |
}else{ | |
echo "<p> A media do aluno igual a $media.Aluno na PROVA FINAL</p>"; | |
} | |
?> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//atribui um valor a variavel | |
$nota1 = 7; | |
$nota2 = 6.5; | |
$nota3 = 4; | |
$nota4 = 7; | |
// realiza a soma das variav�is de divide para ter a m�dia | |
$media = ($nota1 + $nota2 + $nota3 + $nota4)/4; | |
//verifica se a m�dia � maior ou igual a sete, caso a resposta seja NEGATIVA ela pula para o else if | |
if ($media >= 7){ | |
echo "<p> A media do aluno � igual a $media. Aluno Aprovado</p>"; | |
// como existem tres condi��es a descrita aqui deve ser apenas uma preposi��o, sen�o o la�o fica com erro | |
} else if($media < 4){ | |
echo "<p> A media do aluno � igual a $media. Aluno ja era ta Reprovado</p>"; | |
}else{ | |
echo "<p> A media do aluno � igual a $media.Aluno na Prova Final</p>"; | |
} | |
?> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo <p>Oi, Eu serei visto na sua tela</p> | |
<p>Oi, Eu tamb�m serei visto por voc�</p> | |
<p>E eu aqui novamente na sua tela, rs</p> | |
?> | |
<a href="formulario.html">Formulario</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
@session_start(); | |
// inclui o arquivo de configura��o do sistema | |
include "config_sistema.php"; | |
// verifica se a variavel existir | |
if(isset($_SESSION['login_usuario']) and isset($_SESSION['senha_usuario'])) { | |
// se existie as sess�es coloca os valores em uma varivel | |
$login_usuario = $_SESSION['login_usuario']; | |
$senha_usuario = $_SESSION['senha_usuario']; | |
} else { | |
$erro = urlencode("Voc� n�o esta logado!"); | |
header("Location: login.php"); | |
exit; | |
} | |
// verifica se as variaveis est�o atribuidas | |
if(!(empty($login_usuario) or empty($senha_usuario))) { | |
// se estiverem atribuidos vamos ver se exist o login | |
$consulta = mysql_query("select * from dados_usuarios where Login = '$login_usuario'"); | |
if(mysql_num_rows($consulta) == 1) { | |
// se o usuario exostir vamos verificar a senha | |
if($senha_usuario != mysql_result($consulta,0,"Senha")) { | |
// se a senha est� correta vamos apagar a | |
// sess�o que existia mas erra a errada | |
unset($_SESSION['login_usuario']); | |
unset($_SESSION['senha_usuario']); | |
$erro = urlencode("Voc� n�o esta logado!"); | |
header("Location: login.php"); | |
exit; | |
} | |
} else { | |
unset($_SESSION['login_usuario']); | |
unset($_SESSION['senha_usuario']); | |
$erro = urlencode("Voc� n�o esta logado!"); | |
header("Location: login.php"); | |
exit; | |
} | |
} else { | |
// caso as sess�es estarem vaizias | |
$erro = urlencode("Voc� n�o esta logado!"); | |
header("Location: login.php"); | |
exit; | |
} | |
mysql_close($conn); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment