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

Problemas Com Session


carol

Pergunta

oi gente,

.. gostaria de mais uma ajuda d vocês ..

Peguei esse tópico sobre sessão na net ... mais eu não sei que acontece que quando digito os dados que ele pede a sessão não é criada ...

gostaria da ajuda de vocês p me ajudar a solucionar esse problema ....

index.php

<?
    //VERIFICA SE O FORMULÁRIO FOI ENVIADO
    if($_POST["postok"]) {
  
  //RECEBE OS DADOS ENVIADOS PELO FORMULÁRIO
  $nome    =    $_POST["txtNome"];
  $idade    =    $_POST["txtIdade"];
  
  //GRAVA NA SESSÃO SE OS CAMPOS NÃO ESTIVEREM EM BRANCO
  if ( (!empty($nome)) AND (!empty($idade)) ) {
      //INICAILIZA A SESSÃO
      session_start();
      
      //REGISTRA AS VARIÁVEIS NA SESSÃO
      $_SESSION["sess_nome"]    =    $nome;
      $_SESSION["sess_idade"]    =    $idade;
  }//FECHA IF (empty)
  else {
      $erro++; //SOMA 1 A VARIÁVEL ERRO
      $html_error    .=    "<br>Os campos não podem ser deixados em branco.";
  }//FECHA ELSE
    }//FECHA IF($_post)
?>

<html>
<head>
<title>Sessão</title>
</head>

<body>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr> 
        <td><font size="5" face="Arial"><strong>Autentica&ccedil;&atilde;o de usu&aacute;rios usando sess&otilde;es - SESSION </strong></font></td>
      </tr>
    </table>
    
    <hr noshade>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr bgcolor="#EBEBEB"> 
        <td height="31"><div align="center"><font size="2" face="Arial">[ Gravando os dados na sess&atilde;o ]</font></div></td>
        <td height="31"><div align="center"><font size="2" face="Arial">[ <a href="verifica.php">Verificando a sess&atilde;o</a> ]</font></div></td>
        <td height="31"><div align="center"><font size="2" face="Arial">[ <a href="encerra.php">Encerrando a sess&atilde;o</a> ]</font></div></td>
      </tr>
    </table>
    
    <br>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><font size="2" face="Arial">Os dados digitados abaixo, ser&atilde;o guardados na sess&atilde;o que ser&aacute; criada.</font></td>
      </tr>
    </table>
    
    <br>
    <?
    //VERIFICA SE O FORMULÁRIO FOI ENVIADO
    if($_POST["postok"]) {
  //VERIFICA SE ACONTECEU ALGUM ERRO
  if($erro) {
      echo  "<div align='center'><b>$html_error</b></div>";
  }//FECHA if (erro)
  // CASO NÃO TENHA OCOORIDO NEHUM ERRO ...
  else {
      echo  "<br><br><table border='0' cellpading='0' cellspacing='0' width='90%'>";
      echo  "<tr>";
      echo    "<td><div align='center'><font face='Arial' size='2'><b>Sessão criada !!</b></font></div></td>";
      echo  "</tr>";
      echo    "</table>";
  }//FECHA ELSE(erro)
    } //FECHA IF(postok)
    
    //EXIBE O FORMULÁRIO
    else { ?>
  <form action="" method="post" name="frm_sessao">
      <table width="60%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr> 
          <td width="16%" height="25"><strong><font size="2" face="Arial">Nome:</font></strong></td>
            <td width="84%" height="25"><font size="2" face="Arial">
          <input name="txtNome" type="text" size="30" maxlength="30"></font></td>
      </tr>
        
      <tr> 
            <td height="25"><strong><font size="2" face="Arial">Idade:</font></strong></td>
            <td height="25"><font size="2" face="Arial">
          <input name="txtIdade" type="text" size="3" maxlength="3"></font></td>
      </tr>
        
      <tr> 
            <td colspan="2"><div align="center"> 
            <input name="btnEnviar" type="submit" value="[ Gravar dados na sess&atilde;o ]"></div></td>
          <input type="hidden" name="postok" value="1">
      </tr>
        </table>
  </form>
    <?
    } //FECHA ELSE?>
</body>
</html>
verifica.php
<?
    //INICIALIZA A SESSÃO
    session_start();
?>

<html>
<head>
<title>Sessão</title>
</head>

<body>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr> 
        <td><font size="5" face="Arial"><strong>Autentica&ccedil;&atilde;o de usu&aacute;rios usando sess&otilde;es - SESSION </strong></font></td>
      </tr>
    </table>
    
    <hr noshade>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr bgcolor="#EBEBEB"> 
        <td height="31"><div align="center"><font size="2" face="Arial">[ <a href="index.php">Gravando 
        os dados na sess&atilde;o</a> ]</font></div></td>
        <td height="31"><div align="center"><font size="2" face="Arial">[ Verificando 
        a sess&atilde;o ]</font></div></td>
        <td height="31"><div align="center"><font size="2" face="Arial">[ <a href="encerra.php">Encerrando a sess&atilde;o</a> ]</font></div></td>
      </tr>
    </table>
    
    
<br>
<br>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        
    <td><font color="#FF0000" size="3" face="Arial"><strong>Resultado da verifica&ccedil;&atilde;o:</strong></font></td>
      </tr>
    </table>
    
    
    <br>
    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td><font size="2" face="Arial">
  <?
  //VERIFICA SE AS VARIÁVES ESTÃO INICIALIZADAS NA SESSÃO
  if(!empty($_SESSION["sess_nome"]) AND (!empty($_SESSION["sess_idade"])) ) {
      echo  "<b>A sessão está ativa.</b><br><br>";
      echo  "Nome ...........: ".$_SESSION["sess_nome"];
      echo  "<br>Idade ............: ".$_SESSION["sess_idade"];
  }//FECHA IF
  
  //SE NÃO TIVER NADA REGISTRADO, EMITE A MENSAGEM.
  else {
      echo  "<b>A sessão NÃO FOI CRIADA AINDA.</b>";
  } //FECHA ELSE?></font></td>
      </tr>
    </table>
</body>
</html>
encerra.php
<?
    //INICIALIZA A SESSÃO
    session_start();
    
    //VERIFICA SE AS VARIÁVEIS ESTÃO REGISTRADAS
    if( (!empty($_SESSION["sess_nome"])) AND (!empty($_SESSION["sess_idade"])) ) {
  //DESTRÓI A SESSÃO
  $destroi    =    session_destroy();
    } //FECHA IF
?>

<html>
<head>
<title>Sessão</title>
</head>

<body>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr> 
        <td><font size="5" face="Arial"><strong>Autentica&ccedil;&atilde;o de usu&aacute;rios usando sess&otilde;es - SESSION </strong></font></td>
      </tr>
    </table>
    
    <hr noshade>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr bgcolor="#EBEBEB"> 
        <td height="31"><div align="center"><font size="2" face="Arial">[ <a href="index.php">Gravando 
        os dados na sess&atilde;o</a> ]</font></div></td>
        <td height="31"><div align="center"><font size="2" face="Arial">[ <a href="verifica.php">Verificando 
        a sess&atilde;o</a> ]</font></div></td>
        <td height="31" bgcolor="#EBEBEB"><div align="center"><font size="2" face="Arial">[ 
        Encerrando a sess&atilde;o ]</font></div></td>
      </tr>
    </table>
    
    <br><br>
    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td><div align="center"><font size="2" face="Arial">
  <?
  //ANALISA O RESULTADO DA DESTRUIÇÃO
  if($destroi) {
      echo  "<b>Sessão eliminada com SUCESSO !!</b>";
  }
  else {
      echo  "<b>Aconteceu algum erro. Por favor, tente  novamente.</b><br><br>";
      echo  "<b>Exemplo: Verifique se a sessão já foi criada.";
  }
  ?></font></div></td>
      </tr>
    </table>
</body>
</html>

O problema é esse, não da erro

Eu coloco meu nome no form.. e clico em gravar, ai não acontece nada ...

vou em verificar sessão e nada a unica coisa que ele mostra é

Resultado da verificação:

A sessão NÃO FOI CRIADA AINDA.

so isso .. ai que não intendo ... :blink:

Quem puder me ajudar eu agradeço .... t+

beijokas..

Link para o comentário
Compartilhar em outros sites

3 respostass a esta questão

Posts Recomendados

  • 0

La vai ..

    

     Session_start();
     
    session_register("newsadmin");
    $newsadmin = 1;

    
Para recuperar :
    
     $sessao = $_SESSION['newsadmin'];
    
verificar se está setada a sessão :
    <?if (!session_is_registered("newsadmin")) {?>
    

ICQ UIN 12045528

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,1k
    • Posts
      651,8k
×
×
  • Criar Novo...