Ir para conteúdo
Fórum Script Brasil
  • 0

Problema sessão PHP


guihgf

Pergunta

Boa noite todos, sou novo no fórum, inclusive no php. Criei uma sessão no arquivo 1 ao validar a senha e o user,onde em seguida é aberta a página home:

if($linha==1)
   {
       session_start();
       $dados=mysql_fetch_array($reg);
       $_SESSION['user']=$dados['usuario'];
       $_SESSION['nome']=$dados['nome'];
       include("home.php");
   }
Na home, tem um label chamado bem vindo, onde concateno com o $_SESSION['nome'],até ai tudo bem, consegui recupera a sessão, ela estava ativa. Na mesma página home tem um link que direciona pra arquivo gerperfil.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>Untitled Document</title>
<style type="text/css">

.div
{
        position:absolute;
}

#apDiv1 {
        position:absolute;
        width:386px;
        height:10px;
        z-index:1;
        left: 528px;
        top: 9px;
        font-family: "Brush Script MT";
        font-size: 14px;
}

#apDiv2 {
        position:absolute;
        width:378px;
        height:27px;
        z-index:1;
        left: 8px;
        top: 9px;
}
#apDiv3 {
        position:absolute;
        width:914px;
        height:30px;
        z-index:1;
        left: 0px;
        top: 655px;
}
#apDiv1 table tr td .home {
        font-size: 24px;
}
#apDiv1 table tr td {
        font-size: 24px;
}
#apDiv4 {
        position:absolute;
        width:150px;
        height:106px;
        z-index:1;
        left: 29px;
        top: 56px;
}
</style>
</head>
<body>
<table width="895" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="4"><img src="Home/cabecalho/cabecalho_r1_c1.jpg" width="917" height="100"/>
      <div class="div">
        <div id="apDiv4">
            <img src="Perfil/Perfil.gif" width="115" height="100" align="right" />
        </div>
      </div>
      <div class="div">
        <div id="apDiv1">
            <table width="363" align="center">
                <tr>
                  <td ><span class="home">Bem Vindo: </span><?echo $_SESSION['nome'];?></td>
                  <td width="63"></td>                          
                 </tr>
            </table>
        </div>
      </div>
      <div class="div">
        <div id="apDiv2">
            <table align="left" width="300">
              <tr>
                <td width="63" height="27" align="center"><a href="#">Início</a> </td>
      
                    <td width="61" align="center" >
                        <a href="gerperfil.php" target="principal">Perfil</a>
                    </td>
             
                <td width="61" align="center"><a href="#">Grupos</a></td>
                <td width="67" align="center"><a href="#">Instituições</a></td>
                <td width="61" align="center"><a href="index.php" <? session_destroy()?>>Sair</a></td>
              </tr>
            </table>
        </div>
      </div>
      <div class="div">
        <div id="apDiv3">
            <table width="900" align="center">
                <tr align="center">
                 <td width="90"><p><a href="#">Termos</a></p></td>
                 <td width="101"><a href="#">Criador</a></td>
                 <td width="68"><a href="#">Sobre</a></td>
                 <td width="122"><a href="#">Colabore</a></td>
                 <td width="162"><a href="#">Convidar Colegas</a></td>
                 <td width="181"><a href="#">Versão Para Celular</a></td>
                 <td width="142"><a href="#">Sugestões</a></td>
                </tr>
             </table>
        </div>
     </div>
    </td>
  </tr>
  <tr>
    <td colspan="5"><img src="Home/cabecalho/menu_r2_c1.jpg" width="915" height="49" /></td>
  </tr>
  <tr>
    <td width="207" rowspan="2"><img src="Home/body/foto_r3_c1.jpg" width="207" height="117" /><img src="Home/body/categorias/categoria_r4_c1.jpg" width="207" height="33" /><img src="Home/body/categorias/categoria_r5_c1.jpg" width="207" height="34" /><img src="Home/body/categorias/categoria_r6_c1.jpg" width="207" height="44" /><img src="Home/body/categorias/categoria_r7_c1.jpg" width="207" height="48" /><img src="Home/body/categorias/categoria_r8_c1.jpg" width="207" height="46" /><img src="Home/body/categorias/categoria_r9_c1.jpg" width="207" height="45" /><img src="Home/body/categorias/categoria_r10_c1.jpg" width="207" height="45" /><img src="Home/body/categorias/categoria_r11_c1.jpg" width="207" height="53" /><img src="Home/body/categorias/categoria_r12_c1.jpg" width="207" height="47" /><img src="Home/body/categorias/categoria_r13_c1.jpg" width="207" height="43" /><img src="Home/body/categorias/categoria_r14_c1.jpg" width="207" height="42" /></td>
    <td width="484" rowspan="2" align="right" valign="top"><iframe name="principal" height="590" width="500" frameborder="0"></iframe></td>
    <td width="209" align="right" valign="top"><img src="Home/body/colegas_r3_c3.jpg" width="209" height="312" align="baseline" /></td>
  </tr>
  <tr>
    <td align="right" valign="top"><img src="Home/body/colegas_r9_c3.jpg" width="209" height="287" /></td>
  </tr>
  <tr>
    <td colspan="5"><img src="Home/rodapé/rodape_r4_c1.jpg" width="917" height="51" /></td>
  </tr>
</table>
</body>
</html>
Porém no arquivo gerperfil.php não consigo mais recupera a sessão:
$usuario=$_SESSION['user']; //sessão não encontrada
    include ("conexao.inc");  
    $query="select * from usuarios where usuario='$usuario'";
    $result=mysql_query($query);
    $valores=  mysql_fetch_array($result);
    include("perfil.php");

Onde será que estou errando pra sessão simplesmente sumir ? Até mais pessoal!!

Link para o comentário
Compartilhar em outros sites

3 respostass a esta questão

Posts Recomendados

  • 0

Tirei amigo e deu na mesma. Inclui também o session_start();

<?php
    session_start();
    $usuario=$_SESSION['user'];
    include ("conexao.inc");  
    $query="select * from usuarios where usuario='$usuario'";
    $result=mysql_query($query);
    $valores=  mysql_fetch_array($result);
    header("Location: perfil.php");
?>

e mesmo assim a $_SESSION['user']; não tem nada.

Qual o cara abre a index isto é carregado:

<td width="61" align="center"><a href="index.php" <? session_destroy()?>>Sair</a></td>

Ou seja, você está distruindo as sessões na index...

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      652k
×
×
  • Criar Novo...