Ir para conteúdo
Fórum Script Brasil

frlouzada

Membros
  • Total de itens

    28
  • Registro em

  • Última visita

Posts postados por frlouzada

  1. Bem galera... achei uma solução +- como eu queria. Foi a que mais se aproximou!

    Aí vai o códio:

    <?php
    session_start();
    
    include("config.php");
    include("include.php");
    
    if ($_SERVER["QUERY_STRING"] == "invalido" || $_POST["login_"] == "" || $_POST["senha_"] == "") {
    if ($_SERVER["QUERY_STRING"] == "invalido") {
      $text = "<font face=\"$fonte\" size=\"$tfonte\">Usuário ou senha inválido. <a href=mailto:$admine>Contate o administrador</a> se você tem certeza de que os dados estão corretos.<br><br>";
    }
    
    echo <<<HTML
    <HTML>
    <title>$nsite</title>
    <form action="login.php" method="post">
    <table align="center" width="90%" border="0" cellpadding="0" cellspacing="0">
    <tr><td height="25">Bem vindo <b>visitante</b>! <a href="cadastro.php" target="_parent">Cadastre-se</a> ou efetue login ao lado!</td>
    <td height="25">Login: </td><td><input name="login_" type="text"></td>
    <td height="25">Senha: </td><td><input name="senha_" type="password"></td>
    <td height="25"> </td><td><input name="logar" type="submit" value="Logar"></td></tr>
    <tr><td colspan="4">$text</td></tr>
    </table>
    </form>
    </HTML>
    HTML;
    
    } else {
    $query = mysql_query("Select * From users where login='" . $_POST["login_"] . "' and senha='" . $_POST["senha_"] . "' limit 1;");
    $valida = mysql_num_rows($query);
    if ($valida > 0) {
      setcookie("usuario", $login_);
      setcookie("senha", $senha_);
      header("Location: " . $_SESSION['local']);
    } else {
      header("Location: index.php?invalido");
    }
    }
    ?>

  2. Fala galera,

    logo abaixo vou colocar o código de fazer o login num sistema. O problema é o seguinte: Como estou usando query string, quando o login ou a senha são incorretos ele está mostrando a mensagem em uma página toda em branco.

    Será que tem como, em vez da página ser totalmente recarregada para aparecer a mensagem, aparecer uma caixa de alerta com a mensagem, ou então aparecer os campos de login/senha novamente com uma pequena mensagem abaixo dizendo "login inválido!"

    tipo:

    Login [ ] Senha [ ] [Logar]

    * Login/Senha inválidos

    Espero que possam me ajudar! Aí vai o código:

    <?php
    include("config.php");
    include("include.php");
    
    session_start();
    
    $query = mysql_query("Select * From users where login='$login_' and senha='$senha_'");
    $valida = mysql_fetch_array($query);
    
    $user = $valida["login"];
    $pass = $valida["senha"];
    
    if($login_ == '' || $senha_ == ''){
    echo"
    <HTML>
    <title>$nsite</title>
    <form action=\"login.php\" method=\"post\">
    <table align=\"center\" width=\"90%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
    <tr><td height=\"25\">Bem vindo <b>visitante</b>!  <a href=\"cadastro.php\" target=\"_parent\">Cadastre-se</a> ou efetue login ao lado!</td>
    <td height=\"25\">Login:  </td><td><input name=\"login_\" type=\"text\"></td>
    <td height=\"25\">Senha:  </td><td><input name=\"senha_\" type=\"password\"></td>
    <td height=\"25\"> </td><td><input name=\"logar\" type=\"submit\" value=\"Logar\"></td></tr>
    </table>
    </form>
    </HTML>";
    } elseif($login_ == $user && $senha_ == $pass){
    setcookie("usuario", $login_);
    setcookie("senha", $senha_);
    header("Location: ".$_SESSION['local']);
    
    } elseif($login_ != $valida["login"] || $senha_ != $valida["senha"]){
    echo "<font face=\"$fonte\" size=\"$tfonte\">Usuário ou senha inválido.<br><a href=mailto:$admine>Contate o administrador</a> se você tem certeza de que os dados estão corretos.<br><br>
    <a href=login.php>«« Voltar</a></font>";
    }
    ?>

  3. Fala galera,

    Estou com um probleminha no formulário abaixo. Tenho a função de validação do formulário MM_validateForm() que fiz algumas adaptações para validar CPF e CNPJ. Mas ela só está chamando a função de validar CPF. Mesmo quando o radio button está marcado em CNPJ ele está chamando a função validaCPF, sendo que quando o CNPJ estiver marcado ele deveria chamar a função validaCNPJ.

    Alguém poderia me ajudar a identificar qual é o problema?

    Código atualizado

    <?
    include("config.php");
    
      if($acao == 'cadastra'){
    $sql = "SELECT * FROM users where login='$CampoNumero'";
    
    $resultado = mysql_query($sql)
    or die ("Não foi possível realizar a consulta ao banco de dados");
    
    if(mysql_num_rows($resultado)>0) {
    
    while ($linha=mysql_fetch_array($resultado)) {
    $CampoNumero = $linha["loginc"];
    }
    }
    if(($CampoNumero == $loginc) && ($CampoNumero != "")){
    echo"<script>alert('Este CPF/CNPJ já está cadastrado. Entre com outro CPF/CNPJ');
    history.back(-1);</script>";
    }else{
        if (${"chkCPF"}=="on"){
            $nome = $_POST['nome'];
            $email = $_POST['email'];
            $ddd = $_POST['ddd'];
            $telefone = $_POST['telefone'];
            $endereco = $_POST['endereco'];
            $cep = $_POST['cep'];
            $cidade = $_POST['cidade'];
            $estado = $_POST['estado'];
            $cpf = $_POST['CampoNumero'];
            $cnpj = '';
            $login = $_POST['CampoNumero'];
            $senha = $_POST['senha'];
            $sql = mysql_query("Insert into users values('$id', '$nome', '$email', '$ddd', '$telefone', '$endereco', '$cep', '$cidade', '$estado', '$cpf', '$cnpj', '$login', '$senha')");
    
    if($sql){
    echo "<script>alert('Usuário cadastrado com sucesso.');
    location.href='index.php';
    </script>
    ";
    } else {
    echo "<script>alert('Não foi possível cadastrar usuário.');
    history.back(-1);
    </script>
    ";
    }
    
        }else{
            $nome = $_POST['nome'];
            $email = $_POST['email'];
            $ddd = $_POST['ddd'];
            $telefone = $_POST['telefone'];
            $endereco = $_POST['endereco'];
            $cep = $_POST['cep'];
            $cidade = $_POST['cidade'];
            $estado = $_POST['estado'];
            $cpf = '';
            $cnpj = $_POST['CampoNumero'];
            $login = $_POST['CampoNumero'];
            $senha = $_POST['senha'];        
            $sql = mysql_query("Insert into users values('$id', '$nome', '$email', '$ddd', '$telefone', '$endereco', '$cep', '$cidade', '$estado', '$cpf', '$cnpj', '$login', '$senha')");
    
    if($sql){
    echo "<script>alert('Usuário cadastrado com sucesso.');
    location.href='index.php';
    </script>
    ";
    } else {
    echo "<script>alert('Não foi possível cadastrar usuário.');
    history.back(-1);
    </script>
    ";
    }
    
        }
    }
    } else {
    echo"
    <HTML>
    <head>
    <title>$nsite</title>
    </head>
    <form action=\"cadastrar.php?acao=cadastra\" method=\"post\" onSubmit=\"MM_validateForm('nome','','R','email','','NisEmail','ddd','','RisNum','telefone','','RisNum','endereco','','R','cep','','RisNum','cidade','','R','estado','','R','CampoNumero','','RisNum','senha','','RinRange6:8');return document.MM_returnValue\">
    <table width=\"100%\" align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
    <tr><td class=\"texto\">Nome:&nbsp;</td><td><input class=\"campo\" name=\"nome\" type=\"text\" size=\"30\" maxlength=\"255\"></td></tr>
    <tr><td class=\"texto\">E-mail:&nbsp;</td><td><input class=\"campo\" name=\"email\" type=\"text\" size=\"30\" maxlength=\"100\"></td></tr>
    <tr><td class=\"texto\">DDD(xx) - Telefone(somente números):&nbsp;</td><td><input class=\"campo\" name=\"ddd\" type=\"text\" size=\"2\" maxlength=\"2\">&nbsp;-&nbsp;<input class=\"campo\" name=\"telefone\" type=\"text\" size=\"15\" maxlength=\"8\"></td></tr>
    <tr><td class=\"texto\">Endereço:&nbsp;</td><td><input class=\"campo\" name=\"endereco\" type=\"text\" size=\"30\"></td></tr>
    <tr><td class=\"texto\">CEP (Somente números):&nbsp;</td><td><input class=\"campo\" name=\"cep\" type=\"text\" size=\"15\" maxlength=\"8\"></td></tr>
    <tr><td class=\"texto\">Cidade:&nbsp;</td><td><input class=\"campo\" name=\"cidade\" type=\"text\" size=\"30\"></td></tr>
    <tr><td class=\"texto\">Estado:&nbsp;</td><td><input class=\"campo\" name=\"estado\" type=\"text\" size=\"30\"></td></tr>
    <tr><td class=\"texto\"><input type=\"radio\" name=\"chkCPF\" id=\"chkCPF\" value=\"on\" checked>CPF (pessoa física) ou</td></tr>
    <tr><td class=\"texto\"><input type=\"radio\" name=\"chkCPF\" id=\"chkCPF\" value=\"off\">CNPJ (pessoa jurídica)</td></tr>
    <tr><td class=\"texto\">N&uacute;mero (CPF/CNPJ):</td><td><input class=\"campo\" type=\"text\" name=\"CampoNumero\" id=\"CampoNumero\" size=\"18\" maxlength=\"14\"></td></tr>
    <tr><td class=\"texto\">Senha:</td><td><input class=\"campo\" type=\"password\" name=\"senha\" id=\"senha\" size=\"18\" maxlength=\"8\"></td></tr>
    <tr><td class=\"texto\"></td><td><input class=\"campo\" name=\"cadastrar\" type=\"submit\" value=\"Cadastrar\"></td></tr>
    <tr><td class=\"texto\"></td><td><a href=java script:history.go(-1)>«« Voltar</a></td></tr>
    </table>
    </HTML>
    ";
    } 
    ?>
    <HTML>
    <head>
    <script language="JavaScript" type="text/JavaScript">
    <!--
    
                 function validaCPF(cpf) {
                     erro = new String;
                     if (cpf.length != 11) erro += "CPF deve conter 11 dígitos numéricos! \n\n";
                     var nonNumbers = /\D/;
                     if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros! \n\n";
                     if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
                             erro += "Numero de CPF invalido!"
                   }
                   var a = [];
                   var b = new Number;
                   var c = 11;
                   for (i=0; i<11; i++){
                          a[i] = cpf.charAt(i);
                           if (i < 9) b += (a[i] * --c);
                   }
                   if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
                   b = 0;
                   c = 11;
                   for (y=0; y<10; y++) b += (a[y] * c--);
                   if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
                   if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
                           erro +="Digito verificador com problema!";
                   }
                   if (erro.length > 0){
                           return erro;
                   }
                   return true;
           }
    
    
             function validaCNPJ(CNPJ) {
                     erro = new String;
                     if (CNPJ.length != 14) erro += "CNPJ deve conter 14 dígitos numéricos! \n\n";
    
                     //substituir os caracteres que não são números
                   if(document.layers && parseInt(navigator.appVersion) == 4){
                           x = CNPJ.substring(0,2);
                           x += CNPJ.substring (3,6);
                           x += CNPJ.substring (7,10);
                           x += CNPJ.substring (11,14);
                           CNPJ = x;
                   } else {
                           CNPJ = CNPJ.replace (".","");
                           CNPJ = CNPJ.replace (".","");
                           CNPJ = CNPJ.replace ("-","");
                           CNPJ = CNPJ.replace ("/","");
                   }
                   var nonNumbers = /\D/;
                   if (nonNumbers.test(CNPJ)) erro += "A verificação de CNPJ suporta apenas números! \n\n";
                   var a = [];
                   var b = new Number;
                   var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
                   for (i=0; i<12; i++){
                           a[i] = CNPJ.charAt(i);
                           b += a[i] * c[i+1];
     }
                   if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
                   b = 0;
                   for (y=0; y<13; y++) {
                           b += (a[y] * c[y]);
                   }
                   if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
                   if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
                           erro +="Dígito verificador com problema!";
                   }
                   if (erro.length > 0){
                           return erro;
                   } else {
                           return true;
                   }
    
          }
    
    function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
    }
    
    function MM_validateForm() { //v4.0
      var i,p,que,nm,test,num,min,max;
      var errors='';
      var args=MM_validateForm.arguments;
      var aux=document.getElementById('senha').value;
      var cpfcnpj=document.getElementById('CampoNumero').value;
      var checkcpf=document.getElementById('chkCPF').value;
      for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
        if (val) { nm=val.name; if ((val=val.value)!="") {
          if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
            if (p<1 || p==(val.length-1)) errors+='O campo '+nm+' requer um endereço de email válido.\n';
          } else if (test!='R') { num = parseFloat(val);
            if (isNaN(val)) errors+='O campo '+nm+' aceita somente números.\n';
            if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
              min=test.substring(8,p); max=test.substring(p+1);
              if (aux.length<min || max<aux.length) errors+='- '+nm+' deve conter no mínimo '+min+' dígitos e no máximo '+max+' dígitos.\n';
        } } } else if (test.charAt(0) == 'R') errors += 'O campo '+nm+' deve ser preenchido.\n'; }
      }  
      if (checkcpf == "on"){ aux = validaCPF(cpfcnpj); if (aux != true) errors += aux; } else {
      aux = validaCNPJ(cpfcnpj); if (aux != true) errors += aux; }
      if (errors) alert('Erro ao preencher o formulário:\n'+errors);
      document.MM_returnValue = (errors == '');
    }
    //-->
    </script>
    </head>
    </html>
    Desculpem aí pela falta de identação!!! EDIT: Problema resolvido! Problema estava que os botões tipo radio estavam com o mesmo ID. Aqui vai código validando corretamente todos os campos.
    <?
    ####################################
    #    Protegendo páginas v. 2.5     #
    #  Script desenvolvido por |paes|  #
    ####################################
    include("config.php");
    
      if($acao == 'cadastra'){
    $sql = "SELECT * FROM users where login='$CampoNumero'";
    
    $resultado = mysql_query($sql)
    or die ("Não foi possível realizar a consulta ao banco de dados");
    
    if(mysql_num_rows($resultado)>0) {
    
    while ($linha=mysql_fetch_array($resultado)) {
    $CampoNumero = $linha["loginc"];
    }
    }
    if(($CampoNumero == $loginc) && ($CampoNumero != "")){
    echo"<script>alert('Este CPF/CNPJ já está cadastrado. Entre com outro CPF/CNPJ');
    history.back(-1);</script>";
    }else{
        if (${"chkCPF"}=="on"){
            $nome = $_POST['nome'];
            $email = $_POST['email'];
            $ddd = $_POST['ddd'];
            $telefone = $_POST['telefone'];
            $endereco = $_POST['endereco'];
            $cep = $_POST['cep'];
            $cidade = $_POST['cidade'];
            $estado = $_POST['estado'];
            $cpf = $_POST['CampoNumero'];
            $cnpj = '';
            $login = $_POST['CampoNumero'];
            $senha = $_POST['senha'];
            $sql = mysql_query("Insert into users values('$id', '$nome', '$email', '$ddd', '$telefone', '$endereco', '$cep', '$cidade', '$estado', '$cpf', '$cnpj', '$login', '$senha')");
    
    if($sql){
    echo "<script>alert('Usuário cadastrado com sucesso.');
    location.href='index.php';
    </script>
    ";
    } else {
    echo "<script>alert('Não foi possível cadastrar usuário.');
    history.back(-1);
    </script>
    ";
    }
    
        }else{
            $nome = $_POST['nome'];
            $email = $_POST['email'];
            $ddd = $_POST['ddd'];
            $telefone = $_POST['telefone'];
            $endereco = $_POST['endereco'];
            $cep = $_POST['cep'];
            $cidade = $_POST['cidade'];
            $estado = $_POST['estado'];
            $cpf = '';
            $cnpj = $_POST['CampoNumero'];
            $login = $_POST['CampoNumero'];
            $senha = $_POST['senha'];        
            $sql = mysql_query("Insert into users values('$id', '$nome', '$email', '$ddd', '$telefone', '$endereco', '$cep', '$cidade', '$estado', '$cpf', '$cnpj', '$login', '$senha')");
    
    if($sql){
    echo "<script>alert('Usuário cadastrado com sucesso.');
    location.href='index.php';
    </script>
    ";
    } else {
    echo "<script>alert('Não foi possível cadastrar usuário.');
    history.back(-1);
    </script>
    ";
    }
    
        }
    }
    } else {
    echo"
    <HTML>
    <head>
    <title>$nsite</title>
    </head>
    <form action=\"cadastrar.php?acao=cadastra\" method=\"post\" onSubmit=\"MM_validateForm('nome','','R','email','','NisEmail','ddd','','RisNum','telefone','','RisNum','endereco','','R','cep','','RisNum','cidade','','R','estado','','R','CampoNumero','','RisNum','senha','','RinRange6:8');return document.MM_returnValue\">
    <table width=\"100%\" align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
    <tr valign=\"top\"><td align=\"center\" colspan=\"2\"><h1>Cadastro de Clientes</h1></td></tr>
    <tr><td colspan=\"2\">&nbsp;</td></tr>
    <tr><td class=\"texto\">Nome:&nbsp;</td><td><input class=\"campo\" name=\"nome\" type=\"text\" size=\"30\" maxlength=\"255\"></td></tr>
    <tr><td class=\"texto\">E-mail:&nbsp;</td><td><input class=\"campo\" name=\"email\" type=\"text\" size=\"30\" maxlength=\"100\"></td></tr>
    <tr><td class=\"texto\">DDD(xx) - Telefone(somente números):&nbsp;</td><td><input class=\"campo\" name=\"ddd\" type=\"text\" size=\"2\" maxlength=\"2\">&nbsp;-&nbsp;<input class=\"campo\" name=\"telefone\" type=\"text\" size=\"15\" maxlength=\"8\"></td></tr>
    <tr><td class=\"texto\">Endereço:&nbsp;</td><td><input class=\"campo\" name=\"endereco\" type=\"text\" size=\"30\"></td></tr>
    <tr><td class=\"texto\">CEP (Somente números):&nbsp;</td><td><input class=\"campo\" name=\"cep\" type=\"text\" size=\"15\" maxlength=\"8\"></td></tr>
    <tr><td class=\"texto\">Cidade:&nbsp;</td><td><input class=\"campo\" name=\"cidade\" type=\"text\" size=\"30\"></td></tr>
    <tr><td class=\"texto\">Estado:&nbsp;</td><td><input class=\"campo\" name=\"estado\" type=\"text\" size=\"30\"></td></tr>
    <tr><td class=\"texto\"><input type=\"radio\" name=\"chkCPF\" id=\"chkCPF\" value=\"on\" checked>CPF (pessoa física) ou</td></tr>
    <tr><td class=\"texto\"><input type=\"radio\" name=\"chkCPF\" id=\"chkCNPJ\" value=\"off\">CNPJ (pessoa jurídica)</td></tr>
    <tr><td class=\"texto\">N&uacute;mero (CPF/CNPJ):</td><td><input class=\"campo\" type=\"text\" name=\"CampoNumero\" id=\"CampoNumero\" size=\"18\" maxlength=\"14\"></td></tr>
    <tr><td class=\"texto\">Senha:</td><td><input class=\"campo\" type=\"password\" name=\"senha\" id=\"senha\" size=\"18\" maxlength=\"8\"></td></tr>
    <tr><td class=\"texto\"></td><td><input class=\"campo\" name=\"cadastrar\" type=\"submit\" value=\"Cadastrar\"></td></tr>
    <tr><td class=\"texto\"></td><td><a href=java script:history.go(-1)>«« Voltar</a></td></tr>
    </table>
    </HTML>
    ";
    } 
    ?>
    <HTML>
    <head>
    <script language="JavaScript" type="text/JavaScript">
    <!--
    
                 function validaCPF(cpf) {
                     erro = new String;
                     if (cpf.length != 11) erro += "CPF deve conter 11 dígitos numéricos! \n";
                     var nonNumbers = /\D/;
                     if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros! \n";
                     if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
                             erro += "Numero de CPF invalido!"
                   }
                   var a = [];
                   var b = new Number;
                   var c = 11;
                   for (i=0; i<11; i++){
                          a[i] = cpf.charAt(i);
                           if (i < 9) b += (a[i] * --c);
                   }
                   if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
                   b = 0;
                   c = 11;
                   for (y=0; y<10; y++) b += (a[y] * c--);
                   if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
                   if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
                           erro +="Digito verificador com problema!";
                   }
                   if (erro.length > 0){
                           return erro;
                   }
                   return true;
           }
    
    
             function validaCNPJ(CNPJ) {
                     erro = new String;
                     if (CNPJ.length != 14) erro += "CNPJ deve conter 14 dígitos numéricos! \n";
    
                     //substituir os caracteres que não são números
                   if(document.layers && parseInt(navigator.appVersion) == 4){
                           x = CNPJ.substring(0,2);
                           x += CNPJ.substring (3,6);
                           x += CNPJ.substring (7,10);
                           x += CNPJ.substring (11,14);
                           CNPJ = x;
                   } else {
                           CNPJ = CNPJ.replace (".","");
                           CNPJ = CNPJ.replace (".","");
                           CNPJ = CNPJ.replace ("-","");
                           CNPJ = CNPJ.replace ("/","");
                   }
                   var nonNumbers = /\D/;
                   if (nonNumbers.test(CNPJ)) erro += "A verificação de CNPJ suporta apenas números! \n";
                   var a = [];
                   var b = new Number;
                   var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
                   for (i=0; i<12; i++){
                           a[i] = CNPJ.charAt(i);
                           b += a[i] * c[i+1];
     }
                   if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
                   b = 0;
                   for (y=0; y<13; y++) {
                           b += (a[y] * c[y]);
                   }
                   if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
                   if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
                           erro +="Dígito verificador com problema!";
                   }
                   if (erro.length > 0){
                           return erro;
                   } else {
                           return true;
                   }
    
          }
    
    function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
    }
    
    function MM_validateForm() { //v4.0
      var i,p,que,nm,test,num,min,max;
      var errors='';
      var args=MM_validateForm.arguments;
      var aux=document.getElementById('senha').value;
      var cpfcnpj=document.getElementById('CampoNumero').value;
      var checkcpf=document.getElementById('chkCPF');
      for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
        if (val) { nm=val.name; if ((val=val.value)!="") {
          if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
            if (p<1 || p==(val.length-1)) errors+='O campo '+nm+' requer um endereço de email válido.\n';
          } else if (test!='R') { num = parseFloat(val);
            if (isNaN(val)) errors+='O campo '+nm+' aceita somente números.\n';
            if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
              min=test.substring(8,p); max=test.substring(p+1);
              if (aux.length<min || max<aux.length) errors+='- '+nm+' deve conter no mínimo '+min+' dígitos e no máximo '+max+' dígitos.\n';
        } } } else if (test.charAt(0) == 'R') errors += 'O campo '+nm+' deve ser preenchido.\n'; }
      }  
      if (checkcpf.checked == true){ aux = validaCPF(cpfcnpj); if (aux != true) errors += aux; } else {
      aux = validaCNPJ(cpfcnpj); if (aux != true) errors += aux; }
      if (errors) alert('Erro ao preencher o formulário:\n'+errors);
      document.MM_returnValue = (errors == '');
    }
    //-->
    </script>
    </head>
    </html>

  4. M@luco Belez@

    Num dá pra dar include com query string não! Acho que ele vai procurar o arquivo pelo nome inteiro "chama.php?teste=testando" e consequentemente não encontra. Pelo menos uma vez que tentei não deu certo...

    foxbh, Faz o seguinte

    <?php
    $teste = "Testando";
    include 'http://www.todobh.com.br/chama.php';
    ?>
    Pagina que é chamada pelo include
    <?php
    global $teste;
    echo $teste;
    ?>

    Depois diz aí se funciona!!

  5. Com session_start(); e session_destroy(); não funcionou.

    Eu criei um link comum para

    sair.php

    <?php
    setcookie("usuario");
    setcookie("senha");
    header("Location: index.php");
    ?>
    Isso até que faz o logoff e redireciona para index.php, mas eu não queria que ele efetuasse logoff na página1.php e fosse parar na página2.php. Por isso que eu to precisando de algo que detecte a página anterior. e fazendo sair.php
    <?php
    session_start();
    setcookie("usuario");
    setcookie("senha");
    header("Location: ".$_SESSION['local']);
    ?>

    também não funcionou.

    Alguém tem alguma luz aí?!

  6. Beleza, mas como faria para chamar esse script?

    porque atualmente ao clicar no link sair ele está carregando a página com a ação=sair. E a ação sair é executada no verifica.php que é incluída em index.php.

    E para esse como funcionaria?

  7. Beraldo, agora tentei fazer esse esquema com query string mas o problema agora está na hora de efetuar logoff ele mostra um erro que o acesso não é permitido. Na hora de fazer login ele funciona.

    Se quiser dá pra fazer um teste aqui: http://www.acap-es.org.br/lorentino/index.php

    use o CPF 45761613506 para teste de login/logoff. Por enquanto o único link que está utilizando query string é o link "Beija-flores".

    Onde será que está o problema no código abaixo?!

    index.php

    <?php
    session_start();
    $_SESSION['local'] = isset ($_SERVER['QUERY_STRING']) ? $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'] : $_SERVER['PHP_SELF'];
    include("verifica.php");
    include("query.php");
    ?>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=">
    <title>Untitled Document</title>
    <link rel="stylesheet" href="styles/emx_nav_left.css" type="text/css">
    <script type="text/javascript">
    <!--
    var time = 3000;
    var numofitems = 7;
    
    //menu constructor
    function menu(allitems,thisitem,startstate){ 
      callname= "gl"+thisitem;
      divname="subglobal"+thisitem;  
      this.numberofmenuitems = 7;
      this.caller = document.getElementById(callname);
      this.thediv = document.getElementById(divna
      this.thediv.style.visibility = startstate;
    }
    
    //menu methods
    function ehandler(event,theobj){
      for (var i=1; i<= theobj.numberofmenuitems; i++){
        var shutdiv =eval( "menuitem"+i+".thediv");
        shutdiv.style.visibility="hidden";
      }
      theobj.thediv.style.visibility="visible";
    }
                    
    function closesubnav(event){
      if ((event.clientY <48)||(event.clientY > 107)){
        for (var i=1; i<= numofitems; i++){
          var shutdiv =eval('menuitem'+i+'.thediv');
          shutdiv.style.visibility='hidden';
        }
      }
    }
    // -->
    </script>
    </head>
    <body onmousemove="closesubnav(event);"> 
    <div class="skipLinks">skip to: <a href="#content">page content</a> | <a href="pageNav">links on this page</a> | <a href="#globalNav">site navigation</a> | <a href="#siteInfo">footer (site information)</a> </div>
    <div id="masthead"> 
      <h1 id="siteName">Site Name</h1> 
      <div id="utility"> 
        <a href="#">Utility Link</a> | <a href="#">Utility Link</a> | <a href="#">Utility
        Link</a> 
      </div> 
      <div id="globalNav"> 
        <img alt="" src="images/gblnav_left.gif" height="32" width="4" id="gnl"> <img alt="" src="images/glbnav_right.gif" height="32" width="4" id="gnr"> 
        <div id="globalLink"> 
          <a href="#" id="gl1" class="glink" onmouseover="ehandler(event,menuitem1);">Cadastrar</a><a href="#" id="gl2" class="glink" onmouseover="ehandler(event,menuitem2);">Como Fazer Pedido </a><a href="#" id="gl3" class="glink" onmouseover="ehandler(event,menuitem3);">Fazer Pedido </a><a href="#" id="gl4" class="glink" onmouseover="ehandler(event,menuitem4);">Produtos</a><a href="#" id="gl5" class="glink" onmouseover="ehandler(event,menuitem5);">Meu Carrinho </a><a href="#" id="gl6" class="glink" onmouseover="ehandler(event,menuitem6);">Contato</a><a href="#" id="gl7" class="glink" onmouseover="ehandler(event,menuitem7);">global
          link</a> 
        </div> 
        <!--end globalLinks-->      
      </div> 
      <!-- end globalNav --> 
      <div id="subglobal1" class="subglobalNav"> 
        <a href="#">subglobal1 link</a> | <a href="#">subglobal1 link</a> | <a href="#">subglobal1
        link</a> | <a href="#">subglobal1 link</a> | <a href="#">subglobal1 link</a> | <a href="#">subglobal1
        link</a> | <a href="#">subglobal1 link</a> 
      </div> 
      <div id="subglobal2" class="subglobalNav"> 
        <a href="#">subglobal2 link</a> | <a href="#">subglobal2 link</a> | <a href="#">subglobal2
        link</a> | <a href="#">subglobal2 link</a> | <a href="#">subglobal2 link</a> | <a href="#">subglobal2
        link</a> | <a href="#">subglobal2 link</a> 
      </div> 
      <div id="subglobal3" class="subglobalNav"> 
        <a href="#">subglobal3 link</a> | <a href="#">subglobal3 link</a> | <a href="#">subglobal3
        link</a> | <a href="#">subglobal3 link</a> | <a href="#">subglobal3 link</a> | <a href="#">subglobal3
        link</a> | <a href="#">subglobal3 link</a> 
      </div> 
      <div id="subglobal4" class="subglobalNav"> 
        <a href="#">subglobal4 link</a> | <a href="#">subglobal4 link</a> | <a href="#">subglobal4
        link</a> | <a href="#">subglobal4 link</a> | <a href="#">subglobal4 link</a> | <a href="#">subglobal4
        link</a> | <a href="#">subglobal4 link</a> 
      </div> 
      <div id="subglobal5" class="subglobalNav"> 
        <a href="#">subglobal5 link</a> | <a href="#">subglobal5 link</a> | <a href="#">subglobal5
        link</a> | <a href="#">subglobal5 link</a> | <a href="#">subglobal5 link</a> | <a href="#">subglobal5
        link</a> | <a href="#">subglobal5 link</a> 
      </div> 
      <div id="subglobal6" class="subglobalNav"> 
        <a href="#">subglobal6 link</a> | <a href="#">subglobal6 link</a> | <a href="#">subglobal6
        link</a> | <a href="#">subglobal6 link</a> | <a href="#">subglobal6 link</a> | <a href="#">subglobal6
        link</a> | <a href="#">subglobal6 link</a> 
      </div> 
      <div id="subglobal7" class="subglobalNav"> 
        <a href="#">subglobal7 link</a> | <a href="#">subglobal7 link</a> | <a href="#">subglobal7
        link</a> | <a href="#">subglobal7 link</a> | <a href="#">subglobal7 link</a> | <a href="#">subglobal7
        link</a> | <a href="#">subglobal7 link</a> 
      </div> 
      <div id="subglobal8" class="subglobalNav"> 
        <a href="#">subglobal8 link</a> | <a href="#">subglobal8 link</a> | <a href="#">subglobal8
        link</a> | <a href="#">subglobal8 link</a> | <a href="#">subglobal8 link</a> | <a href="#">subglobal8
        link</a> | <a href="#">subglobal8 link</a> 
      </div> 
    </div> 
    <!-- end masthead --> 
    <div id="pagecell1"> 
      <!--pagecell1--> 
      <img alt="" src="images/tl_curve_white.gif" height="6" width="6" id="tl"> <img alt="" src="images/tr_curve_white.gif" height="6" width="6" id="tr"> 
      <div id="breadCrumb"> 
        <?php include ('bemvindo.php'); ?>
      </div> 
      <div id="pageName"> 
        <h2>Page Name</h2> 
        <img alt="small logo" src="" height="59" width="66"/> 
      </div> 
      <div id="pageNav"> 
        <div id="sectionLinks"> 
          <a href="#">Jel Plast </a> <a href="#">MegaZoo</a> <a href="#">NutriP&aacute;ssaros</a> <a href="#">Quinabra</a> <a href="#">Sementes</a> <a href="#">Section
          Link</a> 
        </div> 
        <div class="relatedLinks"> 
          <h3>Jel Plast </h3> 
          <a href="#">Aves</a> <a href="?categoria=jp&sub=beija">Beija-Flores</a> <a href="#">Hamsters</a> <a href="#">Related Link</a> <a href="#">Related Link</a> <a href="#">Related
          Link</a> 
        </div> 
        <div class="relatedLinks"> 
          <h3>Related Link Category</h3> 
          <a href="#">Related Link</a> <a href="#">Related Link</a> <a href="#">Related
          Link</a> <a href="#">Related Link</a> <a href="#">Related Link</a> <a href="#">Related
          Link</a> 
        </div> 
        <div id="advert"> 
          <img src="" alt="" width="107" height="66" /> Advertisement copy goes here.
          Advertisement copy goes here.
        </div> 
      </div> 
      <div id="content"> 
        <div class="feature"> 
    <?php
    if( (isset($pagina)) and (file_exists($pagina)) ) {
    include($pagina);
    } else {
    echo "<br><b>Página solicitada não existente.<br><a href=\"java script:history.back();\">Voltar</a></b>";
    }
    ?>
        </div> 
        <div class="story"> 
          
        </div> 
        <div class="story"> 
          
        </div> 
      </div> 
       <div id="siteInfo"> 
        <img src="" width="44" height="22"> <a href="#">About Us</a> | <a href="#">Site
        Map</a> | <a href="#">Privacy Policy</a> | <a href="#">Contact Us</a> | &copy;2003
        Company Name
      </div> 
    </div> 
    <!--end pagecell1--> 
    <br> 
    <script type="text/javascript">
        <!--
          var menuitem1 = new menu(7,1,"hidden");
                var menuitem2 = new menu(7,2,"hidden");
                var menuitem3 = new menu(7,3,"hidden");
                var menuitem4 = new menu(7,4,"hidden");
                var menuitem5 = new menu(7,5,"hidden");
                var menuitem6 = new menu(7,6,"hidden");
                var menuitem7 = new menu(7,7,"hidden");
        // -->
        </script> 
    </body>
    </html>
    verifica.php
    <?
    ####################################
    #    Protegendo páginas v. 2.5     #
    #  Script desenvolvido por |paes|  #
    ####################################
    ####################################
    #           Não altere               #
    ####################################
    // Sistema para verificar se o usuário já está logado ou não
    
    if($acao == sair){
    session_start();
    setcookie("usuario");
    setcookie("senha");
    header("Location: ".$_SESSION['local']);
    }
    ?>
    query.php
    <?php
    $categoria = isset($_REQUEST['categoria']) ? $_REQUEST['categoria'] : "";
    $sub = isset($_REQUEST['sub']) ? $_REQUEST['sub'] : "";
    ?>
    
    <?php
    if ($categoria == "" && !$sub) {
    $pagina = "cadastrar.php"; 
    }
    elseif ($categoria == "jp" && !$sub) {
    $pagina = "jp.php";
    }
    elseif ($categoria == "jp" && $sub == "beija") {
    $pagina = "loja/jelplast/beija.php"; 
    }
    ?>
    bemvindo.php
    <?
    include("config.php");
    include("include.php");
    
    if(!$HTTP_COOKIE_VARS["usuario"] && !$HTTP_COOKIE_VARS["senha"]){
    include("login.php");
    }else{
    echo"
    <font face=$fonte size=$tfonte>
    Bem vindo <b>$usuario</b>!&nbsp;&nbsp;&nbsp;<a href=?acao=sair>Sair</a>";
    }
    ?>~
    login.php
    <?php
    ####################################
    #    Protegendo páginas v. 2.5     #
    #  Script desenvolvido por |paes|  #
    ####################################
    include("config.php");
    include("include.php");
    
    session_start();
    
    $query = mysql_query("Select * From users where login='$login_' and senha='$senha_'");
    $valida = mysql_fetch_array($query);
    
    $user = $valida["login"];
    $pass = $valida["senha"];
    
    if($login_ == '' || $senha_ == ''){
    echo"
    <HTML>
    <title>$nsite</title>
    <form action=\"login.php\" method=\"post\">
    <table align=\"center\" width=\"90%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
    <tr><td height=\"25\">Bem vindo <b>visitante</b>!&nbsp;&nbsp;<a href=\"cadastro.php\" target=\"_parent\">Cadastre-se</a> ou efetue login ao lado:</td>
    <td height=\"25\">CPF/CNPJ:</td><td><input name=\"login_\" type=\"text\"></td>
    <td height=\"25\">Repita CPF/CNPJ:</td><td><input name=\"senha_\" type=\"password\"></td>
    <td height=\"25\">&nbsp;</td><td><input name=\"logar\" type=\"submit\" value=\"Logar\"></td></tr>
    </table>
    </form>
    </HTML>";
    } elseif($login_ == $user && $senha_ == $pass){
    setcookie("usuario", $login_);
    setcookie("senha", $senha_);
    header("Location: ".$_SESSION['local']);
    } elseif($login_ != $valida["login"] || $senha_ != $valida["senha"]){
    echo "<font face=\"$fonte\" size=\"$tfonte\">Usuário ou senha inválido.<br><a href=mailto:$admine>Contate o administrador</a> se você tem certeza de que os dados estão corretos.<br><br>
    <a href=login.php>«« Voltar</a></font>";
    }
    ?>
    cadastrar.php
    <?
    ####################################
    #    Protegendo páginas v. 2.5     #
    #  Script desenvolvido por |paes|  #
    ####################################
    include("config.php");
    
      if($acao == 'cadastra'){
    $sql = "SELECT * FROM users where login='$CampoNumero'";
    
    $resultado = mysql_query($sql)
    or die ("Não foi possível realizar a consulta ao banco de dados");
    
    if(mysql_num_rows($resultado)>0) {
    
    while ($linha=mysql_fetch_array($resultado)) {
    $CampoNumero = $linha["loginc"];
    }
    }
        if($CampoNumero == $loginc){
    echo"<script>alert('Este CPF/CNPJ já está cadastrado. Entre com outro CPF/CNPJ');
    history.back(-1);</script>";
    }else{
        if (${"chkCPF"}=="on"){
            CalculaCPF($CampoNumero);
        }else{
            CalculaCNPJ($CampoNumero);
        }
    }
    } else {
    echo"
    <HTML>
    <head>
    <title>$nsite</title>
    </head>
    <form action=\"cadastrar.php?acao=cadastra\" method=\"post\" onSubmit=\"MM_validateForm('nome','','R','email','','NisEmail','ddd','','RisNum','telefone','','RisNum','endereco','','R','cep','','RisNum','cidade','','R','estado','','R','CampoNumero','','RisNum');return document.MM_returnValue\">
    <table width=\"100%\" align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
    <tr><td class=\"texto\">Nome:&nbsp;</td><td><input class=\"campo\" name=\"nome\" type=\"text\" size=\"30\" maxlength=\"255\"></td></tr>
    <tr><td class=\"texto\">E-mail:&nbsp;</td><td><input class=\"campo\" name=\"email\" type=\"text\" size=\"30\" maxlength=\"100\"></td></tr>
    <tr><td class=\"texto\">DDD(xx) - Telefone(somente números):&nbsp;</td><td><input class=\"campo\" name=\"ddd\" type=\"text\" size=\"2\" maxlength=\"2\">&nbsp;-&nbsp;<input class=\"campo\" name=\"telefone\" type=\"text\" size=\"15\" maxlength=\"8\"></td></tr>
    <tr><td class=\"texto\">Endereço:&nbsp;</td><td><input class=\"campo\" name=\"endereco\" type=\"text\" size=\"30\"></td></tr>
    <tr><td class=\"texto\">CEP (Somente números):&nbsp;</td><td><input class=\"campo\" name=\"cep\" type=\"text\" size=\"15\" maxlength=\"8\"></td></tr>
    <tr><td class=\"texto\">Cidade:&nbsp;</td><td><input class=\"campo\" name=\"cidade\" type=\"text\" size=\"30\"></td></tr>
    <tr><td class=\"texto\">Estado:&nbsp;</td><td><input class=\"campo\" name=\"estado\" type=\"text\" size=\"30\"></td></tr>
    <tr><td class=\"texto\"><input type=\"radio\" name=\"chkCPF\" value=\"on\" checked>CPF (pessoa física) ou</td></tr>
    <tr><td class=\"texto\"><input type=\"radio\" name=\"chkCPF\" value=\"off\">CNPJ (pessoa jurídica)</td></tr>
    <tr><td class=\"texto\">N&uacute;mero (CPF/CNPJ):</td><td><input class=\"campo\" type=\"text\" name=\"CampoNumero\" size=\"18\" maxlength=\"14\"></td></tr>
    <tr><td class=\"texto\"></td><td><input class=\"campo\" name=\"cadastrar\" type=\"submit\" value=\"Cadastrar\"></td></tr>
    <tr><td class=\"texto\"></td><td><a href=java script:history.go(-1)>«« Voltar</a></td></tr>
    </table>
    </HTML>
    ";
    }
    
      //Calcula CPF
    
      function CalculaCPF($CampoNumero)
      {
       $RecebeCPF=$CampoNumero;
       //Retirar todos os caracteres que não sejam 0-9
       $s="";
       for ($x=1; $x<=strlen($RecebeCPF); $x=$x+1)
       {
        $ch=substr($RecebeCPF,$x-1,1);
        if (ord($ch)>=48 && ord($ch)<=57)
        {
          $s=$s.$ch;
        }
       }
       
       $RecebeCPF=$s;
       if (strlen($RecebeCPF)!=11)
       {
        echo "<script>alert('CPF deve conter 11 dígitos.');
    history.back(-1);</script>";
       }
       else
         if ($RecebeCPF=="00000000000")
         {
           $then;
           echo "<script>alert('CPF Inválido. Entre com um CPF Válido');
    history.back(-1);</script>";
         }
         else
         {
          $Numero[1]=intval(substr($RecebeCPF,1-1,1));
          $Numero[2]=intval(substr($RecebeCPF,2-1,1));
          $Numero[3]=intval(substr($RecebeCPF,3-1,1));
          $Numero[4]=intval(substr($RecebeCPF,4-1,1));
          $Numero[5]=intval(substr($RecebeCPF,5-1,1));
          $Numero[6]=intval(substr($RecebeCPF,6-1,1));
          $Numero[7]=intval(substr($RecebeCPF,7-1,1));
          $Numero[8]=intval(substr($RecebeCPF,8-1,1));
          $Numero[9]=intval(substr($RecebeCPF,9-1,1));
          $Numero[10]=intval(substr($RecebeCPF,10-1,1));
          $Numero[11]=intval(substr($RecebeCPF,11-1,1));
    
         $soma=10*$Numero[1]+9*$Numero[2]+8*$Numero[3]+7*$Numero[4]+6*$Numero[5]+5*
         $Numero[6]+4*$Numero[7]+3*$Numero[8]+2*$Numero[9];
         $soma=$soma-(11*(intval($soma/11)));
    
        if ($soma==0 || $soma==1)
        {
          $resultado1=0;
        }
        else
        {
          $resultado1=11-$soma;
        }
    
        if ($resultado1==$Numero[10])
        {
         $soma=$Numero[1]*11+$Numero[2]*10+$Numero[3]*9+$Numero[4]*8+$Numero[5]*7+$Numero[6]*6+$Numero[7]*5+
         $Numero[8]*4+$Numero[9]*3+$Numero[10]*2;
         $soma=$soma-(11*(intval($soma/11)));
    
         if ($soma==0 || $soma==1)
         {
           $resultado2=0;
         }
         else
         {
          $resultado2=11-$soma;
         }
         if ($resultado2==$Numero[11]){
            $nome = $_POST['nome'];
            $email = $_POST['email'];
            $ddd = $_POST['ddd'];
            $telefone = $_POST['telefone'];
            $endereco = $_POST['endereco'];
            $cep = $_POST['cep'];
            $cidade = $_POST['cidade'];
            $estado = $_POST['estado'];
            $cpf = $_POST['CampoNumero'];
            $cnpj = '';
            $login = $_POST['CampoNumero'];
            $senha = $_POST['CampoNumero'];
            $sql = mysql_query("Insert into users values('$id', '$nome', '$email', '$ddd', '$telefone', '$endereco', '$cep', '$cidade', '$estado', '$cpf', '$cnpj', '$login', '$senha')");
    
    if($sql){
    echo "<script>alert('Usuário cadastrado com sucesso.');
    location.href='logado.php';
    </script>
    ";
    } else {
    echo "<script>alert('Não foi possível cadastrar usuário.');
    history.back(-1);
    </script>
    ";
    }
    
         }
         else
         {
         echo "<script>alert('CPF Inválido. Entre com um CPF Válido');
    history.back(-1);</script>";
         }
        }
        else
        {
         echo "<script>alert('CPF Inválido. Entre com um CPF Válido');
    history.back(-1);</script>";
        }
       }
      }
    // Fim do Calcula CPF
    
    
    //Função que calcula CNPJ
    
      function CalculaCNPJ($CampoNumero)
      {
       $RecebeCNPJ=${"CampoNumero"};
    
       $s="";
       for ($x=1; $x<=strlen($RecebeCNPJ); $x=$x+1)
       {
        $ch=substr($RecebeCNPJ,$x-1,1);
        if (ord($ch)>=48 && ord($ch)<=57)
        {
         $s=$s.$ch;
        }
       }
    
       $RecebeCNPJ=$s;
       if (strlen($RecebeCNPJ)!=14)
       {
         echo "<script>alert('CNPJ deve conter 14 dígitos.');
    history.back(-1);</script>s</h1>";
       }
       else
        if ($RecebeCNPJ=="00000000000000")
        {
         $then;
         echo "<script>alert('CNPJ Inválido. Entre com um CNPJ Válido');
    history.back(-1);</script>";
       }
       else
       {
        $Numero[1]=intval(substr($RecebeCNPJ,1-1,1));
        $Numero[2]=intval(substr($RecebeCNPJ,2-1,1));
        $Numero[3]=intval(substr($RecebeCNPJ,3-1,1));
        $Numero[4]=intval(substr($RecebeCNPJ,4-1,1));
        $Numero[5]=intval(substr($RecebeCNPJ,5-1,1));
        $Numero[6]=intval(substr($RecebeCNPJ,6-1,1));
        $Numero[7]=intval(substr($RecebeCNPJ,7-1,1));
        $Numero[8]=intval(substr($RecebeCNPJ,8-1,1));
        $Numero[9]=intval(substr($RecebeCNPJ,9-1,1));
        $Numero[10]=intval(substr($RecebeCNPJ,10-1,1));
        $Numero[11]=intval(substr($RecebeCNPJ,11-1,1));
        $Numero[12]=intval(substr($RecebeCNPJ,12-1,1));
        $Numero[13]=intval(substr($RecebeCNPJ,13-1,1));
        $Numero[14]=intval(substr($RecebeCNPJ,14-1,1));
    
        $soma=$Numero[1]*5+$Numero[2]*4+$Numero[3]*3+$Numero[4]*2+$Numero[5]*9+$Numero[6]*8+$Numero[7]*7+
        $Numero[8]*6+$Numero[9]*5+$Numero[10]*4+$Numero[11]*3+$Numero[12]*2;
    
        $soma=$soma-(11*(intval($soma/11)));
    
       if ($soma==0 || $soma==1)
       {
         $resultado1=0;
       }
       else
       {
        $resultado1=11-$soma;
       }
       if ($resultado1==$Numero[13])
       {
        $soma=$Numero[1]*6+$Numero[2]*5+$Numero[3]*4+$Numero[4]*3+$Numero[5]*2+$Numero[6]*9+
        $Numero[7]*8+$Numero[8]*7+$Numero[9]*6+$Numero[10]*5+$Numero[11]*4+$Numero[12]*3+$Numero[13]*2;
        $soma=$soma-(11*(intval($soma/11)));
        if ($soma==0 || $soma==1)
        {
         $resultado2=0;
        }
       else
       {
       $resultado2=11-$soma;
       }
       if ($resultado2==$Numero[14]){
            $nome = $_POST['nome'];
            $email = $_POST['email'];
            $ddd = $_POST['ddd'];
            $telefone = $_POST['telefone'];
            $endereco = $_POST['endereco'];
            $cep = $_POST['cep'];
            $cidade = $_POST['cidade'];
            $estado = $_POST['estado'];
            $cpf = '';
            $cnpj = $_POST['CampoNumero'];
            $login = $_POST['CampoNumero'];
            $senha = $_POST['CampoNumero'];        
            $sql = mysql_query("Insert into users values('$id', '$nome', '$email', '$ddd', '$telefone', '$endereco', '$cep', '$cidade', '$estado', '$cpf', '$cnpj', '$login', '$senha')");
    
    if($sql){
    echo "<script>alert('Usuário cadastrado com sucesso.');
    location.href='logado.php';
    </script>
    ";
    } else {
    echo "<script>alert('Não foi possível cadastrar usuário.');
    history.back(-1);
    </script>
    ";
    }
    
       }
       else
       {
       echo "<script>alert('CNPJ Inválido. Entre com um CNPJ Válido');
    history.back(-1);</script>";
       }
      }
      else
      {
       echo "<script>alert('CNPJ Inválido. Entre com um CNPJ Válido');
    history.back(-1);</script>";
      }
     }
    }
    //Fim do Calcula CNPJ
    ?>
    <?
    include("copyright.php");
    ?>
    <HTML>
    <head>
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
    }
    
    function MM_validateForm() { //v4.0
      var i,p,que,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
      for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
        if (val) { nm=val.name; if ((val=val.value)!="") {
          if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
            if (p<1 || p==(val.length-1)) errors+='O campo '+nm+' requer um endereço de email válido.\n';
          } else if (test!='R') { num = parseFloat(val);
            if (isNaN(val)) errors+='O campo '+nm+' aceita somente números.\n';
            if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
              min=test.substring(8,p); max=test.substring(p+1);
              if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
        } } } else if (test.charAt(0) == 'R') errors += 'O campo '+nm+' deve ser preenchido.\n'; }
      } if (errors) alert('Erro ao preencher o formulário:\n'+errors);
      document.MM_returnValue = (errors == '');
    }
    //-->
    </script>
    </head>
    </html>
    beija.php
    <?
    include("verifica.php");
    ?>
    <?
    //INICIALIZA A SESSÃO
    session_start();
    
    //MONTA O ARRAY DE PRODUTOS
    $produtos[101][CODIGO]     =   "010JP";
    $produtos[101][ARTISTA]     =   "Beija-Flores";
    $produtos[101][ALBUM]       =   "Bebedouro Luxo";
    $produtos[101][preço]       =   "25,50";
    $produtos[101][THUMB]      =   "/thumbs/jelplast/beijaflores/010jp.jpg";
    $produtos[101][IMAGEM]      =   "/imagens/jelplast/beijaflores/010jp.jpg";
    
    $produtos[201][CODIGO]     =   "020JP";
    $produtos[201][ARTISTA]     =   "Beija-Flores";
    $produtos[201][ALBUM]       =   "Bebedouro Bandeja";
    $produtos[201][preço]       =   "28,35";
    $produtos[201][THUMB]      =   "/thumbs/jelplast/beijaflores/020jp.jpg";
    $produtos[201][IMAGEM]      =   "/imagens/jelplast/beijaflores/020jp.jpg";
    
    $produtos[301][CODIGO]     =   "030JP";
    $produtos[301][ARTISTA]     =   "Beija-Flores";
    $produtos[301][ALBUM]       =   "Bebedouro Anti-Formiga";
    $produtos[301][preço]       =   "27,00";
    $produtos[301][THUMB]      =   "/thumbs/jelplast/beijaflores/030jp.jpg";
    $produtos[301][IMAGEM]      =   "/imagens/jelplast/beijaflores/030jp.jpg";
    
    $produtos[401][CODIGO]     =   "040JP";
    $produtos[401][ARTISTA]     =   "Beija-Flores";
    $produtos[401][ALBUM]       =   "Bebedouro Simples";
    $produtos[401][preço]       =   "30,00";
    $produtos[401][THUMB]      =   "/thumbs/jelplast/beijaflores/040jp.jpg";
    $produtos[401][IMAGEM]      =   "/imagens/jelplast/beijaflores/040jp.jpg";
    
    
    //TOTAL DE PRODUTOS POR LINHA
    $total = 2;
    ?>
    
    <html>
    <head>
    <title>97º artigo PHP</title>
    <style type="text/css">
    <!--
    body {
        margin-left: 0px;
        margin-top: 0px;
        margin-right: 0px;
        margin-bottom: 0px;
    }
    -->
    </style>
    <script language="JavaScript">
    <!--
    function MM_openBrWindow(theURL,winName,features) { //v2.0
      window.open(theURL,winName,features);
    }
    //-->
    </script>
    </head>
    
    <body>
    <table width="773"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td> <br>
        <table width="95%"  border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td align='center'><font face='Arial' size='4'><b>Bebedouros para Beija-Flores </b></font></td>
          </tr>
        </table>
        <br>
        <table width="95%"  border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td><font face='Arial' size='2'>Confira abaixo, os produtos dispon&iacute;veis no site:</font> </td>
          </tr>
        </table>
        <br>   
        <form action="carrinho.php" method="post" name="frmcarrinho">
           <input type="hidden" name="opc_efetivar" value="1">
    
           <table width="90%"  border="0" align="center" cellpadding="0" cellspacing="0"> 
           <tr>
           <?
           //PEGA A CHAVE DO ARRAY
           $chave = array_keys($produtos);
           
           //EXIBE OS PRODUTOS
            for($i=0; $i<sizeof($chave); $i++) {
               $indice    =   $chave[$i];
               $codigo    =   $produtos[$indice][CODIGO];
               $artista   =   $produtos[$indice][ARTISTA];
               $album     =   $produtos[$indice][ALBUM];
               $preço     =   $produtos[$indice][preço];
               $thumb    =   $produtos[$indice][THUMB];
               $imagem    =   $produtos[$indice][IMAGEM]; 
               
               //VERIFICA
               if($total == $atual) {
                  echo "</tr><tr>";
                  $atual = 0;
               } ?> 
               
              <td width="14%" height="100"><a href="#" border="0" onClick="MM_openBrWindow('<? echo $imagem; ?>','','width=292,height=465')"><img src="<? echo $thumb; ?>" width="80" height="80" border="0"></a></td>
              <td width="36%">
              
              <table width="95%"  border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
                 <td><font face='Arial' size='2'><? echo $artista; ?></font></td>
              </tr>
              
              <tr>
                 <td><font face='Arial' size='2'><? echo $album; ?></font></td>
              </tr>
              
              <tr>
                 <td><font face='Arial' size='2'>R$ <? echo $preço; ?></font></td>
              </tr>
              
              <tr>
                 <td>
                 <input type="hidden" name="txtprod[<? echo $indice;?>][CODIGO]"  value="<? echo $codigo; ?>">
                 <input type="hidden" name="txtprod[<? echo $indice;?>][ARTISTA]"  value="<? echo $artista; ?>">
                 <input type="hidden" name="txtprod[<? echo $indice;?>][ALBUM]"  value="<? echo $album; ?>">
                 <input type="hidden" name="txtprod[<? echo $indice;?>][preço]"  value="<? echo $preço; ?>">
                 <input type="text" name="txtprod[<? echo $indice;?>][QTDE]"  size="3" maxlength="3">     
                 <input type="image" src="carrinho.gif" onClick="java script: document.forms[0].submit();"></td>
              </tr>
              </table></td>
              <?
              //SOMA 1 A VARIÁVEL CONTROLADORA
              $atual++;
           }//FEHA FOR ?>
           </tr>
           </table>   
        </form></td>
      </tr>
      <tr>
        <td><img src="rodape.gif" width="773" height="20"></td>
      </tr>
    </table>
    </body>
    </html>
    config.php
    <?
    ####################################
    #    Protegendo páginas v. 2.5     #
    #  Script desenvolvido por |paes|  #
    ####################################
    // Endereço do seu servidor MySQL
    $dbhost='localhost';
    
    // Usuário do MySQL
    $dbuser='acapes_frl';
    
    // Senha do MySQL
    $dbpasswd='394596';
    
    // Nome do Banco de dados
    $dbname='acapes_protecao';
    
    ####################################
    #           Não altere               #
    ####################################
    // Conexão com o Banco de Dados
    $conexao = @mysql_connect($dbhost, $dbuser, $dbpasswd) or die ("Não foi possível conectar-se ao servidor MySQL");
    $db = @mysql_select_db($dbname) or die ("Não foi possível selecionar o banco de dados <b>$dbname</b>");
    ?>
    include.php
    <?
    ####################################
    #    Protegendo páginas v. 2.5     #
    #  Script desenvolvido por |paes|  #
    ####################################
    ####################################
    #           Não altere               #
    ####################################
    // Sistema para verificar se é administrador
    include("config.php");
    $sql = "SELECT * FROM config";
    
    $resultado = mysql_query($sql)
    or die ("Não foi possível realizar a consulta ao banco de dados");
    
    if(mysql_num_rows($resultado)>0) {
    
    while ($linha=mysql_fetch_array($resultado)) {
    $adminl = $linha["adminl"];
    $nsite = $linha["nsite"];
    $usite = $linha["usite"];
    $nsite = $linha["nsite"];
    $fonte = $linha["fonte"];
    $tfonte = $linha["tfonte"];
    }}
    ?>

  8. Não, eu quis dizer nesse trecho do código. Onde fecha os parênteses? É porque talvez eu utilize query string...

    B)

    $_SESSION['local'] = isset ($_SERVER['QUERY_STRING'] ? $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'] : $_SERVER['PHP_SELF'];
    Mais uma coisa... Eu posso abrir outra sessão sem fechar essa? Agora vou Dizer o que está acontecendo. Quando eu clico em sair, o redirecionamento utilizando
    session_start(); $_SESSION['local'] = $_SERVER['PHP_SELF'];
    está funcionando. Mas ao efetuar login ele não funciona. Dá uma olhada aí no código pra ver se tu encontra algum problema. cadastro.php
    <?php
    session_start();
    $_SESSION['local'] = $_SERVER['PHP_SELF'];
    include("verifica.php");?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=">
    <title>Untitled Document</title>
    <link rel="stylesheet" href="styles/emx_nav_left.css" type="text/css">
    <script type="text/javascript">
    <!--
    var time = 3000;
    var numofitems = 7;
    
    //menu constructor
    function menu(allitems,thisitem,startstate){ 
      callname= "gl"+thisitem;
      divname="subglobal"+thisitem;  
      this.numberofmenuitems = 7;
      this.caller = document.getElementById(callname);
      this.thediv = document.getElementById(divna
      this.thediv.style.visibility = startstate;
    }
    
    //menu methods
    function ehandler(event,theobj){
      for (var i=1; i<= theobj.numberofmenuitems; i++){
        var shutdiv =eval( "menuitem"+i+".thediv");
        shutdiv.style.visibility="hidden";
      }
      theobj.thediv.style.visibility="visible";
    }
                    
    function closesubnav(event){
      if ((event.clientY <48)||(event.clientY > 107)){
        for (var i=1; i<= numofitems; i++){
          var shutdiv =eval('menuitem'+i+'.thediv');
          shutdiv.style.visibility='hidden';
        }
      }
    }
    // -->
    </script>
    </head>
    <body onmousemove="closesubnav(event);"> 
    <div class="skipLinks">skip to: <a href="#content">page content</a> | <a href="pageNav">links on this page</a> | <a href="#globalNav">site navigation</a> | <a href="#siteInfo">footer (site information)</a> </div>
    <div id="masthead"> 
      <h1 id="siteName">Site Name</h1> 
      <div id="utility"> 
        <a href="#">Utility Link</a> | <a href="#">Utility Link</a> | <a href="#">Utility
        Link</a> 
      </div> 
      <div id="globalNav"> 
        <img alt="" src="images/gblnav_left.gif" height="32" width="4" id="gnl"> <img alt="" src="images/glbnav_right.gif" height="32" width="4" id="gnr"> 
        <div id="globalLink"> 
          <a href="#" id="gl1" class="glink" onmouseover="ehandler(event,menuitem1);">global 
          link</a><a href="#" id="gl2" class="glink" onmouseover="ehandler(event,menuitem2);">global
          link</a><a href="#" id="gl3" class="glink" onmouseover="ehandler(event,menuitem3);">global
          link</a><a href="#" id="gl4" class="glink" onmouseover="ehandler(event,menuitem4);">global
          link</a><a href="#" id="gl5" class="glink" onmouseover="ehandler(event,menuitem5);">global
          link</a><a href="#" id="gl6" class="glink" onmouseover="ehandler(event,menuitem6);">global
          link</a><a href="#" id="gl7" class="glink" onmouseover="ehandler(event,menuitem7);">global
          link</a> 
        </div> 
        <!--end globalLinks-->      
      </div> 
      <!-- end globalNav --> 
      <div id="subglobal1" class="subglobalNav"> 
        <a href="#">subglobal1 link</a> | <a href="#">subglobal1 link</a> | <a href="#">subglobal1
        link</a> | <a href="#">subglobal1 link</a> | <a href="#">subglobal1 link</a> | <a href="#">subglobal1
        link</a> | <a href="#">subglobal1 link</a> 
      </div> 
      <div id="subglobal2" class="subglobalNav"> 
        <a href="#">subglobal2 link</a> | <a href="#">subglobal2 link</a> | <a href="#">subglobal2
        link</a> | <a href="#">subglobal2 link</a> | <a href="#">subglobal2 link</a> | <a href="#">subglobal2
        link</a> | <a href="#">subglobal2 link</a> 
      </div> 
      <div id="subglobal3" class="subglobalNav"> 
        <a href="#">subglobal3 link</a> | <a href="#">subglobal3 link</a> | <a href="#">subglobal3
        link</a> | <a href="#">subglobal3 link</a> | <a href="#">subglobal3 link</a> | <a href="#">subglobal3
        link</a> | <a href="#">subglobal3 link</a> 
      </div> 
      <div id="subglobal4" class="subglobalNav"> 
        <a href="#">subglobal4 link</a> | <a href="#">subglobal4 link</a> | <a href="#">subglobal4
        link</a> | <a href="#">subglobal4 link</a> | <a href="#">subglobal4 link</a> | <a href="#">subglobal4
        link</a> | <a href="#">subglobal4 link</a> 
      </div> 
      <div id="subglobal5" class="subglobalNav"> 
        <a href="#">subglobal5 link</a> | <a href="#">subglobal5 link</a> | <a href="#">subglobal5
        link</a> | <a href="#">subglobal5 link</a> | <a href="#">subglobal5 link</a> | <a href="#">subglobal5
        link</a> | <a href="#">subglobal5 link</a> 
      </div> 
      <div id="subglobal6" class="subglobalNav"> 
        <a href="#">subglobal6 link</a> | <a href="#">subglobal6 link</a> | <a href="#">subglobal6
        link</a> | <a href="#">subglobal6 link</a> | <a href="#">subglobal6 link</a> | <a href="#">subglobal6
        link</a> | <a href="#">subglobal6 link</a> 
      </div> 
      <div id="subglobal7" class="subglobalNav"> 
        <a href="#">subglobal7 link</a> | <a href="#">subglobal7 link</a> | <a href="#">subglobal7
        link</a> | <a href="#">subglobal7 link</a> | <a href="#">subglobal7 link</a> | <a href="#">subglobal7
        link</a> | <a href="#">subglobal7 link</a> 
      </div> 
      <div id="subglobal8" class="subglobalNav"> 
        <a href="#">subglobal8 link</a> | <a href="#">subglobal8 link</a> | <a href="#">subglobal8
        link</a> | <a href="#">subglobal8 link</a> | <a href="#">subglobal8 link</a> | <a href="#">subglobal8
        link</a> | <a href="#">subglobal8 link</a> 
      </div> 
    </div> 
    <!-- end masthead --> 
    <div id="pagecell1"> 
      <!--pagecell1--> 
      <img alt="" src="images/tl_curve_white.gif" height="6" width="6" id="tl"> <img alt="" src="images/tr_curve_white.gif" height="6" width="6" id="tr"> 
      <div id="breadCrumb"> 
        <?php include ('bemvindo.php'); ?>
      </div> 
      <div id="pageName"> 
        <h2>Page Name</h2> 
        <img alt="small logo" src="" height="59" width="66"/> 
      </div> 
      <div id="pageNav"> 
        <div id="sectionLinks"> 
          <a href="#">Section Link</a> <a href="#">Section Link</a> <a href="#">Section
          Link</a> <a href="#">Section Link</a> <a href="#">Section Link</a> <a href="#">Section
          Link</a> 
        </div> 
        <div class="relatedLinks"> 
          <h3>Related Link Category</h3> 
          <a href="#">Related Link</a> <a href="#">Related Link</a> <a href="#">Related
          Link</a> <a href="#">Related Link</a> <a href="#">Related Link</a> <a href="#">Related
          Link</a> 
        </div> 
        <div class="relatedLinks"> 
          <h3>Related Link Category</h3> 
          <a href="#">Related Link</a> <a href="#">Related Link</a> <a href="#">Related
          Link</a> <a href="#">Related Link</a> <a href="#">Related Link</a> <a href="#">Related
          Link</a> 
        </div> 
        <div id="advert"> 
          <img src="" alt="" width="107" height="66" /> Advertisement copy goes here.
          Advertisement copy goes here.
        </div> 
      </div> 
      <div id="content"> 
        <div class="feature"> 
          <?php include ('cadastrar.php'); ?>
        </div> 
        <div class="story"> 
          
        </div> 
        <div class="story"> 
          
        </div> 
      </div> 
       <div id="siteInfo"> 
        <img src="" width="44" height="22"> <a href="#">About Us</a> | <a href="#">Site
        Map</a> | <a href="#">Privacy Policy</a> | <a href="#">Contact Us</a> | &copy;2003
        Company Name
      </div> 
    </div> 
    <!--end pagecell1--> 
    <br> 
    <script type="text/javascript">
        <!--
          var menuitem1 = new menu(7,1,"hidden");
                var menuitem2 = new menu(7,2,"hidden");
                var menuitem3 = new menu(7,3,"hidden");
                var menuitem4 = new menu(7,4,"hidden");
                var menuitem5 = new menu(7,5,"hidden");
                var menuitem6 = new menu(7,6,"hidden");
                var menuitem7 = new menu(7,7,"hidden");
        // -->
        </script> 
    </body>
    </html>
    
    verifica.php
    <?
    ####################################
    #    Protegendo páginas v. 2.5     #
    #  Script desenvolvido por |paes|  #
    ####################################
    ####################################
    #           Não altere               #
    ####################################
    // Sistema para verificar se o usuário já está logado ou não
    
    if($acao == sair){
    setcookie("usuario");
    setcookie("senha");
    header("Location: ".$_SESSION['local']);
    }
    ?>
    login.php
    <?php
    ####################################
    #    Protegendo páginas v. 2.5     #
    #  Script desenvolvido por |paes|  #
    ####################################
    include("config.php");
    include("include.php");
    
    
    $query = mysql_query("Select * From users where login='$login_' and senha='$senha_'");
    $valida = mysql_fetch_array($query);
    
    $user = $valida["login"];
    $pass = $valida["senha"];
    
    if($login_ == '' || $senha_ == ''){
    echo"
    <HTML>
    <title>$nsite</title>
    <form action=\"login.php\" method=\"post\">
    <table align=\"center\" width=\"90%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
    <tr><td height=\"25\">Bem vindo <b>visitante</b>!&nbsp;&nbsp;<a href=\"cadastro.php\" target=\"_parent\">Cadastre-se</a> ou efetue login ao lado:</td>
    <td height=\"25\">CPF/CNPJ:</td><td><input name=\"login_\" type=\"text\"></td>
    <td height=\"25\">Repita CPF/CNPJ:</td><td><input name=\"senha_\" type=\"password\"></td>
    <td height=\"25\">&nbsp;</td><td><input name=\"logar\" type=\"submit\" value=\"Logar\"></td></tr>
    </table>
    </form>
    </HTML>";
    } elseif($login_ == $user && $senha_ == $pass){
    setcookie("usuario", $login_);
    setcookie("senha", $senha_);
    header("Location: ".$_SESSION['local']);
    } elseif($login_ != $valida["login"] || $senha_ != $valida["senha"]){
    echo "<font face=\"$fonte\" size=\"$tfonte\">Usuário ou senha inválido.<br><a href=mailto:$admine>Contate o administrador</a> se você tem certeza de que os dados estão corretos.<br><br>
    <a href=login.php>«« Voltar</a></font>";
    }
    ?>
    bemvindo.php
    <?
    include("config.php");
    include("include.php");
    
    if(!$HTTP_COOKIE_VARS["usuario"] && !$HTTP_COOKIE_VARS["senha"]){
    include("login.php");
    }else{
    echo"
    <font face=$fonte size=$tfonte>
    Bem vindo <b>$usuario</b>!&nbsp;&nbsp;&nbsp;<a href=?acao=sair>Sair</a>";
    }
    ?>

  9. Sobre sessões: Sessões

    Sobre variáveis de ambiente: Variáveis do tipo $_SERVER

    Exemplo:

    session_start();
    $_SESSION['local'] = $_SERVER['PHP_SELF'];
    
    Se você estiver usando query strings, terá de fazer assim:
    $_SESSION['local'] = isset ($_SERVER['QUERY_STRING'] ? $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'] : $_SERVER['PHP_SELF']; 
    

    Beraldo

    E como isso ficaria no header? assim?

    header("Location: $_SESSION['local']");

    porque eu tentei fazer isso e não consegui!

    Mais uma coisa: Onde que fecha os parênteses do isset se estiver usando query string?

  10. Bem... vou colocar os códigos que sofreram modificações aqui!

    cadastro.php

    <?php include ('verifica.php');?>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=">
    <title>Untitled Document</title>
    <link rel="stylesheet" href="styles/emx_nav_left.css" type="text/css">
    <script type="text/javascript">
    <!--
    var time = 3000;
    var numofitems = 7;
    
    //menu constructor
    function menu(allitems,thisitem,startstate){ 
      callname= "gl"+thisitem;
      divname="subglobal"+thisitem;  
      this.numberofmenuitems = 7;
      this.caller = document.getElementById(callname);
      this.thediv = document.getElementById(divname);
      this.thediv.style.visibility = startstate;
    }
    
    //menu methods
    function ehandler(event,theobj){
      for (var i=1; i<= theobj.numberofmenuitems; i++){
        var shutdiv =eval( "menuitem"+i+".thediv");
        shutdiv.style.visibility="hidden";
      }
      theobj.thediv.style.visibility="visible";
    }
                    
    function closesubnav(event){
      if ((event.clientY <48)||(event.clientY > 107)){
        for (var i=1; i<= numofitems; i++){
          var shutdiv =eval('menuitem'+i+'.thediv');
          shutdiv.style.visibility='hidden';
        }
      }
    }
    // -->
    </script>
    </head>
    <body onmousemove="closesubnav(event);"> 
    <div class="skipLinks">skip to: <a href="#content">page content</a> | <a href="pageNav">links on this page</a> | <a href="#globalNav">site navigation</a> | <a href="#siteInfo">footer (site information)</a> </div>
    <div id="masthead"> 
      <h1 id="siteName">Site Name</h1> 
      <div id="utility"> 
        <a href="#">Utility Link</a> | <a href="#">Utility Link</a> | <a href="#">Utility
        Link</a> 
      </div> 
      <div id="globalNav"> 
        <img alt="" src="images/gblnav_left.gif" height="32" width="4" id="gnl"> <img alt="" src="images/glbnav_right.gif" height="32" width="4" id="gnr"> 
        <div id="globalLink"> 
          <a href="#" id="gl1" class="glink" onmouseover="ehandler(event,menuitem1);">global 
          link</a><a href="#" id="gl2" class="glink" onmouseover="ehandler(event,menuitem2);">global
          link</a><a href="#" id="gl3" class="glink" onmouseover="ehandler(event,menuitem3);">global
          link</a><a href="#" id="gl4" class="glink" onmouseover="ehandler(event,menuitem4);">global
          link</a><a href="#" id="gl5" class="glink" onmouseover="ehandler(event,menuitem5);">global
          link</a><a href="#" id="gl6" class="glink" onmouseover="ehandler(event,menuitem6);">global
          link</a><a href="#" id="gl7" class="glink" onmouseover="ehandler(event,menuitem7);">global
          link</a> 
        </div> 
        <!--end globalLinks-->      
      </div> 
      <!-- end globalNav --> 
      <div id="subglobal1" class="subglobalNav"> 
        <a href="#">subglobal1 link</a> | <a href="#">subglobal1 link</a> | <a href="#">subglobal1
        link</a> | <a href="#">subglobal1 link</a> | <a href="#">subglobal1 link</a> | <a href="#">subglobal1
        link</a> | <a href="#">subglobal1 link</a> 
      </div> 
      <div id="subglobal2" class="subglobalNav"> 
        <a href="#">subglobal2 link</a> | <a href="#">subglobal2 link</a> | <a href="#">subglobal2
        link</a> | <a href="#">subglobal2 link</a> | <a href="#">subglobal2 link</a> | <a href="#">subglobal2
        link</a> | <a href="#">subglobal2 link</a> 
      </div> 
      <div id="subglobal3" class="subglobalNav"> 
        <a href="#">subglobal3 link</a> | <a href="#">subglobal3 link</a> | <a href="#">subglobal3
        link</a> | <a href="#">subglobal3 link</a> | <a href="#">subglobal3 link</a> | <a href="#">subglobal3
        link</a> | <a href="#">subglobal3 link</a> 
      </div> 
      <div id="subglobal4" class="subglobalNav"> 
        <a href="#">subglobal4 link</a> | <a href="#">subglobal4 link</a> | <a href="#">subglobal4
        link</a> | <a href="#">subglobal4 link</a> | <a href="#">subglobal4 link</a> | <a href="#">subglobal4
        link</a> | <a href="#">subglobal4 link</a> 
      </div> 
      <div id="subglobal5" class="subglobalNav"> 
        <a href="#">subglobal5 link</a> | <a href="#">subglobal5 link</a> | <a href="#">subglobal5
        link</a> | <a href="#">subglobal5 link</a> | <a href="#">subglobal5 link</a> | <a href="#">subglobal5
        link</a> | <a href="#">subglobal5 link</a> 
      </div> 
      <div id="subglobal6" class="subglobalNav"> 
        <a href="#">subglobal6 link</a> | <a href="#">subglobal6 link</a> | <a href="#">subglobal6
        link</a> | <a href="#">subglobal6 link</a> | <a href="#">subglobal6 link</a> | <a href="#">subglobal6
        link</a> | <a href="#">subglobal6 link</a> 
      </div> 
      <div id="subglobal7" class="subglobalNav"> 
        <a href="#">subglobal7 link</a> | <a href="#">subglobal7 link</a> | <a href="#">subglobal7
        link</a> | <a href="#">subglobal7 link</a> | <a href="#">subglobal7 link</a> | <a href="#">subglobal7
        link</a> | <a href="#">subglobal7 link</a> 
      </div> 
      <div id="subglobal8" class="subglobalNav"> 
        <a href="#">subglobal8 link</a> | <a href="#">subglobal8 link</a> | <a href="#">subglobal8
        link</a> | <a href="#">subglobal8 link</a> | <a href="#">subglobal8 link</a> | <a href="#">subglobal8
        link</a> | <a href="#">subglobal8 link</a> 
      </div> 
    </div> 
    <!-- end masthead --> 
    <div id="pagecell1"> 
      <!--pagecell1--> 
      <img alt="" src="images/tl_curve_white.gif" height="6" width="6" id="tl"> <img alt="" src="images/tr_curve_white.gif" height="6" width="6" id="tr"> 
      <div id="breadCrumb"> 
        <?php include ('bemvindo.php'); ?>
      </div> 
      <div id="pageName"> 
        <h2>Page Name</h2> 
        <img alt="small logo" src="" height="59" width="66"/> 
      </div> 
      <div id="pageNav"> 
        <div id="sectionLinks"> 
          <a href="#">Section Link</a> <a href="#">Section Link</a> <a href="#">Section
          Link</a> <a href="#">Section Link</a> <a href="#">Section Link</a> <a href="#">Section
          Link</a> 
        </div> 
        <div class="relatedLinks"> 
          <h3>Related Link Category</h3> 
          <a href="#">Related Link</a> <a href="#">Related Link</a> <a href="#">Related
          Link</a> <a href="#">Related Link</a> <a href="#">Related Link</a> <a href="#">Related
          Link</a> 
        </div> 
        <div class="relatedLinks"> 
          <h3>Related Link Category</h3> 
          <a href="#">Related Link</a> <a href="#">Related Link</a> <a href="#">Related
          Link</a> <a href="#">Related Link</a> <a href="#">Related Link</a> <a href="#">Related
          Link</a> 
        </div> 
        <div id="advert"> 
          <img src="" alt="" width="107" height="66" /> Advertisement copy goes here.
          Advertisement copy goes here.
        </div> 
      </div> 
      <div id="content"> 
        <div class="feature"> 
          <?php include ('cadastrar.php'); ?>
        </div> 
        <div class="story"> 
          
        </div> 
        <div class="story"> 
          
        </div> 
      </div> 
       <div id="siteInfo"> 
        <img src="" width="44" height="22"> <a href="#">About Us</a> | <a href="#">Site
        Map</a> | <a href="#">Privacy Policy</a> | <a href="#">Contact Us</a> | &copy;2003
        Company Name
      </div> 
    </div> 
    <!--end pagecell1--> 
    <br> 
    <script type="text/javascript">
        <!--
          var menuitem1 = new menu(7,1,"hidden");
                var menuitem2 = new menu(7,2,"hidden");
                var menuitem3 = new menu(7,3,"hidden");
                var menuitem4 = new menu(7,4,"hidden");
                var menuitem5 = new menu(7,5,"hidden");
                var menuitem6 = new menu(7,6,"hidden");
                var menuitem7 = new menu(7,7,"hidden");
        // -->
        </script> 
    </body>
    </html>
    
    verifica.php
    <?
    ####################################
    #    Protegendo páginas v. 2.5     #
    #  Script desenvolvido por |paes|  #
    ####################################
    ####################################
    #           Não altere               #
    ####################################
    if($acao == sair){
    setcookie("usuario");
    setcookie("senha");
    header("location: cadastro.php");
    }
    ?>
    bemvindo.php
    <?
    include("config.php");
    include("include.php");
    
    if(!$HTTP_COOKIE_VARS["usuario"] && !$HTTP_COOKIE_VARS["senha"]){
    include("login.php");
    }else{
    echo"
    <font face=$fonte size=$tfonte>
    Bem vindo <b>$usuario</b>!&nbsp;&nbsp;&nbsp;<a href=?acao=sair>Sair</a>";
    }
    ?>
    login.php
    <?
    ####################################
    #    Protegendo páginas v. 2.5     #
    #  Script desenvolvido por |paes|  #
    ####################################
    include("config.php");
    include("include.php");
    
    
    $query = mysql_query("Select * From users where login='$login_' and senha='$senha_'");
    $valida = mysql_fetch_array($query);
    
    $user = $valida["login"];
    $pass = $valida["senha"];
    
    if($login_ == '' || $senha_ == ''){
    echo"
    <HTML>
    <title>$nsite</title>
    <font face=\"$fonte\" size=\"$tfonte\">
    <form action=\"login.php\" method=\"post\">
    <table align=\"center\" width=\"90%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
    <tr><td height=\"25\"><font face=$fonte size=$tfonte>Bem vindo <b>visitante</b>!</td>
    <td height=\"25\"><font face=\"$fonte\" size=\"$tfonte\">CPF/CNPJ:</font></td><td><input name=\"login_\" type=\"text\"></td>
    <td height=\"25\"><font face=\"$fonte\" size=\"$tfonte\">Repita CPF/CNPJ:</font></td><td><input name=\"senha_\" type=\"password\"></td>
    <td height=\"25\">&nbsp;</td><td><input name=\"logar\" type=\"submit\" value=\"Logar\"></td></tr>
    </table>
    </form>
    </HTML>";
    } elseif($login_ == $user && $senha_ == $pass){
    setcookie("usuario", $login_);
    setcookie("senha", $senha_);
    header("Location: cadastro.php");
    } elseif($login_ != $valida["login"] || $senha_ != $valida["senha"]){
    echo "<font face=\"$fonte\" size=\"$tfonte\">Usuário ou senha inválido.<br><a href=mailto:$admine>Contate o administrador</a> se você tem certeza de que os dados estão corretos.<br><br>
    <a href=login.php>«« Voltar</a></font>";
    }
    ?>

    Bem, esses foram os códigos que tiveram mudanças.

    Aparentemente está tudo perfeito, mas agora vem o grande desafio...

    Vocês podem ver que sempre depois do login/logoff o header é direcionado para a página cadastro.php. Mas como eu havia citado anteriormente, eu quero que seja possível efetuar o login em qualquer página do site, então não ficaria legal fazer login na pagina1.php e parar na pagina2.php.

    Alguém sabe como poderei capturar a página anterior ao login/logoff, e armazenar em uma variável global que poderia ser utilizada no header tanto em login.php quanto em verifica.php?!

    Vou colocar aqui o link de onde está hospedado temporariamente todo esse sistema acima. Assim dá pra ver como que tá funcionando +-.

    http://www.acap-es.org.br/lorentino/cadastro.php

    usem o cpf 45761613506 para teste

    EDITANDO:

    Bem galera... achei esse tópico aqui que fala sobre o assunto do que estou precisando.

    http://scriptbrasil.com.br/forum/index.php...pturar+anterior

    Mas não consegui botar em prática o que foi dito pelo beraldo.

    Usando header("Location: $_SERVER[HTTP_REFERER]"); até que funcionou direitinho, mas como foi citado que ele não é confiável, prefiro usar o que foi explicado pelo beraldo!

    Tem como alguém editar o código aí pra mim?!

  11. Se eu fosse usar javascript para redirecionamento, você sabe como usar uma variável do PHP em JavaScript?

    Será que um simples comando de "Refresh de página" não resolveria o meu problema?

    Gutto, não deu pra postar o script modificado?!

    EDIT

    Caramba... to quase conseguindo!

    Só falta saber uma função que pega o nome da página atual para usar no header, porque isso que o ikkinet disse eu não consegui fazer.

    Alguém aí sabe como pegar o nome da página atual?

    quando eu estiver com tempo eu coloco o código com minhas modificações!

  12. Poisé cara... o lance do erro do header eu ví em outro post para usar uma função em javascript que faça redirecionamento.

    Mas agora eu estava pensando no seguinte.

    o header("location: cadastro.php"); (ou qualquer outra função que faça redirecionamento) vai redirecionar a pessoa exclusivamente para cadastro.php. Eu queria saber se existe alguma maneira de que essa pessoa fosse redirecionada para a página que ele estava antes de fazer o login.

    Pois eu quero permitir que ela faça o login em qualquer parte do site e seria estranho ela efetuar o login em pagina1.php e ser transferida para pagina2.php após login.

    Será que tem como?

    Vou esperar as modificações no script. Quando eu chegar em casa eu vejo como ficou, pois agora to trabalhando.

    Valeu []'s

  13. Continuando com os problemas nesse código.

    Agora o problema é o seguinte. Estou fazendo uma página com um conteúdo qualquer e também terá um cabeçalho com uma mensagem de boas vindas.

    Se o usuário não estiver logado a mensagem será "Bem vindo Visitante" e ao lado terá os campos para ele fazer login. Se o usuário já estiver logado, deverá aparecer a mensagem "Bem Vindo nomedousuario" e ao lado um link para ele efetuar logoff.

    Agora vamos aos problemas.

    Quando o usuário não está logado, está aparecendo o seguinte:

    Warning: Cannot modify header information - headers already sent by (output started at /home/acapes/public_html/lorentino/cadastro.php:9) in /home/acapes/public_html/lorentino/verifica.php on line 11

    Bem vindo visitante! CPF/CNPJ: Repita CPF/CNPJ: [LOGAR]

    Apesar de aparecer esse Warning, o login é feito normalmente. Aparece "Bem vindo nomedousuário" e o link para ele efetuar logoff. Mas quando clico no link para ele efetuar o logoff ele carrega a página novamente mas não efetua o logoff.

    Vamos ao códigos. Primeiro da página com o conteúdo qualquer, e logo abaixo o restante:

    "cadastro.php"

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=">
    <title>Untitled Document</title>
    <link rel="stylesheet" href="styles/emx_nav_left.css" type="text/css">
    <script type="text/javascript">
    <!--
    var time = 3000;
    var numofitems = 7;
    
    //menu constructor
    function menu(allitems,thisitem,startstate){ 
      callname= "gl"+thisitem;
      divname="subglobal"+thisitem;  
      this.numberofmenuitems = 7;
      this.caller = document.getElementById(callname);
      this.thediv = document.getElementById(divname);
      this.thediv.style.visibility = startstate;
    }
    
    //menu methods
    function ehandler(event,theobj){
      for (var i=1; i<= theobj.numberofmenuitems; i++){
        var shutdiv =eval( "menuitem"+i+".thediv");
        shutdiv.style.visibility="hidden";
      }
      theobj.thediv.style.visibility="visible";
    }
                    
    function closesubnav(event){
      if ((event.clientY <48)||(event.clientY > 107)){
        for (var i=1; i<= numofitems; i++){
          var shutdiv =eval('menuitem'+i+'.thediv');
          shutdiv.style.visibility='hidden';
        }
      }
    }
    // -->
    </script>
    </head>
    <body onmousemove="closesubnav(event);"> 
    <div class="skipLinks">skip to: <a href="#content">page content</a> | <a href="pageNav">links on this page</a> | <a href="#globalNav">site navigation</a> | <a href="#siteInfo">footer (site information)</a> </div>
    <div id="masthead"> 
      <h1 id="siteName">Site Name</h1> 
      <div id="utility"> 
        <a href="#">Utility Link</a> | <a href="#">Utility Link</a> | <a href="#">Utility
        Link</a> 
      </div> 
      <div id="globalNav"> 
        <img alt="" src="images/gblnav_left.gif" height="32" width="4" id="gnl"> <img alt="" src="images/glbnav_right.gif" height="32" width="4" id="gnr"> 
        <div id="globalLink"> 
          <a href="#" id="gl1" class="glink" onmouseover="ehandler(event,menuitem1);">global 
          link</a><a href="#" id="gl2" class="glink" onmouseover="ehandler(event,menuitem2);">global
          link</a><a href="#" id="gl3" class="glink" onmouseover="ehandler(event,menuitem3);">global
          link</a><a href="#" id="gl4" class="glink" onmouseover="ehandler(event,menuitem4);">global
          link</a><a href="#" id="gl5" class="glink" onmouseover="ehandler(event,menuitem5);">global
          link</a><a href="#" id="gl6" class="glink" onmouseover="ehandler(event,menuitem6);">global
          link</a><a href="#" id="gl7" class="glink" onmouseover="ehandler(event,menuitem7);">global
          link</a> 
        </div> 
        <!--end globalLinks-->      
      </div> 
      <!-- end globalNav --> 
      <div id="subglobal1" class="subglobalNav"> 
        <a href="#">subglobal1 link</a> | <a href="#">subglobal1 link</a> | <a href="#">subglobal1
        link</a> | <a href="#">subglobal1 link</a> | <a href="#">subglobal1 link</a> | <a href="#">subglobal1
        link</a> | <a href="#">subglobal1 link</a> 
      </div> 
      <div id="subglobal2" class="subglobalNav"> 
        <a href="#">subglobal2 link</a> | <a href="#">subglobal2 link</a> | <a href="#">subglobal2
        link</a> | <a href="#">subglobal2 link</a> | <a href="#">subglobal2 link</a> | <a href="#">subglobal2
        link</a> | <a href="#">subglobal2 link</a> 
      </div> 
      <div id="subglobal3" class="subglobalNav"> 
        <a href="#">subglobal3 link</a> | <a href="#">subglobal3 link</a> | <a href="#">subglobal3
        link</a> | <a href="#">subglobal3 link</a> | <a href="#">subglobal3 link</a> | <a href="#">subglobal3
        link</a> | <a href="#">subglobal3 link</a> 
      </div> 
      <div id="subglobal4" class="subglobalNav"> 
        <a href="#">subglobal4 link</a> | <a href="#">subglobal4 link</a> | <a href="#">subglobal4
        link</a> | <a href="#">subglobal4 link</a> | <a href="#">subglobal4 link</a> | <a href="#">subglobal4
        link</a> | <a href="#">subglobal4 link</a> 
      </div> 
      <div id="subglobal5" class="subglobalNav"> 
        <a href="#">subglobal5 link</a> | <a href="#">subglobal5 link</a> | <a href="#">subglobal5
        link</a> | <a href="#">subglobal5 link</a> | <a href="#">subglobal5 link</a> | <a href="#">subglobal5
        link</a> | <a href="#">subglobal5 link</a> 
      </div> 
      <div id="subglobal6" class="subglobalNav"> 
        <a href="#">subglobal6 link</a> | <a href="#">subglobal6 link</a> | <a href="#">subglobal6
        link</a> | <a href="#">subglobal6 link</a> | <a href="#">subglobal6 link</a> | <a href="#">subglobal6
        link</a> | <a href="#">subglobal6 link</a> 
      </div> 
      <div id="subglobal7" class="subglobalNav"> 
        <a href="#">subglobal7 link</a> | <a href="#">subglobal7 link</a> | <a href="#">subglobal7
        link</a> | <a href="#">subglobal7 link</a> | <a href="#">subglobal7 link</a> | <a href="#">subglobal7
        link</a> | <a href="#">subglobal7 link</a> 
      </div> 
      <div id="subglobal8" class="subglobalNav"> 
        <a href="#">subglobal8 link</a> | <a href="#">subglobal8 link</a> | <a href="#">subglobal8
        link</a> | <a href="#">subglobal8 link</a> | <a href="#">subglobal8 link</a> | <a href="#">subglobal8
        link</a> | <a href="#">subglobal8 link</a> 
      </div> 
    </div> 
    <!-- end masthead --> 
    <div id="pagecell1"> 
      <!--pagecell1--> 
      <img alt="" src="images/tl_curve_white.gif" height="6" width="6" id="tl"> <img alt="" src="images/tr_curve_white.gif" height="6" width="6" id="tr"> 
      <div id="breadCrumb"> 
        <?php include ('bemvindo.php'); ?>
      </div> 
      <div id="pageName"> 
        <h2>Page Name</h2> 
        <img alt="small logo" src="" height="59" width="66"/> 
      </div> 
      <div id="pageNav"> 
        <div id="sectionLinks"> 
          <a href="#">Section Link</a> <a href="#">Section Link</a> <a href="#">Section
          Link</a> <a href="#">Section Link</a> <a href="#">Section Link</a> <a href="#">Section
          Link</a> 
        </div> 
        <div class="relatedLinks"> 
          <h3>Related Link Category</h3> 
          <a href="#">Related Link</a> <a href="#">Related Link</a> <a href="#">Related
          Link</a> <a href="#">Related Link</a> <a href="#">Related Link</a> <a href="#">Related
          Link</a> 
        </div> 
        <div class="relatedLinks"> 
          <h3>Related Link Category</h3> 
          <a href="#">Related Link</a> <a href="#">Related Link</a> <a href="#">Related
          Link</a> <a href="#">Related Link</a> <a href="#">Related Link</a> <a href="#">Related
          Link</a> 
        </div> 
        <div id="advert"> 
          <img src="" alt="" width="107" height="66" /> Advertisement copy goes here.
          Advertisement copy goes here.
        </div> 
      </div> 
      <div id="content"> 
        <div class="feature"> 
          <?php include ('cadastrar.php'); ?>
        </div> 
        <div class="story"> 
          
        </div> 
        <div class="story"> 
          
        </div> 
      </div> 
       <div id="siteInfo"> 
        <img src="" width="44" height="22"> <a href="#">About Us</a> | <a href="#">Site
        Map</a> | <a href="#">Privacy Policy</a> | <a href="#">Contact Us</a> | &copy;2003
        Company Name
      </div> 
    </div> 
    <!--end pagecell1--> 
    <br> 
    <script type="text/javascript">
        <!--
          var menuitem1 = new menu(7,1,"hidden");
                var menuitem2 = new menu(7,2,"hidden");
                var menuitem3 = new menu(7,3,"hidden");
                var menuitem4 = new menu(7,4,"hidden");
                var menuitem5 = new menu(7,5,"hidden");
                var menuitem6 = new menu(7,6,"hidden");
                var menuitem7 = new menu(7,7,"hidden");
        // -->
        </script> 
    </body>
    </html>
    
    "bemvindo.php"
    <?
    include("config.php");
    include("include.php");
    
    
    if(!$HTTP_COOKIE_VARS["usuario"] && !$HTTP_COOKIE_VARS["senha"]){
    include("login.php");
    }else{
    echo"
    <font face=$fonte size=$tfonte>
    Bem vindo <b>$usuario</b>!&nbsp;&nbsp;&nbsp;<a href=?acao=sair>Sair</a>";
    }
    
    ?>
    "login.php"
    <?
    ####################################
    #    Protegendo páginas v. 2.5     #
    #  Script desenvolvido por |paes|  #
    ####################################
    include("config.php");
    include("include.php");
    include("verifica.php");
    
    $query = mysql_query("Select * From users where login='$login_' and senha='$senha_'");
    $valida = mysql_fetch_array($query);
    
    $user = $valida["login"];
    $pass = $valida["senha"];
    
    if($login_ == '' || $senha_ == ''){
    echo"
    <HTML>
    <title>$nsite</title>
    <font face=\"$fonte\" size=\"$tfonte\">
    <form action=\"login.php\" method=\"post\">
    <table align=\"left\" width=\"90%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
    <tr><td height=\"25\"><font face=$fonte size=$tfonte>Bem vindo <b>visitante</b>!</td>
    <td height=\"25\"><font face=\"$fonte\" size=\"$tfonte\">CPF/CNPJ:</font></td><td><input name=\"login_\" type=\" text\"></td>
    <td height=\"25\"><font face=\"$fonte\" size=\"$tfonte\">Repita CPF/CNPJ:</font></td><td><input name=\"senha_\" type=\"password\"></td>
    <td height=\"25\">&nbsp;</td><td><input name=\"logar\" type=\"submit\" value=\"Logar\"></td></tr>
    </table>
    </form>
    </HTML>";
    } elseif($login_ == $user && $senha_ == $pass){
    setcookie("usuario", $login_);
    setcookie("senha", $senha_);
    //header("Location: cadastro.php");
    } elseif($login_ != $valida["login"] || $senha_ != $valida["senha"]){
    echo "<font face=\"$fonte\" size=\"$tfonte\">Usuário ou senha inválido.<br><a href=mailto:$admine>Contate o administrador</a> se você tem certeza de que os dados estão corretos.<br><br>
    <a href=login.php>«« Voltar</a></font>";
    }
    ?>
    
    "cadastrar.php"
    <?
    ####################################
    #    Protegendo páginas v. 2.5     #
    #  Script desenvolvido por |paes|  #
    ####################################
    include("config.php");
    
      if($acao == 'cadastra'){
    $sql = "SELECT * FROM users where login='$CampoNumero'";
    
    $resultado = mysql_query($sql)
    or die ("Não foi possível realizar a consulta ao banco de dados");
    
    if(mysql_num_rows($resultado)>0) {
    
    while ($linha=mysql_fetch_array($resultado)) {
    $CampoNumero = $linha["loginc"];
    }
    }
        if($CampoNumero == $loginc){
    echo"<script>alert('Este CPF/CNPJ já está cadastrado. Entre com outro CPF/CNPJ');
    history.back(-1);</script>";
    }else{
        if (${"chkCPF"}=="on"){
            CalculaCPF($CampoNumero);
        }else{
            CalculaCNPJ($CampoNumero);
        }
    }
    } else {
    echo"
    <HTML>
    <head>
    <title>$nsite</title>
    </head>
    <font face=\"$fonte\" size=\"$tfonte\">
    <form action=\"cadastrar.php?acao=cadastra\" method=\"post\" onSubmit=\"MM_validateForm('nome','','R','email','','NisEmail','ddd','','RisNum','telefone','','RisNum','endereco','','R','cep','','RisNum','cidade','','R','estado','','R','CampoNumero','','RisNum');return document.MM_returnValue\">
    <table width=\"100%\" align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
    <tr><td class=\"texto\"><font face=\"$fonte\" size=\"$tfonte\">Nome:&nbsp;</font></td><td><input class=\"campo\" name=\"nome\" type=\"text\" size=\"30\" maxlength=\"255\"></td></tr>
    <tr><td class=\"texto\"><font face=\"$fonte\" size=\"$tfonte\">E-mail:&nbsp;</font></td><td><input class=\"campo\" name=\"email\" type=\"text\" size=\"30\" maxlength=\"100\"></td></tr>
    <tr><td class=\"texto\"><font face=\"$fonte\" size=\"$tfonte\">DDD(xx) - Telefone(somente números):&nbsp;</font></td><td><input class=\"campo\" name=\"ddd\" type=\"text\" size=\"2\" maxlength=\"2\"><font face=\"$fonte\" size=\"$tfonte\">&nbsp;-&nbsp;</font><input class=\"campo\" name=\"telefone\" type=\"text\" size=\"15\" maxlength=\"8\"></td></tr>
    <tr><td class=\"texto\"><font face=\"$fonte\" size=\"$tfonte\">Endereço:&nbsp;</font></td><td><input class=\"campo\" name=\"endereco\" type=\"text\" size=\"30\"></td></tr>
    <tr><td class=\"texto\"><font face=\"$fonte\" size=\"$tfonte\">CEP (Somente números):&nbsp;</font></td><td><input class=\"campo\" name=\"cep\" type=\"text\" size=\"15\" maxlength=\"8\"></td></tr>
    <tr><td class=\"texto\"><font face=\"$fonte\" size=\"$tfonte\">Cidade:&nbsp;</font></td><td><input class=\"campo\" name=\"cidade\" type=\"text\" size=\"30\"></td></tr>
    <tr><td class=\"texto\"><font face=\"$fonte\" size=\"$tfonte\">Estado:&nbsp;</font></td><td><input class=\"campo\" name=\"estado\" type=\"text\" size=\"30\"></td></tr>
    <tr><td class=\"texto\"><font face=\"$fonte\" size=\"$tfonte\"><input type=\"radio\" name=\"chkCPF\" value=\"on\" checked>CPF (pessoa física) ou</font></td></tr>
    <tr><td class=\"texto\"><font face=\"$fonte\" size=\"$tfonte\"><input type=\"radio\" name=\"chkCPF\" value=\"off\">CNPJ (pessoa jurídica)</font></td></tr>
    <tr><td class=\"texto\"><font face=\"$fonte\" size=\"$tfonte\">N&uacute;mero (CPF/CNPJ):</font></td><td><input class=\"campo\" type=\"text\" name=\"CampoNumero\" size=\"18\" maxlength=\"14\"></td></tr>
    <tr><td class=\"texto\"></td><td><input class=\"campo\" name=\"cadastrar\" type=\"submit\" value=\"Cadastrar\"></td></tr>
    <tr><td class=\"texto\"></td><td><font face=\"$fonte\" size=\"$tfonte\"><a href=java script:history.go(-1)>«« Voltar</a></font></td></tr>
    </table>
    </HTML>
    ";
    }
    
      //Calcula CPF
    
      function CalculaCPF($CampoNumero)
      {
       $RecebeCPF=$CampoNumero;
       //Retirar todos os caracteres que não sejam 0-9
       $s="";
       for ($x=1; $x<=strlen($RecebeCPF); $x=$x+1)
       {
        $ch=substr($RecebeCPF,$x-1,1);
        if (ord($ch)>=48 && ord($ch)<=57)
        {
          $s=$s.$ch;
        }
       }
       
       $RecebeCPF=$s;
       if (strlen($RecebeCPF)!=11)
       {
        echo "<script>alert('CPF deve conter 11 dígitos.');
    history.back(-1);</script>";
       }
       else
         if ($RecebeCPF=="00000000000")
         {
           $then;
           echo "<script>alert('CPF Inválido. Entre com um CPF Válido');
    history.back(-1);</script>";
         }
         else
         {
          $Numero[1]=intval(substr($RecebeCPF,1-1,1));
          $Numero[2]=intval(substr($RecebeCPF,2-1,1));
          $Numero[3]=intval(substr($RecebeCPF,3-1,1));
          $Numero[4]=intval(substr($RecebeCPF,4-1,1));
          $Numero[5]=intval(substr($RecebeCPF,5-1,1));
          $Numero[6]=intval(substr($RecebeCPF,6-1,1));
          $Numero[7]=intval(substr($RecebeCPF,7-1,1));
          $Numero[8]=intval(substr($RecebeCPF,8-1,1));
          $Numero[9]=intval(substr($RecebeCPF,9-1,1));
          $Numero[10]=intval(substr($RecebeCPF,10-1,1));
          $Numero[11]=intval(substr($RecebeCPF,11-1,1));
    
         $soma=10*$Numero[1]+9*$Numero[2]+8*$Numero[3]+7*$Numero[4]+6*$Numero[5]+5*
         $Numero[6]+4*$Numero[7]+3*$Numero[8]+2*$Numero[9];
         $soma=$soma-(11*(intval($soma/11)));
    
        if ($soma==0 || $soma==1)
        {
          $resultado1=0;
        }
        else
        {
          $resultado1=11-$soma;
        }
    
        if ($resultado1==$Numero[10])
        {
         $soma=$Numero[1]*11+$Numero[2]*10+$Numero[3]*9+$Numero[4]*8+$Numero[5]*7+$Numero[6]*6+$Numero[7]*5+
         $Numero[8]*4+$Numero[9]*3+$Numero[10]*2;
         $soma=$soma-(11*(intval($soma/11)));
    
         if ($soma==0 || $soma==1)
         {
           $resultado2=0;
         }
         else
         {
          $resultado2=11-$soma;
         }
         if ($resultado2==$Numero[11]){
            $nome = $_POST['nome'];
            $email = $_POST['email'];
            $ddd = $_POST['ddd'];
            $telefone = $_POST['telefone'];
            $endereco = $_POST['endereco'];
            $cep = $_POST['cep'];
            $cidade = $_POST['cidade'];
            $estado = $_POST['estado'];
            $cpf = $_POST['CampoNumero'];
            $cnpj = '';
            $login = $_POST['CampoNumero'];
            $senha = $_POST['CampoNumero'];
            $sql = mysql_query("Insert into users values('$id', '$nome', '$email', '$ddd', '$telefone', '$endereco', '$cep', '$cidade', '$estado', '$cpf', '$cnpj', '$login', '$senha')");
    
    if($sql){
    echo "<script>alert('Usuário cadastrado com sucesso.');
    location.href='logado.php';
    </script>
    ";
    } else {
    echo "<script>alert('Não foi possível cadastrar usuário.');
    history.back(-1);
    </script>
    ";
    }
    
         }
         else
         {
         echo "<script>alert('CPF Inválido. Entre com um CPF Válido');
    history.back(-1);</script>";
         }
        }
        else
        {
         echo "<script>alert('CPF Inválido. Entre com um CPF Válido');
    history.back(-1);</script>";
        }
       }
      }
    // Fim do Calcula CPF
    
    
    //Função que calcula CNPJ
    
      function CalculaCNPJ($CampoNumero)
      {
       $RecebeCNPJ=${"CampoNumero"};
    
       $s="";
       for ($x=1; $x<=strlen($RecebeCNPJ); $x=$x+1)
       {
        $ch=substr($RecebeCNPJ,$x-1,1);
        if (ord($ch)>=48 && ord($ch)<=57)
        {
         $s=$s.$ch;
        }
       }
    
       $RecebeCNPJ=$s;
       if (strlen($RecebeCNPJ)!=14)
       {
         echo "<script>alert('CNPJ deve conter 14 dígitos.');
    history.back(-1);</script>s</h1>";
       }
       else
        if ($RecebeCNPJ=="00000000000000")
        {
         $then;
         echo "<script>alert('CNPJ Inválido. Entre com um CNPJ Válido');
    history.back(-1);</script>";
       }
       else
       {
        $Numero[1]=intval(substr($RecebeCNPJ,1-1,1));
        $Numero[2]=intval(substr($RecebeCNPJ,2-1,1));
        $Numero[3]=intval(substr($RecebeCNPJ,3-1,1));
        $Numero[4]=intval(substr($RecebeCNPJ,4-1,1));
        $Numero[5]=intval(substr($RecebeCNPJ,5-1,1));
        $Numero[6]=intval(substr($RecebeCNPJ,6-1,1));
        $Numero[7]=intval(substr($RecebeCNPJ,7-1,1));
        $Numero[8]=intval(substr($RecebeCNPJ,8-1,1));
        $Numero[9]=intval(substr($RecebeCNPJ,9-1,1));
        $Numero[10]=intval(substr($RecebeCNPJ,10-1,1));
        $Numero[11]=intval(substr($RecebeCNPJ,11-1,1));
        $Numero[12]=intval(substr($RecebeCNPJ,12-1,1));
        $Numero[13]=intval(substr($RecebeCNPJ,13-1,1));
        $Numero[14]=intval(substr($RecebeCNPJ,14-1,1));
    
        $soma=$Numero[1]*5+$Numero[2]*4+$Numero[3]*3+$Numero[4]*2+$Numero[5]*9+$Numero[6]*8+$Numero[7]*7+
        $Numero[8]*6+$Numero[9]*5+$Numero[10]*4+$Numero[11]*3+$Numero[12]*2;
    
        $soma=$soma-(11*(intval($soma/11)));
    
       if ($soma==0 || $soma==1)
       {
         $resultado1=0;
       }
       else
       {
        $resultado1=11-$soma;
       }
       if ($resultado1==$Numero[13])
       {
        $soma=$Numero[1]*6+$Numero[2]*5+$Numero[3]*4+$Numero[4]*3+$Numero[5]*2+$Numero[6]*9+
        $Numero[7]*8+$Numero[8]*7+$Numero[9]*6+$Numero[10]*5+$Numero[11]*4+$Numero[12]*3+$Numero[13]*2;
        $soma=$soma-(11*(intval($soma/11)));
        if ($soma==0 || $soma==1)
        {
         $resultado2=0;
        }
       else
       {
       $resultado2=11-$soma;
       }
       if ($resultado2==$Numero[14]){
            $nome = $_POST['nome'];
            $email = $_POST['email'];
            $ddd = $_POST['ddd'];
            $telefone = $_POST['telefone'];
            $endereco = $_POST['endereco'];
            $cep = $_POST['cep'];
            $cidade = $_POST['cidade'];
            $estado = $_POST['estado'];
            $cpf = '';
            $cnpj = $_POST['CampoNumero'];
            $login = $_POST['CampoNumero'];
            $senha = $_POST['CampoNumero'];        
            $sql = mysql_query("Insert into users values('$id', '$nome', '$email', '$ddd', '$telefone', '$endereco', '$cep', '$cidade', '$estado', '$cpf', '$cnpj', '$login', '$senha')");
    
    if($sql){
    echo "<script>alert('Usuário cadastrado com sucesso.');
    location.href='logado.php';
    </script>
    ";
    } else {
    echo "<script>alert('Não foi possível cadastrar usuário.');
    history.back(-1);
    </script>
    ";
    }
    
       }
       else
       {
       echo "<script>alert('CNPJ Inválido. Entre com um CNPJ Válido');
    history.back(-1);</script>";
       }
      }
      else
      {
       echo "<script>alert('CNPJ Inválido. Entre com um CNPJ Válido');
    history.back(-1);</script>";
      }
     }
    }
    //Fim do Calcula CNPJ
    ?>
    <?
    include("copyright.php");
    ?>
    <HTML>
    <head>
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
    }
    
    function MM_validateForm() { //v4.0
      var i,p,que,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
      for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
        if (val) { nm=val.name; if ((val=val.value)!="") {
          if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
            if (p<1 || p==(val.length-1)) errors+='O campo '+nm+' requer um endereço de email válido.\n';
          } else if (test!='R') { num = parseFloat(val);
            if (isNaN(val)) errors+='O campo '+nm+' aceita somente números.\n';
            if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
              min=test.substring(8,p); max=test.substring(p+1);
              if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
        } } } else if (test.charAt(0) == 'R') errors += 'O campo '+nm+' deve ser preenchido.\n'; }
      } if (errors) alert('Erro ao preencher o formulário:\n'+errors);
      document.MM_returnValue = (errors == '');
    }
    //-->
    </script>
    </head>
    </html>
    "config.php"
    <?
    ####################################
    #    Protegendo páginas v. 2.5     #
    #  Script desenvolvido por |paes|  #
    ####################################
    // Endereço do seu servidor MySQL
    $dbhost='localhost';
    
    // Usuário do MySQL
    $dbuser='acapes_frl';
    
    // Senha do MySQL
    $dbpasswd='******';
    
    // Nome do Banco de dados
    $dbname='acapes_protecao';
    
    ####################################
    #           Não altere               #
    ####################################
    // Conexão com o Banco de Dados
    $conexao = @mysql_connect($dbhost, $dbuser, $dbpasswd) or die ("Não foi possível conectar-se ao servidor MySQL");
    $db = @mysql_select_db($dbname) or die ("Não foi possível selecionar o banco de dados <b>$dbname</b>");
    ?>
    "include.php"
    <?
    ####################################
    #    Protegendo páginas v. 2.5     #
    #  Script desenvolvido por |paes|  #
    ####################################
    ####################################
    #           Não altere               #
    ####################################
    // Sistema para verificar se é administrador
    include("config.php");
    $sql = "SELECT * FROM config";
    
    $resultado = mysql_query($sql)
    or die ("Não foi possível realizar a consulta ao banco de dados");
    
    if(mysql_num_rows($resultado)>0) {
    
    while ($linha=mysql_fetch_array($resultado)) {
    $adminl = $linha["adminl"];
    $nsite = $linha["nsite"];
    $usite = $linha["usite"];
    $nsite = $linha["nsite"];
    $fonte = $linha["fonte"];
    $tfonte = $linha["tfonte"];
    }}
    ?>
    
    "verifica.php"
    <?
    ####################################
    #    Protegendo páginas v. 2.5     #
    #  Script desenvolvido por |paes|  #
    ####################################
    ####################################
    #           Não altere               #
    ####################################
    // Sistema para verificar se o usuário já está logado ou não
    if(!$HTTP_COOKIE_VARS["usuario"] && !$HTTP_COOKIE_VARS["senha"]){
    header("Location: cadastro.php");
    }
    if($acao == sair){
    setcookie("usuario");
    setcookie("senha");
    header("location: cadastro.php");
    }
    ?>
    

    Bem, aí estão os códigos. Espero que possam me ajudar

  14. Fala Galera... To de volta no tópico.

    A parada é a seguinte. Até sexta feira meu sistema de login estava funcionando normalmente, mas aí no sábado eu viajei e só voltei a mexer nele hoje. Para minha surpresa eu não estou conseguindo cadastrar mais ninguém.

    Não sei se isso está acontecendo por causa de problemas no servidor de hospedagem.

    Na hora de fazer login, ele funciona normalmente mas na hora de cadastrar usuário ele mostra a mensagem "Não foi possível cadastrar usuário".

    Olhando o código, parece que o mysql_query não está acontecendo, mas alguém saberia me explicar porque?

    EDIT 12:51 - Já achei o erro. Nesse trecho de código eu tinha tirado a variável dinâmica $cnpj:

    if ($resultado2==$Numero[11]){
            $nome = $_POST['nome'];
            $email = $_POST['email'];
            $ddd = $_POST['ddd'];
            $telefone = $_POST['telefone'];
            $endereco = $_POST['endereco'];
            $cep = $_POST['cep'];
            $cidade = $_POST['cidade'];
            $estado = $_POST['estado'];
            $cpf = $_POST['CampoNumero'];
            $login = $_POST['CampoNumero'];
            $senha = $_POST['CampoNumero'];
            $sql = mysql_query("Insert into users values('$id', '$nome', '$email', '$ddd', '$telefone', '$endereco', '$cep', '$cidade', '$estado', '$cpf', '$login', '$senha')");
    
    if($sql){
    echo "<script>alert('Usuário cadastrado com sucesso.');
    location.href='logado.php';
    </script>
    ";
    } else {
    echo "<script>alert('Não foi possível cadastrar usuário.');
    history.back(-1);
    </script>
    ";
    }

    Por isso, tinha campo NOT Null ficando em branco e não estava adicionando.

  15. Mas se você reparar, esse

    if ($resultado2==$Numero[11]){
    está dentro da função que testa o cpf. Ele só insere no BD se entrar no if. Repare na função de validar CPF inteira.
    //Calcula CPF
    
      function CalculaCPF($CampoNumero)
      {
       $RecebeCPF=$CampoNumero;
       //Retirar todos os caracteres que não sejam 0-9
       $s="";
       for ($x=1; $x<=strlen($RecebeCPF); $x=$x+1)
       {
        $ch=substr($RecebeCPF,$x-1,1);
        if (ord($ch)>=48 && ord($ch)<=57)
        {
          $s=$s.$ch;
        }
       }
       
       $RecebeCPF=$s;
       if (strlen($RecebeCPF)!=11)
       {
        echo "<h1>É obrigatório o CPF com 11 dígitos</h1>";
       }
       else
         if ($RecebeCPF=="00000000000")
         {
           $then;
           echo "<h1>CPF Inválido</h1>";
         }
         else
         {
          $Numero[1]=intval(substr($RecebeCPF,1-1,1));
          $Numero[2]=intval(substr($RecebeCPF,2-1,1));
          $Numero[3]=intval(substr($RecebeCPF,3-1,1));
          $Numero[4]=intval(substr($RecebeCPF,4-1,1));
          $Numero[5]=intval(substr($RecebeCPF,5-1,1));
          $Numero[6]=intval(substr($RecebeCPF,6-1,1));
          $Numero[7]=intval(substr($RecebeCPF,7-1,1));
          $Numero[8]=intval(substr($RecebeCPF,8-1,1));
          $Numero[9]=intval(substr($RecebeCPF,9-1,1));
          $Numero[10]=intval(substr($RecebeCPF,10-1,1));
          $Numero[11]=intval(substr($RecebeCPF,11-1,1));
    
         $soma=10*$Numero[1]+9*$Numero[2]+8*$Numero[3]+7*$Numero[4]+6*$Numero[5]+5*
         $Numero[6]+4*$Numero[7]+3*$Numero[8]+2*$Numero[9];
         $soma=$soma-(11*(intval($soma/11)));
    
        if ($soma==0 || $soma==1)
        {
          $resultado1=0;
        }
        else
        {
          $resultado1=11-$soma;
        }
    
        if ($resultado1==$Numero[10])
        {
         $soma=$Numero[1]*11+$Numero[2]*10+$Numero[3]*9+$Numero[4]*8+$Numero[5]*7+$Numero[6]*6+$Numero[7]*5+
         $Numero[8]*4+$Numero[9]*3+$Numero[10]*2;
         $soma=$soma-(11*(intval($soma/11)));
    
         if ($soma==0 || $soma==1)
         {
           $resultado2=0;
         }
         else
         {
          $resultado2=11-$soma;
         }
    
    //Esse IF verifica se o CPF é válido
    
         if ($resultado2==$Numero[11]){
            $nome = $_POST["nome"];
            $email = $_POST["email"];
            $ddd = $_POST["ddd"];
            $telefone = $_POST["telefone"];
            $endereco = $_POST["endereco"];
            $cep = $_POST["cep"];
            $email = $_POST["email"];
            $cidade = $_POST["cidade"];
            $estado = $_POST["estado"];
            $cpf = $_POST["CampoNumero"];
            $cnpj = null;
            $login = $_POST["CampoNumero"];
            $senha = $_POST["CampoNumero"];
    
    //Se ele entrou no IF então CPF é válido e ele adiciona no BD
    
            $sql = mysql_query("Insert into users values('$id', '$nome', '$email', '$ddd', '$telefone', '$endereco', '$cep', '$cidade', '$estado', '$cpf', '$cnpj', '$login', '$senha')");
    
    if($sql){
    echo "
    <HTML>
    <title>$nsite</title>
    <font face=\"$fonte\" size=\"$tfonte\">O usuário <b>$CampoNumero</b> foi cadastrado com sucesso. Agora ele poderá acessar as partes restritas de seu site.<br></font>
    <meta http-equiv=\"refresh\" content=\"5;URL=logado.php\">
    </HTML>";
    } else {
    echo "<HTML>
    <title>$nsite</title>Não foi possível cadastrar esse usuário...
    <meta http-equiv=\"refresh\" content=\"2;URL=cadastrar.php\">
    </HTML>";
    }
    
    \\Se não for válido ele mostra mensagem de erro
    
         }
         else
         {
         echo "<h1>CPF Inválido</h1>";
         }
        }
        else
        {
         echo "<h1>CPF Inválido</h1>";
        }
       }
      }
    // Fim do Calcula CPF
    

    Realmente está errado o que eu fiz?

    Se estiver eu continuo não entendendo a Solução correta. Teria como fazer isso no código que está no primeiro code?

  16. Na pergunta 1 eu quis saber se isso que eu fiz está certo

    $estado = $HTTP_POST_VARS["estado"];
    $cpf = null;
    $cnpj = $HTTP_POST_VARS["CampoNumero"];
    Ou se para deixá-la null é só colocar na modelagem do banco de dados e não mexer mais nela. A solução da 2 eu acho que entendi. Não dá pra testar agora porque to no trabalho, mas quando chegar em casa eu testo. Vê pra mim se ele teria que ficar assim:
    if ($resultado2==$Numero[11]){
            $nome = $_POST["nome"];
            $email = $_POST["email"];
            $ddd = $_POST["ddd"];
            $telefone = $_POST["telefone"];
            $endereco = $_POST["endereco"];
            $cep = $_POST["cep"];
            $email = $_POST["email"];
            $cidade = $_POST["cidade"];
            $estado = $_POST["estado"];
            $cpf = $_POST["CampoNumero"];
            $cnpj = null;
            $login = $_POST["CampoNumero"];
            $senha = $_POST["CampoNumero"];
            $sql = mysql_query("Insert into users values('$id', '$nome', '$email', '$ddd', '$telefone', '$endereco', '$cep', '$cidade', '$estado', '$cpf', '$cnpj', '$login', '$senha')");
    
    if($sql){
    echo "
    <HTML>
    <title>$nsite</title>
    <font face=\"$fonte\" size=\"$tfonte\">O usuário <b>$CampoNumero</b> foi cadastrado com sucesso. Agora ele poderá acessar as partes restritas de seu site.<br></font>
    <meta http-equiv=\"refresh\" content=\"5;URL=logado.php\">
    </HTML>";
    } else {
    echo "<HTML>
    <title>$nsite</title>Não foi possível cadastrar esse usuário...
    <meta http-equiv=\"refresh\" content=\"2;URL=cadastrar.php\">
    </HTML>";
    }
    
         }
         else
         {
         echo "<h1>CPF Inválido</h1>";
         }
        }
        else
        {
         echo "<h1>CPF Inválido</h1>";
        }
    

×
×
  • Criar Novo...