Ir para conteúdo
Fórum Script Brasil

neto.joaobatista

Membros
  • Total de itens

    116
  • Registro em

  • Última visita

Sobre neto.joaobatista

  • Data de Nascimento 05/09/1981

Perfil

  • Gender
    Male
  • Location
    Franca/SP

neto.joaobatista's Achievements

0

Reputação

  1. Bom, aqui vai uma implementação do hash SHA-1, estou trabalhando na serie SHA-2 (atualmente SHA-256 e futuramente SHA-512). O código abaixo é para quem gosta de saber o que acontece debaixo dos panos quando você usa uma função nativa ou quando a função nativa não está disponível no seu servidor... <?php /** * Implementação PHP do Secure Hash Algorithm segundo a Secure Hash Standard (SHS) (FIPS PUB 180-3) de outubro de 2008. * <p> * Nessa primeira versão está sendo implementado apenas o hash SHA-1, a proxima versão já contará com SHA-256 * e futuramente SHA-384 e SHA-512 * </p> * * @version 0.1 * @author João Batista Neto <neto.joaobatista@gmail.com> * @since 2009-08-06 * @license LGLP * @link http://csrc.nist.gov/publications/fips/fips180-3/fips180-3_final.pdf * @category Computer Security, Cryptography, Hash. */ abstract class SecureHash { /** * Identifica o hash SHA-1 */ const SHA_1 = "sha1"; /** * Identifica o hash SHA-256 */ const SHA_256 = "sha256"; /** * Implementação do algorítimo de via única SHA-1 (Secure Hash Algorithm 1) definido pela especificação FIPS 180-3 * <p> * Message Size: < 2**64 * Block Size: 512 bits * Word Size: 32 bits * Message Digest Size: 160 bits * </p> * @link http://csrc.nist.gov/publications/fips/fips180-3/fips180-3_final.pdf * @param $message * @return string */ static public function sha1( $message ){ /** * Pre-processamento */ $M = self::pre_process( $message ); /** * Define os valores iniciais [5.3.1] */ $H = array( 0x67452301 , 0xefcdab89 , 0x98badcfe , 0x10325476 , 0xc3d2e1f0 ); /** * Calculando o Hash [6.1.2] */ for ( $i = 0 , $N = count( $M ); $i < $N; $i += 16 ){ $W = array(); /** * [6.1.2.1] */ for ( $t = 0; $t < 80; $t++ ){ $W[ $t ] = ( $t <= 15 ) ? $M[ $i + $t ] : self::ROTL( $W[ $t - 3 ] ^ $W[ $t - 8 ] ^ $W[ $t - 14 ] ^ $W[ $t - 16 ] , 1 ); } /** * [6.1.2.2] */ $a = $H[ 0 ]; $b = $H[ 1 ]; $c = $H[ 2 ]; $d = $H[ 3 ]; $e = $H[ 4 ]; /** * [6.1.2.3] */ for ( $t = 0; $t < 80; $t++ ){ $T = self::add( self::add( self::ROTL( $a , 5 ) , self::f( $t , $b , $c , $d ) ) , self::add( self::add( $e , $W[ $t ] ) , self::Kt( $t ) ) ); $e = $d; $d = $c; $c = self::ROTL( $b , 30 ); $b = $a; $a = $T; } /** * [6.1.2.4] */ $H[ 0 ] = self::add( $H[ 0 ] , $a ); $H[ 1 ] = self::add( $H[ 1 ] , $b ); $H[ 2 ] = self::add( $H[ 2 ] , $c ); $H[ 3 ] = self::add( $H[ 3 ] , $d ); $H[ 4 ] = self::add( $H[ 4 ] , $e ); } return ( sprintf( "%08x%08x%08x%08x%08x" , $H[ 0 ] , $H[ 1 ] , $H[ 2 ] , $H[ 3 ] , $H[ 4 ] ) ); } /** * Pre-processamento [5] * @return array */ static private function pre_process( $message ){ $size = strlen( $message ); $M = array(); $N = ( ( $size + 8 ) >> 6 ) + 1; /** * [5.1.1] */ $message .= "x80"; for ( $i = 0; $i < $N * 16; $i++ ) $M[ $i ] = 0; for ( $i = 0; $i < $size; $i++ ) $M[ $i >> 2 ] |= ord( $message{ $i } ) << ( 24 - ( $i % 4 ) * 8 ); $M[ $i >> 2 ] |= 0x80 << ( 24 - ( $i % 4 ) * 8 ); $M[ $N * 16 - 1 ] = $size * 8; return( $M ); } /** * Operação AND [3.2.2] * Z = (X + Y) mod 2^32 * @param integer $x * @param integer $y * @return integer O novo valor */ static private function add( $x , $y ){ $lsw = ( $x & 0xffff ) + ( $y & 0xffff ); $msw = ( $x >> 16 ) + ( $y >> 16 ) + ( $lsw >> 16 ); return ( ( $msw << 16 ) | ( $lsw & 0xFFFF ) ); } /** * Operação Right Shift [3.2.3] * @param $x * @param $n * @return integer */ static private function SHR( $x , $n ){ $z = hexdec( 80000000 ); if ( $z & $x ){ $x = ( $x >> 1 ); $x &= ~$z; $x |= 0x40000000; $x = ( $x >> ( $n - 1 ) ); } else { $x = ( $x >> $n ); } return( $x ); } /** * Operação Circular Right Shift [3.2.4] * @param integer $x * @param integer $n * @return integer */ static private function ROTR( $x , $n ){ return( ( self::SHR( $x , $n ) | ( $x << ( 32 - $n ) ) & 0xFFFFFFFF ) ); } /** * Operação Circular Left Shift [3.2.5] * @param integer $num * @param integer $n * @return integer */ static private function ROTL( $x , $n ){ return ( ( $x << $n ) | self::SHR( $x , 32 - $n ) ); } /** * Função f [4.1.1] * @param $t * @param $b * @param $c * @param $d * @return integer */ static private function f( $t , $b , $c , $d ){ if ( ( $t >= 0 ) && ( $t <= 19 ) ) return ( self::Ch( $b , $c , $d ) ); if ( ( $t >= 20 ) && ( $t <= 39 ) ) return ( self::Parity( $b , $c , $d ) ); if ( ( $t >= 40 ) && ( $t <= 59 ) ) return ( self::Maj( $b , $c , $d ) ); if ( ( $t >= 60 ) && ( $t <= 79 ) ) return ( self::Parity( $b , $c , $d ) ); } /** * Ch [4.1.1] * @param integer $x * @param integer $y * @param integer $z * @return integer */ static private function Ch( $x , $y , $z ){ return ( ( $x & $y ) ^ ( ~$x & $z ) ); } /** * Parity [4.1.1] * @param integer $x * @param integer $y * @param integer $z * @return integer */ static private function Parity( $x , $y , $z ){ return ( $x ^ $y ^ $z ); } /** * Maj [4.1.1] * @param integer $x * @param integer $y * @param integer $z * @return integer */ static private function Maj( $x , $y , $z ){ return ( ( $x & $y ) ^ ( $x & $z ) ^ ( $y & $z ) ); } /** * Sigma{256} 0 [4.1.2] * @param integer $x * @return integer */ static private function Sigma_0( $x ){ return( ( self::ROTR( $x , 2 ) ^ self::ROTR( $x , 13 ) ^ self::ROTR( $x , 22 ) ) ); } /** * Sigma{256} 1 [4.1.2] * @param integer $x * @return integer */ static private function Sigma_1( $x ){ return( ( self::ROTR( $x , 6 ) ^ self::ROTR( $x , 11 ) ^ self::ROTR( $x , 25 ) ) ); } /** * sigma{256} 0 [4.1.2] * @param integer $x * @return integer */ static private function sigma0( $x ){ return( ( self::ROTR( $x , 7 ) ^ self::ROTR( $x , 18 ) ^ ( self::SHR( $x , 3 ) ) ) ); } /** * sigma{256} 1 [4.1.2] * @param integer $x * @return integer */ static private function sigma1( $x ){ return( ( self::ROTR( $x , 17 ) ^ self::ROTR( $x , 19 ) ^ ( self::SHR( $x , 10 ) ) ) ); } /** * Recupera o valor da constante Kt [4.2.1] e [4.2.2] * @param integer $t * @param string $type * @return integer */ static private function Kt( $t , $type = self::SHA_1 ){ /** * Kt [4.2.1] */ $k_SHA1 = array( 0x5a827999 , 0x6ed9eba1 , 0x8f1bbcdc , 0xca62c1d6 ); /** * Kt [4.2.2] */ $k_SHA256 = array( 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 ); /** * Retorna a constante segundo o hash usado */ switch ( $type ){ case self::SHA_1 : if ( ( $t >= 0 ) && ( $t <= 19 ) ) return ( $k_SHA1[ 0 ] ); if ( ( $t >= 20 ) && ( $t <= 39 ) ) return ( $k_SHA1[ 1 ] ); if ( ( $t >= 40 ) && ( $t <= 59 ) ) return ( $k_SHA1[ 2 ] ); if ( ( $t >= 60 ) && ( $t <= 79 ) ) return ( $k_SHA1[ 3 ] ); throw new UnexpectedValueException( sprintf( "O valor %08x não era esperado." , $t ) ); case self::SHA_256: return( $k_SHA256[ $t ] ); } } } Agora fazendo o cálculo: $message = "João Batista Neto"; printf( "nativo: %s\nSHA-1: %s\n" , sha1( $message ) , SecureHash::sha1( $message ) ); A saída será: nativo: f0c8faeacb1df5cebc50c63d1d9aef0f0266535d SHA-1: f0c8faeacb1df5cebc50c63d1d9aef0f0266535d
  2. Tenta assim: $data = "22/07/2009"; $part = strptime( $data , "%d/%m/%Y" ); $wday = explode( "/" , sprintf( "Domingo/%s" , implode( "-feira/" , array( "Segunda" , "Terça" , "Quarta" , "Quinta" , "Sexta" , "Sábado" ) ) ) ); printf( "A data %s vai cair %s" , $data , $wday[ $part[ "tm_wday" ] ] ); A saída será: A data 22/07/2009 vai cair Quarta-feira
  3. neto.joaobatista

    Executar arquivos

    Na resposta ele diz que foi interrompido no ApeGera0003.php e não no 3 arquivo, o código que lhe enviei executa conforme a listagem e não seguindo uma ordem pré-estabelecida. O primeiro arquivo que ele tentou executar foi o ApeGera0003.php e encontrou um erro, por isso ele parou.
  4. neto.joaobatista

    Executar arquivos

    Kara, se você vai acessar o diretório pelo browser então você precisa de um index.php que irá ler qualquer outro arquivo.php na pasta e executá-lo, é isso ? index.php <?php abstract class Main { /** * Número de erros encontrados * @var integer */ static private $erros = 0; /** * Número de arquivos.php encontrados * @var integer */ static private $total = 0; /** * Número de arquivos executados * @var integer */ static private $executados = 0; /** * Arquivo que está sendo executado no momento * @var string */ static private $current = ""; /** * Substitui a saida pelo relatório de execução * @param string $buffer O buffer de execução * @return string */ static public function handleBuffer( $buffer ){ $ret = sprintf( "%d arquivos executados de um total de %d<br />%d erros<br /><br />" , self::$executados , self::$total , self::$erros ); if ( self::$total != self::$executados ){ $ret .= sprintf( "Execução interrompida no arquivo %s." , self::$current ); } $ret = sprintf( "<html><head><title>%s executados.</title></head><body>%s</body></html>" , self::$executados ? self::$executados : "nenhum" , $ret ); return( $ret ); } /** * Trata os erros encontrados * @return boolean TRUE */ static public function handleError(){ ++self::$erros; return( true ); } /** * Inicia a busca por todos os arquivos.php do diretório atual */ static public function start(){ $lista = array(); set_error_handler( array( "Main" , "handleError" ) , E_ALL ); if ( ( $dh = opendir( "." ) ) ){ while ( ( $file = readdir( $dh ) ) ){ if ( $file != "index.php" ){ $info = pathinfo( $file ); if ( $info[ "extension" ] == "php" ){ $lista[] = $file; } } } closedir( $dh ); self::exec( $lista ); } else { printf( "Não foi possível abrir o diretório" ); } } /** * Executa a lista de arquivos.php * @param array $lista Matriz que contém todos os arquivos.php encontrados no diretório */ static private function exec( $lista ){ ob_start( array( "Main" , "handleBuffer" ) ); for ( $i = 0 , self::$total = count( $lista ); $i < self::$total; $i++ ){ self::$current = $lista[ $i ]; try { require( self::$current ); ++self::$executados; } catch ( Exception $e ){ ++self::$erros; } } header( "Content-type: text/html; charset=utf-8" , true , 200 ); ob_end_flush(); } } Main::start();
  5. Tenta mudar sua tag form para: <form enctype="multipart/form-data" method="post" action="cliente_cadastro.php">
  6. Tenta assim: if ( ( $res = mysql_query( sprintf( "SELECT * FROM documento_anexo WHERE id_documento = %d LIMIT 1;" , $idDocumento ) ) ) ){ if ( ( $row = mysql_fetch_array( $res ) ) ){ $img = imagecreatefromstring( $row[ "imagem" ] ); imagejpeg( $img , sprintf( "imagens/%s.jpg" , $row[ "id" ] ) ); header( "Content-type: image/jpeg" ); header( sprintf( "Content-length: %d" , strlen( $row[ "imagem" ] ) ) ); print( $row[ "imagem" ] ); } mysql_free_result( $res ); } Coloquei um LIMIT 1 porque você está enviando cabeçalhos HTTP e por isso você pode enviar apenas uma vez, tornando também o loop while desnecessário
  7. Bom, a não ser que sua base seja uma base antiga, você conseguirá criar o trigger normalmente, utilize as ferramentas GUI do MySQL, pelo MySQL Query Browser você conseguirá fazer isso normalmente.
  8. Bom amigo, não sei se entendi direito o que você quer fazer mas se for o que eu entendi então você nem precisa do php para fazer isso. Imagina que a tabela `caixa` seja assim: mysql> desc `caixa`; +-------+-----------------------+------+-----+-------------------+-----------------------------+ | Field | Type | Null | Key | Default | Extra | +-------+-----------------------+------+-----+-------------------+-----------------------------+ | id | mediumint(8) unsigned | NO | PRI | NULL | auto_increment | | saldo | decimal(10,3) | NO | | 0.000 | | | data | timestamp | NO | PRI | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP | +-------+-----------------------+------+-----+-------------------+-----------------------------+ 3 rows in set (0.00 sec) Para pegarmos o último saldo é só selecionarmos o último registro inserido: select c.`saldo` from `caixa` c where date( `data` ) = date( now() ) order by c.`id` DESC LIMIT 1 ; Isso fará com que o último saldo da data atual seja retornado, com isso basta garantirmos que se não houver nenhum registro na data (ex. a tabela está vazia) nós tenhamos o valor 0 e não null: select ifnull((select c.`saldo` from `caixa` c where date(`data`)=date(now()) order by c.`id` DESC LIMIT 1 ),0); Pronto, agora que conseguimos recuperar o último saldo da data atual então podemos utilizar isso como subquery e utilizar o resultado para gravar no banco: insert into `caixa`(`saldo`) select ifnull((select c.`saldo` from `caixa` c where date(`data`)=date(now()) order by c.`id` DESC LIMIT 1 ),0) + 10; Preste atenção no + 10 no final do insert, esse é o valor do caixa atual, a cada fechamento de caixa você irá somar ao saldo anterior. Testando: mysql> create table `caixa` ( `id` mediumint(8) unsigned not null auto_increment, `saldo` decimal(10,3) not null default 0, `data` timestamp not null default current_timestamp on update current_timestamp, primary key(`id`,`data`) ) engine=MyISAM; Query OK, 0 rows affected (0.00 sec) mysql> insert into `caixa`(`saldo`) select ifnull((select c.`saldo` from `caixa` c where date(`data`)=date(now()) order by c.`id` DESC limit 1),0) + 10; Query OK, 1 row affected (0.01 sec) Records: 1 Duplicates: 0 Warnings: 0 mysql> insert into `caixa`(`saldo`) select ifnull((select c.`saldo` from `caixa` c where date(`data`)=date(now()) order by c.`id` DESC limit 1),0) + 10; Query OK, 1 row affected (0.00 sec) Records: 1 Duplicates: 0 Warnings: 0 mysql> insert into `caixa`(`saldo`) select ifnull((select c.`saldo` from `caixa` c where date(`data`)=date(now()) order by c.`id` DESC limit 1),0) + 10; Query OK, 1 row affected (0.00 sec) Records: 1 Duplicates: 0 Warnings: 0 mysql> insert into `caixa`(`saldo`) select ifnull((select c.`saldo` from `caixa` c where date(`data`)=date(now()) order by c.`id` DESC limit 1),0) + 10; Query OK, 1 row affected (0.00 sec) Records: 1 Duplicates: 0 Warnings: 0 mysql> select * from caixa; +----+--------+---------------------+ | id | saldo | data | +----+--------+---------------------+ | 1 | 10.000 | 2009-07-17 07:13:11 | | 2 | 20.000 | 2009-07-17 07:13:13 | | 3 | 30.000 | 2009-07-17 07:13:14 | | 4 | 40.000 | 2009-07-17 07:13:15 | +----+--------+---------------------+ 4 rows in set (0.00 sec) Ai no PHP você só precisará substituir o 10 pelo seu valor: $saldo = 12.33; $sql = sprintf( "insert into `caixa`(`saldo`) select ifnull((select c.`saldo` from `caixa` c where date(`data`)=date(now()) order by c.`id` DESC limit 1),0) + %f" , $saldo ); if ( mysql_query( $sql ) ){ printf( "Saldo gravado com sucesso.\n" ); }
  9. Bom, se você vai usar o mysqli então a conexão é diferente: $usuario = "daniel"; $senha = "daniel"; $endereco = "localhost"; $banco = "sistema"; $conn = mysqli_init(); @$conn->real_connect( $endereco , $usuario , $senha , $banco ); if ( $conn->errno ){ printf( "Erro ao conectar: %s" , $conn->error ); } else { printf( "ok, conectamos..." ); } $conn->close();
  10. neto.joaobatista

    Problemas com Login

    O erro de fato está na definição da sua sessão, você está verificando se a sessão login existe, mas está definindo com outro nome: Você verifica assim: if(isset($_SESSION['login'])) #Verifico se existe a Sessão Login E cria a sessão assim: else // se a senha for bater com nome de usuario então inicio a sessão { $_SESSION['login_usuario'] = $usuario; $_SESSION['senha_usuario'] = $senha; header('Location: /admin/'); } Tenta criar sua sessão assim: $_SESSION[ "login" ][ "usuario" ] = $usuario; $_SESSION[ "login" ][ "senha" ] = $senha;
  11. Quando você cria um input do tipo file no seu html, o nome desse campo é enviado para o PHP e o conteúdo dele é o nome da imagem que a pessoa enviou. No código que você postou não incluiu a parte que recebe de fato o arquivo, nem a parte que define a variável $imagem_name. Por isso eu apenas peguei a parte que copia sua imagem de um lugar e manda para outro, renomeei o arquivo de destino mantendo a pasta e pronto. O nome que foi gerado pelo hash é exatamente o md5 do contaúdo de $imagem_name Bom, você tem a opção de, quando resgatar a imagem do banco de dados você usar o md5 no nome real dela, isso irá fazer com que você saiba qual é a imagem. No seu banco está assim: mysql> select logomarca from c_clicalista where `clica_id`=44; +---------------+ | logomarca | +---------------+ | logomarca.jpg | +---------------+ 1 row in set (0.00 sec) Ai você recupera assim no PHP: if ( ( $resp = mysql_query( "select logomarca from c_clicalista where `clica_id`=44" , $conn ) ) ){ if ( ( $row = mysql_fetch_array( $resp , MYSQL_ASSOC ) ) ){ $arquivo = sprintf( "%s" , preg_replace_callback( "/(\\w+)\\.(\\w{3})/" , create_function( '$mtc', 'return( sprintf( "%s.%s" , md5( $mtc[ 1 ] ) , $mtc[ 2 ] ) );' ) , $row[ "logomarca" ] ) ); printf( "O arquivo que está no banco é: %s e depois do md5 ficou %s\n" , $row[ "logomarca" ] , $arquivo ); } mysql_free_result( $resp ); } Isso vai exibir: O arquivo que está no banco é: logomarca.jpg e depois do md5 ficou c3735b888c69db8a2b34bd772e4b5bb0.jpg
  12. Bom amigo, aquele trigger que eu lhe mostrei no fórum de MySQL resolve seu problema com apenas uma modificação, em vez de pegar o último `contrato` cadastrado e somar 1 (é o que está fazendo) você vai fazer ele pegar o último `clica_id` e somar 1, na verdade você nem precisa fazer isso porque com o trigger é possível fazer isso automático também: Primeiro você precisa apagar o primeiro trigger: drop trigger contratos_autoincrement; Agora criando um novo que vai se basear na coluna `clica_id` create trigger contratos_autoincrement before insert on c_clicalista for each row set NEW.contrato=(select ifnull( NEW.clica_id , ifnull( max( `clica_id` ) , 0 ) + 1 ) from c_clicalista); Esse trigger ai, antes de inserir o novo registro, vai verificar se o seu insert está definindo um `clica_id` se estiver ele vai usar o `clica_id` definido no insert, senão vai pegar o último `clica_id` da tabela, somar 1 e gravar na tabela. Testando: mysql> drop trigger contratos_autoincrement; Query OK, 0 rows affected (0.00 sec) mysql> create trigger contratos_autoincrement before insert on c_clicalista for each row set NEW.contrato=(select ifnull( NEW.clica_id , ifnull( max( `clica_id` ) , 0 ) + 1 ) from c_clicalista); Query OK, 0 rows affected (0.00 sec) Ai você insere seus registros normalmente: INSERT INTO c_clicalista VALUES('45' , null , '87' , '' , '' , '' , 'mauricio' , '123456' , 'Casa de Ração Ponto Final' , '' , '' , 'maursantos@hotmail.com' , '3228 3150' , 'Av. Alpheu Ribeiro, 1291 Carapina Grande - Serra - ES' , '' , 'Ativado' , ''); INSERT INTO c_clicalista VALUES('44' , null , '45' , '' , '' , '' , 'Salão da Selma' , '123456' , 'Salão da Selma' , '' , '' , '' , '8811 - 1176' , 'Av. Alpheu Ribeiro, 1110 Carapina Grande - Serra - ES' , '' , 'Ativado' , ''); Depois é só testar para ver o resultado: mysql> select * from c_clicalista; +----------+----------+--------+--------+-----+--------------+-----------------+--------+-----------------------------+------+------------+------------------------+-------------+-------------------------------------------------------+------+---------+-----------+ | clica_id | contrato | cat_id | nome_1 | cpf | nome_contato | login | senha | nome | site | breve_desc | email | telefones | como_chegar | desc | status | logomarca | +----------+----------+--------+--------+-----+--------------+-----------------+--------+-----------------------------+------+------------+------------------------+-------------+-------------------------------------------------------+------+---------+-----------+ | 44 | 0044 | 45 | | | | Salão da Selma | 123456 | Salão da Selma | | | | 8811 - 1176 | Av. Alpheu Ribeiro, 1110 Carapina Grande - Serra - ES | | Ativado | | | 45 | 0045 | 87 | | | | mauricio | 123456 | Casa de Ração Ponto Final | | | maursantos@hotmail.com | 3228 3150 | Av. Alpheu Ribeiro, 1291 Carapina Grande - Serra - ES | | Ativado | | +----------+----------+--------+--------+-----+--------------+-----------------+--------+-----------------------------+------+------------+------------------------+-------------+-------------------------------------------------------+------+---------+-----------+ 2 rows in set (0.00 sec)
  13. Putz, para que esse tanto de quebra de linha, hahahahah Vamos condensar um pouco, tenta assim: <html> <head> <meta http-equiv="content-type" content="text/html" charset="UTF-8"> <link rel="stylesheet" type="text/css" href="../css/estilo.css" /> <title>Urna Online</title> </head> <body> <?php #variaveis $login = $_SESSION["login"]; $senha = $_SESSION["senha"]; $conexao_tabela = ("SELECT * FROM eleitores WHERE login='$login' AND senha='$senha'"); $RS = mysql_query($conexao_tabela) or die ("$erro3"); $passou = true; $erro = null; foreach ( $_POST as $name => $value ){ $name = preg_replace( "/\\bval_(.*)\\b/" , "$1" , $name ); if ( empty( $value ) || ( $RS[ $name ] != $value ) ){ $passou = false; $erro = $name; break; } } if ( !$passou ) printf( "O campo %s está incorreto." , $erro ); else printf( "<meta http-equiv='Refresh' content='0;URL=escolha_estado.php>" ); ?> </body> </html>
  14. neto.joaobatista

    Verificação De IP

    Primeiro você vai precisar criar uma tabela para armazenar os ips: create table`ips` ( `id` mediumint(8) unsigned not null auto_increment, `ip` varchar(15) not null, `date` timestamp not null default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, primary key (`id`), key `ipdata` (`ip`,`date`) ) engine=MyISAM; Depois você faz no PHP assim: $ip = isset( $_SERVER[ 'HTTP_X_FORWARD_FOR' ] ) && $_SERVER[ 'HTTP_X_FORWARD_FOR' ] ? $_SERVER[ 'HTTP_X_FORWARD_FOR' ] : isset( $_SERVER[ 'REMOTE_ADDR' ] ) && $_SERVER[ 'REMOTE_ADDR' ] ? $_SERVER[ 'REMOTE_ADDR' ] : null; $sql = sprintf( "select count(*) 'total' from `ips` where ( `ips`.`ip` = '%s' ) AND ( ( to_days( now() ) - to_days( `date` ) ) = 0 ) AND ( hour( timediff( now() , `date` ) ) < 24 );" , $ip ); $conn = mysql_connect( "seuservidor" , "usuario" , "suasenha" ); if ( $conn ){ mysql_select_db( "seubancodedados" , $conn ); if ( ( $res = mysql_query( $sql , $conn ) ) ){ if ( ( $row = mysql_fetch_array( $res , MYSQL_ASSOC ) ) ){ if ( ( (int) $row[ "total" ] ) ){ printf( "Você já viu esse conteúdo hoje..." ); } else { mysql_free_result( $res ); if ( mysql_query( sprintf( "insert into ips( `ip` ) values( '%s' );" , $ip ) ) ){ printf( "Ok, você pode ver o conteúdo" ); } } } } mysql_close( $conn ); } Agora abre seu navegador, aponta para o lugar que você salvou o arquivo.php e abre uma vez, depois da um refresh e vê se é isso que você precisa
  15. Tenta mudar a linha: copy($imagem, "clicalista/c_banners/$imagem_name"); /*envia a imagem para a pasta*/ para copy( $imagem , sprintf( "clicalista/c_banners/%s" , preg_replace_callback( "/(\\w+)\\.(\\w{3})/" , create_function( '$mtc', 'return( sprintf( "%s.%s" , md5( $mtc[ 1 ] ) , $mtc[ 2 ] ) );' ) , $imagem_name ) ) );
×
×
  • Criar Novo...