Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!--index.php -->
- <?php
- session_start();
- require 'config.php';
- if(empty($_SESSION['logado'])){
- header("Location: login.php");
- exit;
- }
- $id = $_SESSION['logado'];
- $sql = $pdo->prepare("SELECT nome FROM usuarios WHERE id = :id");
- $sql->bindValue(":id",$id);
- $sql->execute();
- if($sql->rowCount() > 0){
- $sql = $sql->fetch();
- $nome = $sql['nome'];
- }else{
- header("Location: login.php");
- }
- ?>
- <h1>Sistem de Marketing</h1>
- <h3><?php echo "Beem vindo: ".$nome; ?></h3>
- <a href="cadastro.php">Cadastre um usuário</a>
- ?>
- <!--fim index -->
- <!--Cadastro.php -->
- <?php
- session_start();
- require 'config.php';
- if(!empty($_POST['nome']) && !empty($_POST['email'])){
- $nome = addslashes($_POST['nome']);
- $email = addslashes($_POST['email']);
- $id_pai = $_SESSION['logado'];
- $senha = md5($email);
- $sql = $pdo->prepare("SELECT * FROM usuarios WHERE email = :email");
- $sql->bindValue(":email",$email);
- $sql->execute();
- if($sql->rowCount() == 0){
- $sql = $pdo->prepare("INSERT INTO usuarios (id_pai, nome, email, senha) VALUES(:id_pai, :nome, :email, :senha)");
- $sql->bindValue(":id_pai",$id_pai);
- $sql->bindValue(":nome",$nome);
- $sql->bindValue(":email",$email);
- $sql->bindValue(":senha",$senha);
- $sql->execute();
- header("Location: index.php");
- exit;
- }else{
- echo " Usuário já existe ";
- }
- }
- ?>
- <form method="POST">
- Nome:<br/>
- <input type="text" name="nome"/><br/><br/>
- Email:<br/>
- <input type="text" name="email"/><br/><br/>
- <input type="submit" value="Cadastrar">
- </form>
- <!--Fim cadastro -->
- <!--Login.php -->
- <?php
- session_start();
- require 'config.php';
- if(isset($_POST['email']) && !empty($_POST['email'])){
- $email = addslashes($_POST['email']);
- $senha = md5(addslashes($_POST['senha']));
- $sql = $pdo->prepare("SELECT * FROM usuarios WHERE email = :email AND senha = :senha");
- $sql->bindValue(":email",$email);
- $sql->bindValue(":senha",$senha);
- $sql->execute();
- if($sql->rowCount() > 0){
- $sql = $sql->fetch();
- $_SESSION['logado'] = $sql['id'];
- header("Location: index.php");
- exit;
- }else{
- echo "Usuário ou senha inválida";
- }
- }
- ?>
- <form method="POST">
- Email:<br/>
- <input type="text" name="email"/><br/><br/>
- Senha:<br/>
- <input type="password" name="senha"/><br/><br/>
- <input type="submit" value="Logar">
- </form>
- <!--fim login -->
- <!--config.php -->
- <?php
- try{
- $pdo = new PDO("mysql:dbname=projeto_mmn; host=localhost", "root", "");
- }catch(PDOException $e){
- echo "Erro: ".$e->getMessage();
- }
- ?>
- <!--fim config -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement