Olá pessoal. Desculpem postar um assunto tão fora do escopo…
Estou dando manutenção para um portal em PHP e estou passando por certas dificuldades. O novo servidor desabilitou o uso de variáveis globais e os scripts estão repletos de usos desta má prática.
Tenho este scritp que monta a página de gerenciamento do portal, verificando se o usuário loga tem privilégios ou não.
<html>
<?php
session_start();
include "../include/mysql_bdi.inc";
include "criptografa.php";
$ChaveLocal="chave.txt";
$Chave=substr(LerChaveDoArquivo($ChaveLocal,$Frase),1-1,strlen($Frase));
$usuario = $_POST["usuario"];
$senha = $_POST["senha"];
if ($usuario == ""){
$usuario = "nada";}
if ($senha == ""){
$senha = "nada";}
if (($usuario != "usuario") || ($senha != "senha")){
echo "IDENTIFICAÇÃO INVÁLIDA";
}
else {
$logado = true;
//session_register("logado");
$_SESSION["logado"] = $logado;
?>
<head>
<title>Projetos do Grupo BDI</title>
<link rel="stylesheet" href="../estilo/bdi.css">
</head>
<body>
<table class="borda_tabela_principal" align="center" width="85%" cellspacing="1" cellpadding="0" border="0">
<tr>
<td align="center">
<?php include "include/cabecalho_manager.inc"; ?>
</td>
</tr>
<tr>
<td>
<table border="0" width="100%" height="70%" align="left" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#FFFFFF" align="center" valign="top" width="20%">
<br>
<a href="../index.php">
<img src="../imagens/logobdi.gif" border="0" alt="BDI">
</a>
</td>
<td bgcolor="#FFFFFF" align="center" valign="top" width="80%">
<br><br><br>
Bem-vindo ao <b>Manager(v.0.1)</b> do sítio "Projetos do Grupo BDI".
<p>
<font class=titulo> Até o momento ocorreu o seguinte número de acessos:</font>
<br>
<?php
include "../include/mysql_bdi.inc";
$sql = "select count(*) as total from log where host_origem not like '%143.54%'";
$sql_in = "select count(*) as total from log where host_origem like '%143.54%'";
$resultado = mysql_query($sql);
$cont = mysql_result($resultado, 0, "total");
echo $cont . " acessos de fora da UFRGS <br>";
$resultado_in = mysql_query($sql_in);
$cont_in = mysql_result($resultado_in, 0, "total");
echo $cont_in . " acessos da UFRGS ";
mysql_close($conexao);
?>
<br><br><br><br><br><br><br>
</td>
</tr>
</table>
</td>
</tr>
</table>
<?php } ?>
</body>
</html>
Percebam que é incluído um cabeçalho em:
<?php include "include/cabecalho_manager.inc"; ?>Este arquivo tem a seguinte estrutura:
<script language="JavaScript">
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
</script>
<br>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td align="center" valign="top">
<a href="index.php" class="link_cabecalho">
| PÁGINA NORMAL
</a>
<a href="manager/projetos/index.php" class="link_cabecalho">
| PROJETOS
</a>
<a href="manager/membros/index.php" class="link_cabecalho">
| MEMBROS
</a>
<a href="/bdi/manager/publicacoes/index.php" class="link_cabecalho">
| PUBLICAÇÕES
</a>
<a href="manager/links/index.php" class="link_cabecalho">
| PESQUISA
</a>
<!--<a href="fotos/fotos.php" class="link_cabecalho">
| FOTOS
</a>-->
<!--<a href="disciplinas/disciplinas.php" class="link_cabecalho">
| DISCIPLINAS
</a>-->
<!--<a href="#" onclick="MM_openBrWindow('mapa2.html','mapa','width=800,height=280')" class="link_cabecalho">
| MAPA DO SITE
</a>-->
<!--<a href="/faq.php" class="link_cabecalho">
| FAQ |
</a>-->
<!--<a href="/manager/tabelas_base/index.php" class="link_cabecalho">
Tabelas de Base
</a>-->
</td>
</tr>
</table>
<br>
Supondo que eu clique em “Projetos”, vou chamar este script:
manager/projetos/index.php
<html>
<?php
//session_start();
$logado = $_SESSION["logado"];
//echo "<p>".$logado."</p>";
if (!($logado))
{
echo "IDENTIFICAÇÃO INVÁLIDA";
}
else
{
?>
<head>
<title>Projetos do Grupo BDI</title>
<link rel="stylesheet" href="../../estilo/bdi.css">
</head>
<body>
<table class="borda_tabela_principal" align="center" width="85%" cellspacing="1" cellpadding="0" border="0">
<tr>
<td align="center">
<?php include "../include/cabecalho_manager.inc"; ?>
</td>
</tr>
<tr>
<td>
<table border="0" width="100%" height="%70" align="left" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#FFFFFF" align="center" valign="top" width="20%">
<br>
<a href="../index.php">
<img src="../../imagens/logobdi.gif" border="0" alt="BDI">
</a>
<?php include "../include/menus/projetos.inc"; ?>
</td>
<td bgcolor="#FFFFFF" align="left" valign="top" width="80%">
<br>
<font class="titulo">Projetos em Andamento:</font><br><br>
<?php
include "../../include/mysql_bdi.inc";
//PROJETOS EM ANDAMENTO
$proj_andamento = mysql_query("select id, nome from PROJETOS where status='A'");
$nro_linhas_proj_andamento = mysql_num_rows($proj_andamento);
for ($j = 0; $j < $nro_linhas_proj_andamento; $j++)
{
$nomeProjetoA = mysql_result($proj_andamento, $j, "nome");
$idA = mysql_result($proj_andamento, $j, "id");
echo "<li><a class='item_membros' href='modificar_projeto.php?id=".$idA."'>". $nomeProjetoA ."</a></li><br>";
}
//PROJETOS CONCLUIDOS
$proj_conclu = mysql_query("select id, nome from PROJETOS where status='C'");
$nro_linhas_proj_conclu = mysql_num_rows($proj_conclu);
echo "<br><font class='titulo'>Projetos Concluídos:</font><br><br>";
for ($j = 0; $j < $nro_linhas_proj_conclu; $j++){
$nomeProjetoC = mysql_result($proj_conclu, $j, "nome");
$idC = mysql_result($proj_conclu, $j, "id");
echo "<li><a class='item_membros' href='modificar_projeto.php?id=".$idC."'>". $nomeProjetoC ."</a></li><br>";
}
mysql_close($conexao);
?>
</td>
</tr>
</table>
</td>
</tr>
</table>
<?php } ?>
</body>
</html>
Estou tentando gravar o estado da variável logado, na sessão…Mas ao que parece não estou obtendo êxito…Alguém sabe o que eu posso estar fazendo de errado? Sou iniciante em PHP (e me deram essa abacaxi pr adescascar).