Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Convert mail to image (guard mail) from spam (See related posts)

// description of your code here

   1  
   2  <?php
   3  
   4  if(empty($_GET['sid'])){
   5  	//write html for image
   6  	$mail='example@domain.com';
   7      $text=base64_encode(serialize($mail));
   8  	echo '<img src="imgmail.php?sid='.$text.'" /><br/>';
   9  }else{
  10  	//show coded mail image
  11  	$text=$_GET['sid'];
  12  	header("Content-type: image/gif");	
  13  	echo mail_to_image($text);
  14  }
  15  
  16  function mail_to_image($ctext='no mail'){
  17  	$text=unserialize(base64_decode($ctext));
  18      $size=strlen($text)*8;
  19      $im = @imagecreate($size, 20) or die("Cannot Initialize new GD image stream");
  20      $background_color = imagecolorallocate($im, 255, 255, 255);
  21      $text_color = imagecolorallocate($im, 0, 0, 0);
  22      imagestring($im,3, 5, 5,  $text , $text_color);
  23      return imagegif($im);
  24  }
  25  ?> 

Comments on this post

bublik posts on Jul 10, 2007 at 04:59
Hide all links in page body
1 page example

   1  
   2  <?php
   3  
   4  if(empty($_GET['sid'])){
   5  	//write html for image
   6  	
   7  echo $body='<div>
   8  <h3>source page</h3>
   9  <a href="mailto:asdn@dddd.com">asdn@dddd.com</a>
  10  <a href="mailto:test@cccc.com">test@cccc.com</a>
  11  <a href="asdasd" >link</a></div>';
  12  
  13  //extract all mails
  14  preg_match_all("/<a[^>]+?href\s*=\s*[\"']?mailto:([^'\" >]+?)[ '\"]?\s*>/i",$body, $mails);
  15  	
  16  	while($mail=array_shift($mails[1])){
  17      	$text=base64_encode(serialize($mail));
  18  		$img_mail= '<img src="imgmail.php?sid='.$text.'" />';
  19  		
  20  	$body = preg_replace("/<a[^>]+?href\s*=\s*[\"']?mailto:(".$mail.")[ '\"]?\s*>(.*)<\/a>/i", $img_mail, $body);	
  21  	}
  22  	
  23  	echo '<h3>New body<h3>'.$body;
  24  }else{
  25  	//show coded mail image
  26  	$text=$_GET['sid'];
  27  	header("Content-type: image/gif");	
  28  	echo mail_to_image($text);
  29  }
  30  
  31  function mail_to_image($ctext='no mail'){
  32  	$text=unserialize(base64_decode($ctext));
  33      $size=strlen($text)*8;
  34      $im = @imagecreate($size, 20) or die("Cannot Initialize new GD image stream");
  35      $background_color = imagecolorallocate($im, 255, 255, 255);
  36      $text_color = imagecolorallocate($im, 0, 0, 0);
  37      imagestring($im,3, 5, 5,  $text , $text_color);
  38      return imagegif($im);
  39  }
  40  ?> 
  41  

You need to create an account or log in to post comments to this site.


Click here to browse all 5355 code snippets

Related Posts