Filter:   InfoImg
download antispam.php
Language: PHP
LOC: 30
Project Info
Virtual Photo Album(vphotoalb)
Server: SourceForge
Type: cvs
...alb\vphotoalb\html\include\
   .htaccess
   antispam.php
   constants.php
   db.php
   db_my.php
   db_pg.php
   db_schema.php
   faq_strings.php
   form.php
   functions.php
   globals.php
   html.php
   html_verifier.php
   ImageProcessing.php
   input.php
   mime.php
   originals.php
   PictureFinder.php
   queries.php
   read_exif_data.php
   read_tiff_data.php
   SearchParameters.php
   security.php
   strings.en.php
   strings.fr.php
   strings.php
   tables.php

<?php
/* Output mailto: links using nontrival javascript to thwart attempts by
 * spammers to retrieve email address from web pages.
 *
 * Written by: Chris Studholme
 * Copyright:  GPL (http://www.fsf.org/copyleft/gpl.html)
 * $Id: antispam.php,v 1.2 2003/12/21 00:26:13 cstudhol Exp $
 */


/* Returns the equivalent of '<a href="$url">$text</a>' but using javascript
 * that the client must execute to recreate the link.  If the client does not
 * support javascript, they will only see '$text'.
 */
function antispam_link($url,$text) {
  // encode entire tag
  $tag = "<a href=\"".$url."\">";

  // convert string to array of ordered numbers between 1 and 2 billion
  $tag_a = array();
  $max_inc = 1000000000 / 256 / strlen($tag);
  $prefix = 1000000000;
  for ($i=0; $i<strlen($tag); ++$i) {
    $prefix += 256 * mt_rand(1,$max_inc);
    $tag_a[] = $prefix + ord($tag[$i]);
  }

  // permute the array
  for ($i=0; $i<count($tag_a)-1; ++$i) {
    $j = mt_rand($i,count($tag_a)-1);
    $x = $tag_a[$i]; $tag_a[$i] = $tag_a[$j]; $tag_a[$j] = $x;
  }

  // javascript to create array, sort, and output tag
  $code = "a=Array(";
  $code .= $tag_a[0];
  for ($i=1; $i<count($tag_a); ++$i)
    $code .= ",".$tag_a[$i];
  $code .= "); a.sort(); for (i=0; i<a.length; ++i)".
    " document.write(String.fromCharCode(a[i]%256));";

  // complete javascript program
  return 
    "<script type=\"text/javascript\">".
    $code.
    "</script>".
    $text.
    "<script type=\"text/javascript\">".
    "document.write(\"</a>\");".
    "</script>";
}


?>