IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

bouton regénérer


Sujet :

Langage PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre Expert
    Avatar de laurentSc
    Homme Profil pro
    Webmaster débutant perpétuel !
    Inscrit en
    Octobre 2006
    Messages
    10 508
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Webmaster débutant perpétuel !
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2006
    Messages : 10 508
    Billets dans le blog
    1
    Par défaut bouton regénérer
    Bonsoir,

    je viens de récupérer un script qui génère un code captcha. Ca marche bien sauf que ce que je mets derrière le script est ignoré. Je pense que ça vient de la fonction includée, mais je ne vois pas. Quelqu'un verrait-il ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    <?php
    session_start();
    	include ("functions/php/captcha.fct.php"); // fichier ou sont mes fonctions de création de captcha
    	header('Content-type: image/png'); 
    	header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
    	header('Cache-Control: no-store, no-cache, must-revalidate');
    	header('Cache-Control: post-check=0, pre-check=0', false);
    	header('Pragma: no-cache');
     
    	echo captcha(5,array(0,0,0),array(255,255,255),array(0,250,125));
     
    	echo "captcha=".$sTexte;
    ?>
    <html>
    <head>
      <meta content="text/html; charset=ISO-8859-1"
     http-equiv="content-type">
      <title></title>
    </head>
    <body>
    <form method="post" action="" enctype="application/x-www-form-urlencoded">
    <table><tr><td>texte : </td><td><input name="texte" type="text" size="30"></td></tr>
    <tr><td colspan=2>
    	<INPUT type="submit" value="Envoyer"></td></tr></table>
    </form>
    <?php
    if ($_POST['texte']!=$sTexte) echo 'captcha pas bon'; else echo 'captcha bon';
    ?>
    </body>
    </html>
    captcha.fct.php
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    <?php
    	/**
    	* @name captcha
    	* Afficher  une image avec 5 caractères généré aléatoirement.
    	* 
    	* @param Numeric iNbCaract : nombre de caractère
    	* @param Array aTextColor : Code couleur(RGB) séparé par des virgules de la couleur du texte.
    	* @param Array aBgColor : Code couleur(RGB) séparé par des virgules de la couleur de fond.
    	* @param Array aBorderColor : Code couleur(RGB) séparé par des virgules de la couleur de bordure.
    	*
    	* @return Image l'image crée.
    	*/
     
    	function captcha ($iNbCaract,$aTextColor, $aBgColor, $aBorderColor ) {
    		//vérification d'existance de la fonction
    		if ( !function_exists('imagecreatetruecolor') ){
    			return false;
    		}
     
    		//test des paramètres
    		if (!is_int($iNbCaract))
    			$iNbCaract = 5;
     
     
    		if ( is_array($aTextColor) && count($aTextColor)=== 3 ){ // si c'est un tableau de 3 
    			for($i=0; $i<3;$i++){
    				if ( $aTextColor[$i] < 0 || $aTextColor[$i] > 255 ){ // si ce n'est pas compris entre 0 et 255
    					$aTextColor[$i] = 0; // on met à zéro = blanc
    				} 
    			}
    		}else { // c'est pas un tableau de 3
    			$aTextColor = array(0,0,0);		
    		}
     
    		if ( is_array($aBgColor) && count($aBgColor)=== 3 ){ // si c'est un tableau de 3 
    			for($i=0; $i<3;$i++){
    				if ( $aBgColor[$i] < 0 || $aBgColor[$i] > 255 ){ // si ce n'est pas compris entre 0 et 255
    					$aBgColor[$i] = 255; // on met à 255 = noir
    				} 
    			}
    		}else { // c'est pas un tableau de 3
    			$aBgColor = array(255,255,255);		
    		}
     
    		if ( is_array($aBorderColor) && count($aBorderColor)=== 3 ){ // si c'est un tableau de 3 
    			for($i=0; $i<3;$i++){
    				if ( $aBorderColor[$i] < 0 || $aBorderColor[$i] > 255 ){ // si ce n'est pas compris entre 0 et 255
    					$aBorderColor[$i] = 0; // on met à zéro = blanc
    				} 
    			}
    		}else { // c'est pas un tableau de 3
    			$aBorderColor = array(0,0,0);		
    		}		
    		//fin test des paramètres
     
    		//variables
    		$iWidth = $iNbCaract * 20;
    		$iHeight = 27;
    		$iFontSize = 5; // de 1 à 5
    		$sRep = "./captcha/";
    		//fin variables
     
    		//chiffre
    		$aCaractere = array();
    		for ($i=0; $i<=9; $i++) 
    			$aCaractere[]  = $i;
    		//majuscule
    		for ($i=65; $i<=90; $i++) 
    			$aCaractere[] = chr($i);
    		//minuscule
    		for ($i=97; $i<=122; $i++) 
    			$aCaractere[] = chr($i);
     
    		//texte aléatoire
    		$sTexte = "";
    		$sTexteImg = "";
    		$iLenCaractere = sizeof($aCaractere)-1;
    		for ($cpt=0;$cpt<$iNbCaract;$cpt++) {
    			$iNum_caract=rand(0, $iLenCaractere );
    			$sTexte .= $aCaractere[$iNum_caract];
    			$sTexteImg .= $aCaractere[$iNum_caract] . " ";
    		}
     
    		//enregistrement du texte dans la session
    		$_SESSION['captcha'] = $sTexte;
     
    		//création d'une image
    		$rImage = imagecreatetruecolor ($iWidth, $iHeight);
     
    		//couleur du texte
    		if (count($aTextColor) === 3)
    			$cText_color = imagecolorallocate ($rImage, $aTextColor[0], $aTextColor[1], $aTextColor[2]);
     
    		// couleur de fond
    		if (count($aBgColor) === 3)
    			$cBg_color = imagecolorallocate ($rImage, $aBgColor[0], $aBgColor[1], $aBgColor[2]);
     
    		// couleur de fond
    		if (count($aBorderColor) === 3)
    			$cBorder_color = imagecolorallocate ($rImage, $aBorderColor[0], $aBorderColor[1], $aBorderColor[2]);
     
    		// on dessine la bordure
    		imagefilledrectangle($rImage, 0, 0, $iWidth, $iHeight,$cBorder_color);
    		imagefilledrectangle($rImage, 1, 1, $iWidth-2, $iHeight-2,$cBg_color);
     
    		// on écrit le texte
    		imagestring ($rImage, $iFontSize, 10, 5,  $sTexteImg, $cText_color);
     
    		// on brouille l'image : floue
    		//imagefilter($rImage, IMG_FILTER_SMOOTH,2); //IMG_FILTER_EMBOSS, IMG_FILTER_SMOOTH
     
    		// Rotation
    		$rImage = imagerotate($rImage, 5, $cBg_color);
     
    		return imagepng($rImage);
     
    		imagedestroy ($rImage);
    	}
     
    ?>

  2. #2
    Membre émérite Avatar de vorace
    Homme Profil pro
    Développeur
    Inscrit en
    Août 2010
    Messages
    573
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur

    Informations forums :
    Inscription : Août 2010
    Messages : 573
    Par défaut
    ca ne searit pas plutot ça :
    captcha.php :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <?php
    session_start();
    	include ("captcha.fct.php"); // fichier ou sont mes fonctions de création de captcha
    	header('Content-type: image/png'); 
    	header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
    	header('Cache-Control: no-store, no-cache, must-revalidate');
    	header('Cache-Control: post-check=0, pre-check=0', false);
    	header('Pragma: no-cache');
     
    	echo captcha(5,array(0,0,0),array(255,255,255),array(0,250,125));
     
    ?>
    formulaire :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
     
    <?php
    session_start();
    $sTexte = $_SESSION['captcha'];
    ?>
    <html>
    <head>
      <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
      <title></title>
    </head>
    <body>
    <?php
    if (isset($_POST['captcha'])){
    	if($_POST['captcha'] != $sTexte) echo 'captcha pas bon'; else echo 'captcha bon';
    }
    ?>
    <form method="post" action="" enctype="application/x-www-form-urlencoded">
    <table><tr><td>texte : </td><td><input name="texte" type="text" size="30"></td></tr>
    <tr><td><img src="captcha.php"/></td><td><input name="captcha" type="text" size="30"/></td></tr>
    <tr><td colspan=2>
    	<INPUT type="submit" value="Envoyer"></td></tr></table>
    </form>
    </body>
    </html>

  3. #3
    Membre Expert
    Avatar de laurentSc
    Homme Profil pro
    Webmaster débutant perpétuel !
    Inscrit en
    Octobre 2006
    Messages
    10 508
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Webmaster débutant perpétuel !
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2006
    Messages : 10 508
    Billets dans le blog
    1
    Par défaut
    Merci d'avoir proposé une réponse ; j'ai juste modifié un peu le formulaire pour que ça fasse ce que je souhaite :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    <?php
    session_start();
    $sTexte = $_SESSION['captcha'];
    ?>
    <html>
    <head>
      <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
      <title></title>
    </head>
    <body>
    <?php
    if (isset($_POST['captcha'])){
    	if($_POST['captcha'] != $sTexte) echo 'captcha pas bon'; else echo 'captcha bon';
    }
    ?>
    <form method="post" action="" enctype="application/x-www-form-urlencoded">
    <table>
    <tr><td colspan=2><img src="captcha.php"/></td></tr>
    <tr><td>texte : </td><td><input name="captcha" type="text" size="30"/></td></tr>
    <tr><td colspan=2>
    	<INPUT type="submit" value="Envoyer"></td></tr></table>
    </form>
    </body>
    </html>

  4. #4
    Membre Expert
    Avatar de laurentSc
    Homme Profil pro
    Webmaster débutant perpétuel !
    Inscrit en
    Octobre 2006
    Messages
    10 508
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Webmaster débutant perpétuel !
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2006
    Messages : 10 508
    Billets dans le blog
    1
    Par défaut bouton regénérer
    Je ressors ce sujet, car je voudrais ajouter un bouton "regénérer". Voilà ce que j'ai fait (pour le formulaire), mais ça ne marche pas :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    <?php
    if (isset($_POST['captcha'])){
    	if($_POST['captcha'] != $sTexte) echo 'captcha pas bon'; else echo 'captcha bon';
    }
    ?>
    <SCRIPT language="Javascript">
    function regenerer(){
    id=document.getElementById("captcha").src="captcha.php";
    }
     
    </SCRIPT>
     
    <form method="post" action="" enctype="application/x-www-form-urlencoded">
    <table>
    <tr><td colspan=2><img name="captcha" src="captcha.php"/></td></tr>
    <tr><td>texte : </td><td><input name="captcha" type="text" size="30"/></td></tr>
    <tr><td colspan=2><input type='button' value='Regénérer' name="regenerer" onclick="regenerer()"></td></tr>
    <tr><td colspan=2>
    	<INPUT type="submit" value="Envoyer"></td></tr></table>
    </form>

  5. #5
    Membre émérite Avatar de vorace
    Homme Profil pro
    Développeur
    Inscrit en
    Août 2010
    Messages
    573
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur

    Informations forums :
    Inscription : Août 2010
    Messages : 573
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    <?php
    session_start();
    if(isset($_SESSION['captcha'])) $sTexte = $_SESSION['captcha'];
    ?>
    <html>
    	<head>
    		<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
    		<title></title>
    		<script language="Javascript">
    			function regenerer(id) {
    				var obj = document.getElementById(id);
    				var src = obj.src;
    				var pos = src.indexOf('?');
    				if (pos >= 0) {
    					src = src.substr(0, pos);
    				}
    				var date = new Date();
    				obj.src = src + '?v=' + date.getTime();
    				return false;
    			}
    		</script>
    	</head>
    	<body>
    		<?php
    		if (isset($_POST['captcha'])){
    			if($_POST['captcha'] != $sTexte) echo 'captcha pas bon'; else echo 'captcha bon';
    		}
    		?>
    		<form method="post" action="" enctype="application/x-www-form-urlencoded">
    			<table>
    			<tr><td><img src="captcha.php" id="captcha" /></td><td><input type="button" onclick="regenerer('captcha');" value="regenerer"/></td></tr>
    			<tr><td>texte : </td><td><input name="captcha" type="text" size="30"/></td></tr>
    			<tr><td colspan="2">
    				<input type="submit" value="Envoyer"/></td></tr>
    			</table>
    		</form>
    	</body>
    </html>

  6. #6
    Membre Expert
    Avatar de laurentSc
    Homme Profil pro
    Webmaster débutant perpétuel !
    Inscrit en
    Octobre 2006
    Messages
    10 508
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Webmaster débutant perpétuel !
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2006
    Messages : 10 508
    Billets dans le blog
    1
    Par défaut
    Merci beaucoup

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Pop-up d'une dialog box a partir d'un bouton
    Par bobbyjack dans le forum MFC
    Réponses: 21
    Dernier message: 13/09/2005, 15h32
  2. redémarrer un prog à partir d'un bouton
    Par yokito dans le forum Langage
    Réponses: 5
    Dernier message: 06/09/2002, 13h19
  3. Réponses: 2
    Dernier message: 31/08/2002, 14h00
  4. Bmp pour boutons
    Par Fizgig dans le forum Outils
    Réponses: 5
    Dernier message: 22/08/2002, 10h56
  5. Afficher/Masquer un bouton comme IE 6
    Par benj63 dans le forum C++Builder
    Réponses: 3
    Dernier message: 29/07/2002, 13h12

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo