Código Funciona em Localhost e na Web não funciona
Pessoal estou com um probleminha aqui é que o meu código dá certo em localhost e quando eu subo para web não funciona, depois de alguns teste identifiquei que um método que chama dá bronca na web e em localhost não, mas quando tiro o método que verifica se o usuário está logado o código HTML funciona normal mais faz o login :upset: .
Segue o código da página index de login:
<?php
ob_start();
session_start();
require_once ("classes/config.php");
if (isset($_POST["entrar"])):
$logar = new Login();
$logar->setUsuario($_POST['usuario']);
$logar->setSenha(md5($_POST['senha']));
$logar->logar();
if($logar->getErro()):
$erro = $logar->getErro();
else:
header("Location: painel/index.php");
endif;
endif;
Login::logado();
ob_end_flush();
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Suporte HS</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/reset.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body class="body">
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4 logo-hs">
<img src="img/logo-hs.png" alt="Suporte HS" class="center-block" />
</div>
<div class="col-md-4 col-md-offset-4 msg">
<?php echo isset($erro) ? '<div class="alert alert-danger">' . $erro . '</div>' : ""; ?>
</div>
<div class="col-md-4 col-md-offset-4">
<form class="formlogin" action="" method="POST">
<div class="form-group">
<label for="login">Login</label>
<input type="email" class="form-control" id="login" name="usuario" placeholder="Seu Login">
</div>
<div class="form-group">
<label for="senha">Senha</label>
<input type="password" class="form-control" id="senha" name="senha" placeholder="Senha">
</div>
<input type="submit" class="btn btn-default btn-login" name="entrar" value="Entrar" />
</form>
</div>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>
Página Config:
<?php
/**
* Description of Autoload
*
* @author Roberto
*/
//function __autoload($classes) {
//
// $pastas = array('classes/','interface/');
//
// if(file_exists("{$pastas}" . $classes . ".php")):
// include_once "{$pastas}{$classes}.php";
// else:
// echo "Não foi possivel carregar a Classe {$classes}";
// endif;//}
// AUTO LOAD DE CLASSES ####################
function __autoload($Class) {
$cDir = ['conn', 'actions', 'interface'];
$iDir = null;
foreach ($cDir as $dirName):
if (!$iDir && file_exists(__DIR__ . "\\{$dirName}\\{$Class}.php") && !is_dir(__DIR__ . "\\{$dirName}\\{$Class}.class.php")):
include_once (__DIR__ . "\\{$dirName}\\{$Class}.php");
$iDir = true;
endif;
endforeach;
if (!$iDir):
trigger_error("Não foi possível incluir {$Class}.php", E_USER_ERROR);
die;
endif;
}
Classe de Conexão.
<?php
/**
* Faz conexão com o banco de dados
*
* @author Roberto
*/
abstract class Conexao {
const USER = "robertof_suporte";
const PASS = "minhasenha";
private static $instance = null;
private static function conectar() {
try {
if (self::$instance == null):
$dsn = "mysql:host=localhost;dbname=robertof_suporte";
self::$instance = new PDO($dsn, self::USER, self::PASS);
self::$instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
endif;
} catch (PDOException $e) {
echo "Erro: " . $e->getMessage();
}
return self::$instance;
}
protected static function getDB() {
return self::conectar();
}
}
Classe de login:
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of Login
*
* @author Roberto
*/
class Login extends Conexao implements iLogin {
private $Usuario;
private $Senha;
private $Erro;
function getUsuario() {
return $this->Usuario;
}
function getSenha() {
return $this->Senha;
}
function getErro() {
return $this->Erro;
}
function setUsuario($Usuario) {
$this->Usuario = $Usuario;
}
function setSenha($Senha) {
$this->Senha = $Senha;
}
function setErro($Erro) {
$this->Erro = $Erro;
}
public function deslogar() {
}
public function logar() {
$pdo = parent::getDB();
try {
$logar = $pdo->prepare("SELECT * FROM usuarios WHERE email = :usuario AND senha = :senha");
$logar->bindValue(":usuario", $this->getUsuario(), PDO::PARAM_STR);
$logar->bindValue(":senha", $this->getSenha(), PDO::PARAM_STR);
$logar->execute();
} catch (PDOException $e) {
echo "Erro: ".$e->getMessage();
}
if($logar->rowCount() == 1):
$dados = $logar->fetch(PDO::FETCH_ASSOC);
$_SESSION['logado'] = true;
$_SESSION['id_user'] = $dados['id_user'];
$_SESSION['nome'] = $dados['nome'];
$_SESSION['email'] = $dados['email'];
$_SESSION['nivel'] = $dados['nivel'];
$_SESSION['status'] = $dados['status'];
else:
$this->setErro("<b>Erro:</b> Favor informe um Usúario e uma Senha válidos.");
endif;
}
public static function verificaLogado() {
if(!isset($_SESSION['logado'])):
header("Location: ../index.php");
endif;
}
public static function logado() {
if(isset($_SESSION['logado'])):
header("Location: ". SITE_BASE_PAINEL ."");
endif;
}
}
O pior que tudo isso ai acima funciona em localhost mais na web não :upset:
Agradeço a ajuda de todos :D
Discussão (5)
Carregando comentários...