0
I need help finding an error.
From the looks of it is a signature GOOD who’s showing up before the session_start()
.
I’ve searched all the files (by Notepad++
) and everyone is utf-8 sem BOM
.
The structure of my pages are that way:
<?php
require_once("testaAdmin.php");
require_once("../_global/_erros/erros.ini");
require_once("../_controlls/_util/Constantes.php");
$constantes = new Constantes();
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo $constantes->getTituloSiteAdmin(); ?></title>
<?php require_once("../_global/_meta/meta.ini"); ?>
<link rel="shortcut icon" type="image/x-icon" href="../_img/favicon.ico" />
<link type="text/css" rel="stylesheet" href="_global/_css/admin.css" />
<link type="text/css" rel="stylesheet" href="_global/_css/menu.css" />
</head>
<body>
<div id="topo"><h1><?php echo $constantes->getCabecalhoAdmin(); ?></h1></div>
<div id="menu">
<div class="sessoes"><?php require_once($menu.".php"); ?></div>
</div>
<div id="cont">
<?php
if($adminLogado->getTipo() != "s" && $_GET["admin"] != $adminLogado->getIdAdmins()) {
echo "<h1 class='h1CentralizadoAvisos'>Você não tem autorização para alterar este Administrador</h1>";
}
else {
?>
<div class="sessoes"><?php require_once("administradoresEditarConteudo.php"); ?></div>
<?php
}
?>
</div>
<div id="base">
<div class="sessoes"><?php require_once($base.".php"); ?></div>
</div>
<div id="final">
<div class="sessoes"><?php require_once("final.php"); ?></div>
</div>
</body>
</html>
The page testaAdmin.php
<?php
session_start();
header ("Content-Type: text/html; charset=utf-8");
require_once("../_controlls/_models/Admins.php");
require_once("../_controlls/_util/TestaAdmin.php");
$testaAdmin = new TestaAdmin();
$testaAdmin->validaAdmin($_SESSION["admin"]);
if(!$testaAdmin->getAdminValido()) {
echo "<script>location.href='index.php?erroadmin=".urlencode('Você não esta logado. Por favor faça Login')."'</script>";
} else {
$adminLogado = unserialize($_SESSION["admin"]);
if ($adminLogado->getBloqueado() == "s") {
session_destroy();
echo "<script>location.href='index.php?erroadmin=".urlencode('Administrador Bloqueado. Por favor faça contato com o gerente Administrador!')."'</script>";
}
$testaAdmin->setTextoCabecalho($adminLogado);
$testaAdmin->setMenu($adminLogado);
$testaAdmin->setBase($adminLogado);
$menu = $testaAdmin->getMenu();
$base = $testaAdmin->getBase();
echo $testaAdmin->getTextoCabecalho();
}
?>
All my pages follow this scheme and differ only in content pages.
Only one page this error
Warning: unserialize() expects parameter 1 to be string, object given in /home/dimoveis/public_html/novo/admin/testaAdmin.php on line 19
Fatal error: Call to a member function getBloqueado() on a non-object in /home/dimoveis/public_html/novo/admin/testaAdmin.php on line 21
Follows the Class TestaAdmin
<?php
class TestaAdmin {
private $adminValido;
private $textoCabecalho;
private $menu;
private $base;
public function __construct () {
}
public function validaAdmin ($sessao) {
$this->adminValido = isset($sessao) ? true : false;
}
public function setTextoCabecalho ($admin) {
$this->textoCabecalho = "<h6 style='text-align:center; width:1000px;'>Seja bem vindo Administrador ". $admin->getNome()." => <a href='logout.php' style='color:#000'>Sair</a></h6><br /><br />";
}
public function setMenu ($admin) {
$this->menu = ($admin->getTipo() == "s") ? "menu" : "menu2";
}
public function setBase ($admin) {
$this->base = ($admin->getTipo() == "c") ? "base2" : "base";
}
public function getAdminValido() {
return $this->adminValido;
}
public function getTextoCabecalho() {
return $this->textoCabecalho;
}
public function getMenu () {
return $this->menu;
}
public function getBase () {
return $this->base;
}
}
?>
Where is that mistake?
Class Admins
<?php
class Admins {
private $idAdmins;
private $tipo;
private $nome;
private $login;
private $senha;
private $bloqueado;
public function __construct ($_tipo, $_nome, $_login, $_senha, $_bloqueado) {
$this->tipo = $_tipo;
$this->nome = $_nome;
$this->login = $_login;
$this->senha = $_senha;
$this->bloqueado = $_bloqueado;
}
public function setIdAdmins ($_idAdmins) {
$this->idAdmins = $_idAdmins;
}
public function getIdAdmins () {
return $this->idAdmins;
}
public function getTipo () {
return $this->tipo;
}
public function getNome () {
return $this->nome;
}
public function getLogin () {
return $this->login;
}
public function getSenha () {
return $this->senha;
}
public function getBloqueado () {
return $this->bloqueado;
}
}
?>
logon.php
<?php
require_once "../_controlls/_conexao/Conexao.php";
require_once "../_controlls/_models/Admins.php";
require_once "../_controlls/_daos/AdminsDao.php";
$connection = new Conexao();
$conexao = $connection->abreConexao();
$AdminsDao = new AdminsDao($conexao);
if (!isset($_GET["acao"])) {
$erroadmin = (isset($_GET["erroadmin"])) ? $_GET["erroadmin"] : "";
?>
<h1>Logar no Sistema</h1><br />
<h3 class="avisos"><?php echo $erroadmin; ?></h3>
<form action="" method="post">
<input type="hidden" name="acao" value="logar" /> <br />
<label class="labelPequeno">Login</label><input type="text" class="typeTextMedio" maxlength="<?php echo $constantes->getLenLogin(); ?>" name="login" required /> <br /> <br />
<label class="labelPequeno">Senha</label><input type="password" class="typeTextMedio" maxlength="<?php echo $constantes->getLenSenha(); ?>" name="senha" required /> <br /> <br />
</label><input type="submit" value="Enviar" /><br /> <br />
</form>
<?php
}
if (isset($_POST["acao"]) && $_POST["acao"] == "logar") {
$login = $_POST["login"];
$senha = $_POST["senha"];
if( $login == "" || $senha == "" ) {
echo "<label class='avisos'>erro: Algum campo esta vazio. Verifique</label>";
} else {
if ( strlen($login) > $constantes->getLenLogin() || strlen($senha) > $constantes->getLenSenha() ) {
echo "<label class='avisos'>Login ou Senha com quantidade de caracters errado!</label>";
} else {
$admin = $AdminsDao->pesquisaAdmin($login, $senha);
if($admin == null) {
echo "<label class='avisos'>Usuário ou senha inválidos</label>";
} else {
if($admin->getBloqueado() == "s"){
echo "<label class='avisos'>".$admin->getNome().": O Administrador geral bloqueou você!</label>";
} else {
$_SESSION["admin"] = serialize($admin);
echo "<script>location.href='principal.php'</script>";
}
}
$connection->fechaConexao();
}
}
}
?>
The problem is not quite with
session_start
, recommend to make more intuitive titles to the problem =) - understand as a constructive criticism– Guilherme Nascimento
Oh William, thank you for hello. I’ll be more attentive. But it’s just that at the time, it was this title that came to mind that related more to the problem that I understood was going through
– Carlos Rocha
A doubt Carlos, why are you trying to use
unserialize
with a session variable? Wouldn’t it be better to keep as variable and even arrays?– Guilherme Nascimento
It was actually the only way I could find to get the session into a class method to see if the session exists.
– Carlos Rocha
I understand, you’re sending the class data, I think there’s more practical way.
– Guilherme Nascimento
I wanted to save in the session the class object that stores the logged in administrator
– Carlos Rocha
Face on logon.php in the part where it checks that is locked vc is calling a get parameter, I believe I wanted to call the getName method. Something else, by the way register_globals is enabled?
– marcusagm
is getNome() right. Here in mine is correct. register_globals = on The session works yes. I already answered this question, check below.
– Carlos Rocha