dynamic image display in src attribute of img tag

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • benoypaul
    New Member
    • May 2007
    • 28

    dynamic image display in src attribute of img tag

    Hi,

    I want to display images randomly in my new user registration form as like new user registration form of rediff (Verify your registration item in rediff). I know how to give php program as src attribute of img tag. Also know php code. If any one know this, please let me know.

    Thanks in Advance
  • kushalpuri
    New Member
    • May 2007
    • 1

    #2
    Hi

    The problem you are discussing here is "CAPTCHA" .you can find the code from phpclasses.org for this by searching with captcha

    regards,
    Kushal Puri

    Originally posted by benoypaul
    Hi,

    I want to display images randomly in my new user registration form as like new user registration form of rediff (Verify your registration item in rediff). I know how to give php program as src attribute of img tag. Also know php code. If any one know this, please let me know.

    Thanks in Advance

    Comment

    • benoypaul
      New Member
      • May 2007
      • 28

      #3
      Thanks.

      I got some php code for captcha. But it is not displaying image. code is given below

      form.php

      ?php
      session_start() ;
      ?>
      <HTML>
      <HEAD>
      <TITLE>PHP-CAPTCHA </TITLE>
      <META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=iso-8859-1\">
      </HEAD>
      <BODY onLoad="return focuson();">
      <script language="javas cript">
      function focuson()
      { document.form1. number.focus()}

      function check()
      {
      if(document.for m1.number.value ==0)
      {
      alert("Please enter your Category Name");
      document.form1. number.focus();
      return false;
      }
      }

      </script>
      <?php

      if(isset($_REQU EST['Submit'])){
      $key=substr($_S ESSION['key'],0,5);
      $number = $_REQUEST['number'];
      if($number!=$ke y){
      echo '<center><font face="Verdana, Arial, Helvetica, sans-serif" color="#FF0000" >
      Validation string not valid! Please try again!</font></center>';}
      else{
      echo '<center><font face="Verdana, Arial, Helvetica, sans-serif" color="#66CC00" >
      Your string is valid!</font></center>';}
      }
      ?>
      <form name="form1" method="post" action="form.ph p" onSubmit="retur n check();">
      <table width="342" align="center" cellspacing="0" bgcolor="#D4D0C 8">
      <tr>
      <td colspan="4" align="center"> <hr></td>
      </tr>
      <tr>
      <td width="8" align="center"> &nbsp;</td>
      <td width="330" align="right" valign="top">&n bsp;</td>
      <td width="330" align="right" valign="top">&n bsp;</td>
      <td width="2" align="center"> &nbsp;</td>
      </tr>
      <tr>
      <td align="center"> &nbsp;</td>
      <td align="right" valign="top">&n bsp;</td>
      <td align="right" valign="top">&n bsp;</td>
      <td align="center"> &nbsp;</td>
      </tr>

      <tr>
      <td align="center"> &nbsp;</td>
      <td align="center"> &nbsp;</td>
      <td align="center"> <img src="php_captch a.php"></td>
      <td align="center"> &nbsp;</td>
      </tr>
      <tr>
      <td align="center"> &nbsp;</td>
      <td align="center"> &nbsp;</td>
      <td align="center"> &nbsp;</td>
      <td align="center"> &nbsp;</td>
      </tr>
      <tr>
      <td align="center"> &nbsp;</td>
      <td align="center"> Please enter the string shown in the image in the form.<br></td>
      <td align="center"> <input name="number" type="text" id=\&quot;numbe r\&quot;></td>
      <td align="center"> &nbsp;</td>
      </tr>
      <tr>
      <td align="center"> &nbsp;</td>
      <td align="center"> &nbsp;</td>
      <td align="center"> &nbsp;</td>
      <td align="center"> &nbsp;</td>
      </tr>
      <tr>
      <td align="center"> &nbsp;</td>
      <td align="center"> &nbsp;</td>
      <td align="center"> <input name="Submit" type="submit" value="Submit"> </td>
      <td align="center"> &nbsp;</td>
      </tr>
      <tr>
      <td colspan="4" align="center"> <hr></td>
      </tr>
      </table>
      </form>
      </BODY>
      </HTML>



      php_captcha.php
      <?php
      session_start() ;

      $RandomStr = md5(microtime() );// md5 to generate the random string

      $ResultStr = substr($RandomS tr,0,5);//trim 5 digit

      $NewImage =imagecreatefro mjpeg("img.jpg" );//image create by existing image and as back ground

      $LineColor = imagecoloralloc ate($NewImage,2 33,239,239);//line color
      $TextColor = imagecoloralloc ate($NewImage, 255, 255, 255);//text color-white

      imageline($NewI mage,1,1,40,40, $LineColor);//create line 1 on image
      imageline($NewI mage,1,100,60,0 ,$LineColor);//create line 2 on image

      imagestring($Ne wImage, 5, 20, 10, $ResultStr, $TextColor);// Draw a random string horizontally

      $_SESSION['key'] = $ResultStr;// carry the data through session

      header("Content-type: image/jpeg");// out out the image

      imagejpeg($NewI mage);//Output image to browser

      ?>

      Comment

      Working...