Jump to content


Photo

Ajuda Com Session


  • Faça o login para participar
6 replies to this topic

#1 kbalera

kbalera

    Normal

  • Usuários
  • 108 posts
  • Sexo:Não informado
  • Localidade:<? Ipatinga?>
  • Interesses:<? print "Php - WebDesigner"; ?>

Posted 20/06/2003, 09:24

Ai galere tudo bem eu to precisando de uma ajuda pois nao to intendendo....

olha o codigo ai

<?php
$nome1=$nome;
session_start();
session_register('nome1');
?>


Issu esta no topo da page antes do codigo html

eu to usando funcao para tipo um sistema de login so q tipo assim eu to gravando o nome1 que vai ser igual a variavel nome q vem do form. pois depois eu peco pra da um print no nome1 para nas demais pages eu fazer uma verificacao de login e senha so q antes funcionava agora naum funciona mais eu naum to entendendo... e meus links são assim tipo page.php?l=teste ..... page.php?l=teste1

entao sempre vai estar navegando na mesma paginas so q com conteudo diferente dependendo da variavel....so q agora a session parou de funfar..... me ajudem ai... :light:
<?php
print "nick = Kbalera";
print "email = junior@rockiando.com.br";
print "cidade = IPATINGA/MG";
print "A arte de criar, é bem maior de que falar que criou";

?>

#2 Perazzo

Perazzo

    Turista

  • Usuários
  • 54 posts
  • Sexo:Não informado
  • Localidade:Fortaleza

Posted 20/06/2003, 09:39

Na página de autenticação, faça isso:

$nome1 = $nome;
session_start();
session_register('nome1');
$_SESSION['nome1'] = $nome;

#3 kbalera

kbalera

    Normal

  • Usuários
  • 108 posts
  • Sexo:Não informado
  • Localidade:&lt;? Ipatinga?&gt;
  • Interesses:&lt;? print &quot;Php - WebDesigner&quot;; ?&gt;

Posted 20/06/2003, 10:02

AI blz. vou postar os codigos desde o inicio pra vc me acopanhar pq ainda naum deu

<?php


if($form!=""){

ver_nome($nome,$senha);
}else{

}

function ver_nome($nome,$senha){
include ("config.php");
$select = "Select*From usuarios where nom_usuario = '$nome' && sen_usuario = '$senha'";
$db = mysql_db_query("vinhetas","$select",$conectar)or die ("Não foi possível selecionar ao banco de dados");
$user = mysql_fetch_array($db);

if(($nome == $user["nom_usuario"])and($senha == $user["sen_usuario"])){
                                  header("Location:base.php?nome=$nome");
}else {
 
  Print "<center><b><font face='arial'><font color='red'>Erro:</b></font>Login errado</font></center>";
 
  }
}


?>


Esse codigo e a page index.php q verificar se o formulario foi enviado ou naum se foi ele faz a verificacao de validade de login e senha e se forem corretos redireciona para a base.php mas ai eu t mandando a vaiavel nome...
ai na base tem esse codigo abaixo onde eu to gravando a session

<?php
$nome1 = $nome;
session_start();
session_register('nome1');
$_SESSION['nome1'] = $nome;
print (session_id());
?>

pq nessa page ele sempre va i tar imprimindo o nome da pessoa e a apartir do nome eu vou selecionar no banco de dados.... e tipo assim so q os links dessa base e tudo pra ela mesmo so q mandando uma varial por exemplo base.php a page ai os links base.php?l=teste ..... base.php?l=teste1..... so q qnd eu clico nos links naum ta imprimindo o nome da pessoa naum e se eu mando imprimir o id da session imprime..........

se entenderem e puderem me ajudar..... pq antes tava funcionando direitinho agora naum sei pq naum sei o q mexi q paroiu
<?php
print "nick = Kbalera";
print "email = junior@rockiando.com.br";
print "cidade = IPATINGA/MG";
print "A arte de criar, é bem maior de que falar que criou";

?>

#4 Visitante - Perazzo

Visitante - Perazzo
  • Visitantes

Posted 20/06/2003, 14:55

Primeiro vamos melhorar esse código:

Faça isso:

$user = mysql_nume_rows($db);
if($user > 0)
{
$nome = $_POST['nome']; 
header("Location:base.php?nome=$nome");
}
else
{
  header("Location:erro.php");
}


Então, tente isso:

<?php
$nome1 = $_GET['nome'];
session_start();
session_register('nome1');
$_SESSION['nome1'] = $nome1;
print (session_id());
?>


Qualquer coisa se não funcionar, avisa!

#5 Visitante - Perazzo

Visitante - Perazzo
  • Visitantes

Posted 20/06/2003, 14:56

só corrigindo um erro de digitação:

Não é mysql_nume_rows e sim mysql_num_rows

#6 kbalera

kbalera

    Normal

  • Usuários
  • 108 posts
  • Sexo:Não informado
  • Localidade:&lt;? Ipatinga?&gt;
  • Interesses:&lt;? print &quot;Php - WebDesigner&quot;; ?&gt;

Posted 21/06/2003, 09:12

ow pode crer pela ajuda mas naum rolou naum pq tipo assim......

qnd eu acesso os links o $nome naum fika naum..... tipo assim eu vou posta o codigo das 2 pages pra vc ver


<?php


if($form!=""){

ver_nome($nome,$senha);
}else{

}

function ver_nome($nome,$senha){
include ("config.php");
$select = "Select*From usuarios where nom_usuario = '$nome' && sen_usuario = '$senha'";
$db = mysql_db_query("vinhetas","$select",$conectar)or die ("Não foi possível selecionar ao banco de dados");

$user = mysql_num_rows($db);
if($user > 0)
{
$nome = $_POST['nome']; 
print $nome;
//echo '<meta http-equiv="refresh" content="0;URL=base.php?nome=$nome">';
//header("Location:base.php?nome=$nome");
}
else
{
Print "<center><b><font face='arial'><font color='red'>Erro:</b></font>Login errado</font></center>";
}

}

//$user = mysql_fetch_array($db);
//if(($nome == $user["nom_usuario"])and($senha == $user["sen_usuario"])){
//header("Location:base.php?nome=$nome");
//}else {
//Print "<center><b><font face='arial'><font color='red'>Erro:</b></font>Login errado</font></center>";
//}
//}


?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Index</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td bgcolor="#EAEAEA"><table width="330" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td><div align="center">
              <form name="form1" method="post" action="<?php print $PHP_SELF;?>?form=ok">
                <table width="80%" border = 0 cellpadding = 0 cellspacing = 0>
                  <tr>
                    <td width="100%"><div align="center"><img src="img/logo_patty.jpg" width="304" height="77"></div></td>
                  </tr>
                  <tr>
                    <td>&nbsp;</td>
                  </tr>
                  <tr>
                    <td><div align="center"><img src="img/relacao.jpg" width="305" height="20"></div></td>
                  </tr>
                  <tr>
                    <td><div align="right">
                        <table width="99%" border="0" align="center" cellpadding="0" cellspacing="0">
                          <tr>
                            <td width="20%" bgcolor="#CCCCCC"><em><strong><font color="#000000" size="2" face="Arial, Helvetica, sans-serif">&nbsp;NOME:</font></strong></em></td>
                            <td width="80%" bgcolor="#CCCCCC"><input name="nome" type="text" id="nome" size="30"></td>
                          </tr>
                          <tr>
                            <td bgcolor="#CCCCCC"><em><strong><font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
                              &nbsp;SENHA:</font></strong></em></td>
                            <td bgcolor="#CCCCCC"><input name="senha" type="password" id="senha" size="30"></td>
                          </tr>
                          <tr>
                            <td colspan="2" bgcolor="#CCCCCC"><div align="right">
                                <input name="ok" type="image" id="ok" src="img/ok.jpg" width="20" height="17" border="0">
                              </div></td>
                          </tr>
                        </table>
                      </div></td>
                  </tr>
                  <tr>
                    <td><img src="img/baixo.jpg" width="305" height="36"></td>
                  </tr>
                </TABLE>
              </form>
            </div></td>
        </tr>
      </table><p>&nbsp;</p></td>
  </tr>
</table>
</body>
</html>

esse arquivo ai eh a index.php onde eu tenho form de nome e senha e na mesma ja tenho a verificacao se eh valido.....


<?php
$nome1 = $_GET['nome'];
session_start();
session_register('nome1');
$_SESSION['nome1'] = $nome1;
print (session_id());
print "nome = $nome<br>";
print "nome1= $nome<bR>";
?>

<html>
<head>
<title>Base</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#EEEEEE" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#EEEEEE">
  <tr>
    <td height="111" colspan="3"><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="234" height="91"><img src="recortes/cima_r1_c2.gif" width="176" height="91"></td>
          <td colspan="3" align="center"><div align="left">
              <table width="568" border="0" align="right" cellpadding="0" cellspacing="0">
                <!-- fwtable fwsrc="Untitled" fwbase="menu.gif" fwstyle="Dreamweaver" fwdocid = "742308039" fwnested="0" -->
                <tr>
                  <td width="9"><img src="recortes/spacer.gif" width="9" height="1" border="0" alt=""></td>
                  <td width="75"><img src="recortes/spacer.gif" width="75" height="1" border="0" alt=""></td>
                  <td width="16"><img src="recortes/spacer.gif" width="16" height="1" border="0" alt=""></td>
                  <td width="73"><img src="recortes/spacer.gif" width="73" height="1" border="0" alt=""></td>
                  <td width="13"><img src="recortes/spacer.gif" width="13" height="1" border="0" alt=""></td>
                  <td width="27"><img src="recortes/spacer.gif" width="27" height="1" border="0" alt=""></td>
                  <td width="33"><img src="recortes/spacer.gif" width="33" height="1" border="0" alt=""></td>
                  <td width="15"><img src="recortes/spacer.gif" width="15" height="1" border="0" alt=""></td>
                  <td width="16"><img src="recortes/spacer.gif" width="16" height="1" border="0" alt=""></td>
                  <td width="42"><img src="recortes/spacer.gif" width="42" height="1" border="0" alt=""></td>
                  <td width="3"><img src="recortes/spacer.gif" width="3" height="1" border="0" alt=""></td>
                  <td width="30"><img src="recortes/spacer.gif" width="30" height="1" border="0" alt=""></td>
                  <td width="20"><img src="recortes/spacer.gif" width="20" height="1" border="0" alt=""></td>
                  <td width="6"><img src="recortes/spacer.gif" width="6" height="1" border="0" alt=""></td>
                  <td width="45"><img src="recortes/spacer.gif" width="45" height="1" border="0" alt=""></td>
                  <td width="69"><img src="recortes/spacer.gif" width="69" height="1" border="0" alt=""></td>
                  <td width="10"><img src="recortes/spacer.gif" width="10" height="1" border="0" alt=""></td>
                  <td width="28"><img src="recortes/spacer.gif" width="28" height="1" border="0" alt=""></td>
                  <td width="37"><img src="recortes/spacer.gif" width="37" height="1" border="0" alt=""></td>
                  <td width="10"><img src="recortes/spacer.gif" width="1" height="1" border="0" alt=""></td>
                </tr>
                <tr>
                  <td colspan="3"><img name="menu" src="recortes/menu.gif" width="100" height="31" border="0" alt=""></td>
                  <td colspan="8">&nbsp;</td>
                  <td><img name="l11" src="recortes/l11.gif" width="30" height="31" border="0" alt=""></td>
                  <td bgcolor="#DFDFDF">&nbsp;</td>
                  <td bgcolor="#DFDFDF">&nbsp;</td>
                  <td colspan="5" rowspan="2" valign="top" bgcolor="#DFDFDF"><div align="center"><font color="#333333" size="2" face="Arial, Helvetica, sans-serif"><strong>SISTEMA
                      DE VINHETAS<br>
                      <font color="#000000" size="1">Vo&ecirc; est&aacute; como:
                      <b><font size='2'><?php print "$nome1";?></font></b></font>
                      <br>
                      <font size="1"><?php
      echo date("d",time( )),- date("m",time( )),- date("Y",time( ));
      ?></font> </strong></font></div></td>
                  <td><img src="recortes/spacer.gif" width="1" height="31" border="0" alt=""></td>
                </tr>
                <tr>
                  <td><img name="l1" src="recortes/l1.gif" width="9" height="21" border="0" alt=""></td>
                  <td><a href="?l=agenda"><img name="l2" src="recortes/l2.gif" width="75" height="21" border="0" alt="AGENDA"></a></td>
                  <td><img name="l3" src="recortes/l3.gif" width="16" height="21" border="0" alt=""></td>
                  <td><a href="?l=buscas"><img name="l4" src="recortes/l4.gif" width="73" height="21" border="0" alt="BUSCAS"></a></td>
                  <td><img name="l5" src="recortes/l5.gif" width="13" height="21" border="0" alt=""></td>
                  <td colspan="3"><a href="?l=relatorio"><img name="l6" src="recortes/l6.gif" width="75" height="21" border="0" alt="RELAT&Oacute;RIOS"></a></td>
                  <td><img name="l7" src="recortes/l7.gif" width="16" height="21" border="0" alt=""></td>
                  <td colspan="3"><a href="?l=atuais"><img name="l8" src="recortes/l8.gif" width="75" height="21" border="0" alt="VINHETAS ATUAIS"></a></td>
                  <td colspan="2"><img name="l9" src="recortes/l9.gif" width="26" height="21" border="0" alt=""></td>
                  <td><img src="recortes/spacer.gif" width="1" height="21" border="0" alt=""></td>
                </tr>
                <tr>
                  <td rowspan="3" colspan="6">&nbsp;</td>
                  <td rowspan="2"><img name="l12" src="recortes/l12.gif" width="33" height="23" border="0" alt=""></td>
                  <td rowspan="2" colspan="3"><a href="<?php
      if($nome1==administrador){
      print"painel/index.php?ad=1";
      }else{
      print"";
      }
     
      ?>"><img name="l13" src="recortes/l13.gif" width="73" height="23" border="0" alt=""></a></td>
                  <td colspan="3"><img name="l14" src="recortes/l14.gif" width="53" height="19" border="0" alt=""></td>
                  <td colspan="2"><img name="l15" src="recortes/l15.gif" width="51" height="19" border="0" alt=""></td>
                  <td><img name="l16" src="recortes/l16.gif" width="69" height="19" border="0" alt=""></td>
                  <td><img name="l17" src="recortes/l17.gif" width="10" height="19" border="0" alt=""></td>
                  <td><img name="l18" src="recortes/l18.gif" width="28" height="19" border="0" alt=""></td>
                  <td><img name="l19" src="recortes/l19.gif" width="37" height="19" border="0" alt=""></td>
                  <td><img src="recortes/spacer.gif" width="1" height="19" border="0" alt=""></td>
                </tr>
                <tr>
                  <td rowspan="2" colspan="7"><img name="menu_r4_c11" src="recortes/menu_r4_c11.gif" width="183" height="15" border="0" alt=""></td>
                  <td rowspan="2"><img name="l20" src="recortes/l20.gif" width="28" height="15" border="0" alt=""></td>
                  <td rowspan="2"><img name="l21" src="recortes/l21.gif" width="37" height="15" border="0" alt=""></td>
                  <td><img src="recortes/spacer.gif" width="1" height="4" border="0" alt=""></td>
                </tr>
                <tr>
                  <td height="11" colspan="4"><img name="menu_r5_c7" src="recortes/menu_r5_c7.gif" width="106" height="11" border="0" alt=""></td>
                  <td><img src="recortes/spacer.gif" width="1" height="11" border="0" alt=""></td>
                </tr>
              </table>
            </div>
            <div align="center"></div>
            <div align="center"></div>
            <div align="right"></div>
            <div align="right"> </div>
            <div align="right"></div></td>
        </tr>
        <tr>
          <td height="20" background="recortes/cima_r8_c2.gif">&nbsp;</td>
          <td width="693" background="recortes/cima_r8_c2.gif"><div align="center">
            </div></td>
          <td width="49" background="recortes/cima_r8_c2.gif"><div align="right"><img src="img/cima_r9_c29.gif" width="27" height="20"></div></td>
          <td width="43">&nbsp;</td>
        </tr>
      </table></td>
  </tr>
  <tr>
    <td width="253" valign="top"><table width="100" border="0" cellpadding="0" cellspacing="0">
        <tr valign="top">
          <td>&nbsp;</td>
          <td><img src="recortes/base_r1_c2.gif" width="56" height="33"></td>
          <td><img src="recortes/base_r1_c3.gif" width="78" height="33"></td>
        </tr>
        <tr valign="top">
          <td><img src="recortes/base_r2_c1.gif" width="62" height="29"></td>
          <td><img src="recortes/base_r2_c2.gif" width="56" height="29"></td>
          <td>&nbsp;</td>
        </tr>
        <tr valign="top">
          <td><img src="recortes/base_r3_c1.gif" width="62" height="38"></td>
          <td><img src="recortes/base_r3_c2.gif" width="56" height="38"></td>
          <td>&nbsp;</td>
        </tr>
        <tr valign="top">
          <td background="recortes/base_r5_c1.gif">&nbsp;</td>
          <td><img src="recortes/base_r4_c2.gif" width="56" height="366"></td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td background="recortes/base_r5_c1.gif"><img src="recortes/base_r5_c1.gif" width="61" height="16"></td>
          <td valign="top" background="recortes/base_r5_c2.gif"><img src="recortes/base_r5_c2.gif" width="56" height="16"></td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td background="recortes/base_r5_c1.gif">&nbsp;</td>
          <td valign="top" background="recortes/base_r5_c2.gif">&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
      </table></td>
    <td width="727">&nbsp;</td>
    <td width="39"><div align="right"><img src="recortes/base_r1_c5.gif" width="40" height="100%"></div></td>
  </tr>
</table>
</body>
</html>


e esse ai eh a page base.php o menu ta la em cima com os links do jeito q eu te falei......
<?php
print "nick = Kbalera";
print "email = junior@rockiando.com.br";
print "cidade = IPATINGA/MG";
print "A arte de criar, é bem maior de que falar que criou";

?>

#7 Perazzo

Perazzo

    Turista

  • Usuários
  • 54 posts
  • Sexo:Não informado
  • Localidade:Fortaleza

Posted 21/06/2003, 14:35

Deixa eu peguntar uma coisa:

Quando tu faz isso na primeira página:

$user = mysql_num_rows($db);
if($user > 0)
{
$nome = $_POST['nome']; 
print $nome;
}


O navegador imprime o valor da variável nome?




1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq