How to create a button if you are logged in to an account

0

Hello, I would like to know when someone is logged in to create a button of type FILE. This created the system of registration and login, but I do not know how to know when it is logged in or not.

index.php

<!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=utf-8" />
<title>LuppBox</title>
<link rel="stylesheet" type="text/css" href="estilo_index.css"/>
</head>
<body bgcolor="#0099FF">
	<ul id="cabecario">
    	<li id="logo"><img src="fotos_site/logo.png" width="auto" height="60" /></li>  
        <li id="login_cadastro_css"><a href="login_cadastro.php">Login | Cadastro</a></li>         
    </ul>  
</body>
</html>

do_login.php

<?
	include "connection.php";
	
	$login = $_POST['login_entrar'];
	$senha = $_POST['senha_entrar'];
	
	$sql = mysqli_query($coneccao, "SELECT * FROM usuarios WHERE login = '$login'");	
	
	
	while($linha = mysqli_fetch_array($sql))
	{
		$senha_db = $linha['senha'];
	}
	
	$cont = mysqli_num_rows($sql);
	
	if($cont == 0)
	{		
		echo "<meta http-equiv='refresh' content='0; url=index.php'>
		<script type='text/javascript'>alert('Este usuario não existe')</script>";		
	}
	else
	{
		if($senha_db != $senha)
		{
			echo "<meta http-equiv='refresh' content='0; url=index.php'>
			<script type='text/javascript'>alert('Senha incorreta')</script>";	
		}
		else
		{
			session_start();
			
			$_SESSION['login_usuario'] = $login;	
			$_SESSION['senha_usuario'] = $senha;
			
			header("location: perfil.php");	
		}
	}
	
	mysqli_close($coneccao);
?>

hacer_cadastro.php

<?
	include "connection.php";
	
	$login = $_POST['login_entrar'];
	$senha = $_POST['senha_entrar'];
	
	$sql = mysqli_query($coneccao, "SELECT * FROM usuarios WHERE login = '$login'");	
	
	
	while($linha = mysqli_fetch_array($sql))
	{
		$senha_db = $linha['senha'];
	}
	
	$cont = mysqli_num_rows($sql);
	
	if($cont == 0)
	{		
		echo "<meta http-equiv='refresh' content='0; url=index.php'>
		<script type='text/javascript'>alert('Este usuario não existe')</script>";		
	}
	else
	{
		if($senha_db != $senha)
		{
			echo "<meta http-equiv='refresh' content='0; url=index.php'>
			<script type='text/javascript'>alert('Senha incorreta')</script>";	
		}
		else
		{
			session_start();
			
			$_SESSION['login_usuario'] = $login;	
			$_SESSION['senha_usuario'] = $senha;
			
			header("location: perfil.php");	
		}
	}
	
	mysqli_close($coneccao);
?>

I would like to put a FILE button there under that case you are logged in.

Thank you in advance.

    
asked by anonymous 01.05.2015 / 03:06

2 answers

0

How do I: I split page into small HTML blocks and I'm mounting under conditions, these conditions can be user logon this way:

session_start();
if((!isset($_SESSION['email']) == true) and (!isset($_SESSION['pass']) == true)){
        unset($_SESSION['email']); 
        unset($_SESSION['pass']);
        require_once 'components/modals/login-modal.php';
        require_once 'components/modals/create-account-modal.php';
    }else{
        require_once 'components/modals/logout-modal.php';
    }

Inside each file with .php extension has pure HTML that may or may not be coupled to the page. I use the super global $ _SESSION to store the logon values.

    
02.05.2015 / 15:37
2

Verify that the session is active by using the isset() method.     

    if ( isset($_SESSION["login_usuario"]) && isset($_SESSION["senha_usuario"])) {
        echo "<button type=\"button\">Botão</button>";
    } else {
        echo "Usuário não entrou.";
    }

One tip: You can set the session as a array , it is easier to use, see:

$login = "john_doe";
$senha = password_hash("soeuseiasenha", PASSWORD_DEFAULT);

$_SESSION["usuario"] = array();
$_SESSION["usuario"] = $login;
$_SESSION["senha"]   = $senha;

So to manipulate it, just do this:

if ( isset($_SESSION["usuario"]) ) {
    echo "...";
}
    
01.05.2015 / 03:26