Some PHP programs I have written

a_class.php

TOC

<?php
setcookie("a_class.php","a_class.php",time()+333333);
setcookie("class","everybody loves class",time()+333333);
setcookie("notenoughclasses","and nobody gets enough education",time()+333333);
$set_cookie="si";
#
# this session id stuff is for people who refuse to use cookies
# it keeps track of them on the server side instead of with
# cookies on their PC.
# the session lasts until they close their browser window
#
$mysessionid=session_start();
#
# count the number of times they have been here 
# during this browser session
# when they close the browser this data goes away
# so at the MCC site this data will 
# probably last no longer then an hour or two
# if that long.
# but on a home or office computer that is not 
# turned off the session could last days or weeks
#
if ( $_SESSION['magic hobo class.php'] == '') {
   $_SESSION['magic hobo class.php']=1;
}
else {
   $_SESSION['magic hobo class.php']++;
}
?>
<html>
You don't use PUSH(@array, value) in PGP like you do in PERL
<p>
In PGP you use array_push(array, value)
<p>
<table border=1>
<tr>
<td>
<?php
#
# create an empty array
#
$foo=array();
#
# push some values on it
#
array_push($foo, "Mikey Mouse");
array_push($foo, "George W. Bush");
array_push($foo, "Saddam H");
array_push($foo, "Crazy Mike");
array_push($foo, "Richard M. Nixon");
#
# dump the array
echo "Values on the array \$foo";
echo "<blockquote>";
foreach ($foo as $slot) {
   echo "$slot<br>";
}
echo "</blockquote>";
?>
</td>

</tr>
<tr>
<td>
It says you can use the function 
<blockquote>
serialize()
</blockquote> 
to convert
an array to a flat item that can be saved to a file.
<p>
And convert the flat item back to an array with the
<blockquote>
unserialize()
<blockquote>
function.
<p>
Lets try that!
</td>
</tr>
<tr>
<td>
<?php
#
# convert the array $foo to a flatarray what ever that is
#
$flatarray=serialize($foo);
echo "\$flatarray is<blockquote><pre>$flatarray</pre></blockquote>";
?>
</td>
</tr>
<tr>
<td>
<?php
#
# now convert the flatarray back to an array and display
#
$reinflatedarray=unserialize($flatarray);
echo "the reinflated array is";
echo "<blockquote>";
foreach($reinflatedarray as $slot) {
   echo "$slot<br>";
}
echo "</blockquote>";
?>
</td>
</tr>
</table>


























<p>
Convert URL parameters on CGI's to the %xx value ie:
<blockquote>
movie_program.cgi?movie=micky mouse and the seven dwarfs
</blockquote>
won't cut it and must be coded as
<blockquote>
movie_program.cgi?movie=micky+mouse+and+the+seven+dwarfs
</blockquote>
Now I have one question. What is the difference between
<blockquote>
<table border="3">
<tr valign="top">
<td>
rawurlencode()
</td>
<td>
urlencode();
</td>
</tr>
<tr valign="top">
<td>
rawurldecode()
</td>
<td>
urldecode()
</td>
</tr>
</table>
</blockquote>
The answer is rawurlencode() converts spaces to '%20',<br>
while urlencode() converts spaces to '+'.<br>
I wrote a table that follows to generate all 255 ASCII values<br>
and they are all the same except for a space.
<p>
Perhaps it does different stuff for the UNI-CODE character set.
<p>
<table border=9>
<tr valign="top">
<?php
#
# convert a URL to the coded method
#
$url="micky mouse and the seven dwarfs + & % \$ _-x";
echo "<td>before encodeing<br>&nbsp;&nbsp;$url</td>";
$codedurl=urlencode($url);
echo "<td>after encodeing with the function<br>&nbsp;&nbsp;\$codedurl=urlencode(\$url);<br>we have<br>&nbsp;&nbsp;$codedurl";
echo "<p>and we can use it like this<br>&nbsp;&nbsp;move_cgi.php?movie=$codedurl";
echo "<p>";
echo "<hr>";
echo "<p>";
echo "now lets try the same thing with<br>&nbsp;&nbsp;&nbsp;rawurlencode()<br>instead of<br>&nbsp;&nbsp;&nbsp;urlencode()";
echo "<p>";



$url="micky mouse and the seven dwarfs + & % \$ _-x";
#
# use rawurlencode() instead of urlencode()
#
$codedurl=rawurlencode($url);
echo "after rawencoding with the function<br>&nbsp;&nbsp;\$codedurl=rawurlencode(\$url);<br>we have<br>&nbsp;&nbsp;$codedurl";
echo "<p>";
echo "In this example urlencode() converts spaces to '+'<br>";
echo "while rawurlencode() converts spaces to '%20'<p>";
echo "In a box that follows we will compare the output of rawurlencode() vs urlencode()";
echo "</td>";







$url="micky mouse and the seven dwarfs + & % \$ _-x";
$codedurl=urlencode($url);




#
# convert a coded URL back to ascii text
#
$decodedurl=urldecode($codedurl);
echo "</tr><tr><td colspan=\"2\">we can also convered a coded URL such as this<blockquote>$codedurl</blockquote>back to ascii text with<blockquote>\$decodedurl=urldecode(\$codedurl);</blockquote>which gives us<blockquote>$decodedurl</blockquote></td>";
?>
</tr>




<tr valign="top">
<td colspan="2">
In this example we will compare the differences of<blockquote>rawurlencode()</blockquote> vs<blockquote>urlencode()</blockquote>
<p>
And it looks like the ONLY difference is for a SPACE<br>
At least for ASCII.<br>
It may be different for the UNICODE character set
<p>
<table border=9>
<tr>
<td>







<table border=1>
<?php
$c=0;
for($i=0;$i<16;$i++) {
   echo "<tr>";
   for($k=0;$k<16;$k++) {
      #$cc=ifx_get_char($c);
      #$cc=(char)$c;
      #$cc=decbin($c);
      #
      # looks like both of these do it
      # but the output is destroyed when it gets displayed as HTML
      #
      #            $x=chr($c);
      #            $x=sprintf("%c",$c);
      #
      # convert the decimal number to binary
      # then do both a
      #        urlencode()
      # and a 
      #        rawurlencode()
      #
      # and it turns out the only difference for ASCII
      # is that urlencode() spaces to '+'
      # while the rawurlencode() converts spaces to '%20'
      #
      $uu=urlencode(chr($c));
      $rr=rawurlencode(chr($c));
      if ($uu != $rr) {
         echo "<td>";
         echo "<nobr>not raw=$uu</nobr><br><nobr>raw=$rr</nobr>";
         echo "</td>";
      }
      else {
         echo "<td>";
         echo "&nbsp;";
         echo "</td>";
      }
     $c++;
   }
   echo "</tr>";
}
?>
</table>




</td>
<td>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</td>


<td>
Here are the values that are converted by urlencode() and rawurlencode()<br>
for the ASCII character set<br>
Who knows what happens when you have UNICODE











<table border=1>
<?php
$c=0;
for($i=0;$i<16;$i++) {
   echo "<tr>";
   for($k=0;$k<16;$k++) {
      #$cc=ifx_get_char($c);
      #$cc=(char)$c;
      #$cc=decbin($c);
      #
      # looks like both of these do it
      # but the output is destroyed when it gets displayed as HTML
      #
      #            $x=chr($c);
      #            $x=sprintf("%c",$c);
      #
      # convert the decimal number to binary
      # then do both a
      #        urlencode()
      # and a 
      #        rawurlencode()
      #
      # and it turns out the only difference for ASCII
      # is that urlencode() spaces to '+'
      # while the rawurlencode() converts spaces to '%20'
      #
      $cc=chr($c);
      $uu=urlencode(chr($c));
      $rr=rawurlencode(chr($c));
      #$binary=is_binary($cc);
      $binary="";
      if ($c > 32 && $c < 127) {
         $binary="$cc=";
      }
      if ($cc != $uu) {
         echo "<td style=\"background-color:#ffff00;\">";
         if ($c == 32) {
            echo "<nobr>SP $uu or $rr</nobr>";
         }
         else {
            echo "<nobr>$binary $uu</nobr>";
         }
         echo "</td>";
      }
      else {
         echo "<td  style=\"background-color:#ffffff;\">";
         echo "$cc";
         echo "</td>";
      }
     $c++;
   }
   echo "</tr>";
}
?>
</table>









</td>





</tr>
</table>















</td>
</tr>
</table>
<p>





In PERL you use @array=split(' ',"big long string")
to tokenize a string.
<p>
In PHP you use explode(delimiter, string)
<p>
<?php
$string="Fi fi fo fum I smell the blood of an English man";
?>
<table border="6">
<tr valign="top">
<?php
 echo "<td>string<p>&nbsp;&nbsp;&nbsp;$string</td>";
 #
 # use 
 #     explode(delimiter, string)
 #         instead of 
 #     split(delimiter, string)
 $array=explode(' ',$string);
 echo "<td>";
 echo "each word of tokenized string<p>";
 foreach($array as $foo) {
    echo "&nbsp;&nbsp;&nbsp;$foo<br>";
 }
 echo "</td>";
?>


</tr>
</table>
<p>








Looping thru a string with $string{$char}<br>
$char starts at zero
<table border=1>
<tr valign="top">
<?php
 #
 # create a string
 #
 $string="frozen frogs, white stags and other stuff";
 #
 # display the string
 #
 echo "<td>The string is <p>$string</td>";
 #
 # display the length of the string
 #
 $length=strlen($string);
 echo "<td>Use strlen(\$string) to get the length of the string which is $length bytes.</td>";
 echo "<td>";
 #
 # get each character in the string and display it
 #
 echo "You can use \$letter=\$string{\$char} to reference any given character<p>";
 for($i=0;$i<($length/2);$i++) {
    $letter=$string{$i};
    echo "&nbsp;&nbsp;&nbsp;$letter<br>";
 }
 echo "</td>";
 echo "<td>";
 #
 # get a bunch of different substrings of the string
 # starting with a 1 byte substring going to a long substring
 #
 echo "You can use substr(\$string,start,length) to get a substring<p>";
 for($i=0;$i<($length/2);$i++) {
    $letters=substr($string,$i,($i+1));
    echo "&nbsp;&nbsp;&nbsp;$letters<br>";
 }
 echo "</td>";
?>
</tr>
</table>
<p>





<?php
function zargexample()
{
 echo "I'm function ".__function__."<br>";
 $x=func_num_args();
 echo "I was passed $x args<p>";
 echo "\$args=func_num_args(); is used to get the args<p>";
 if ($x > 0) {
    echo "Dumping args with \$arg=func_get_arg(\$n)<br>";
    echo "And saving them as a hash<br>";
    for ($i=1;$i<=$x;$i++) {
       $arg=func_get_arg($i-1);
       $hash[$arg]=$i;
       echo "&nbsp;&nbsp;$arg<br>";
    }
    echo "<br>Dumping args with \$array=func_get_args()<br>";
    $args=func_get_args();
    foreach($args as $foo) {
       echo "&nbsp;&nbsp;$foo<br>";
    }
    echo "<br>Dumping the hash with print_r(\$hash)<br>";
    print_r($hash);
    echo "<br>";
    echo "<br>Dumping the hash keys gotten with array_keys(\$hash)<br>";
    $hash_keys=array_keys($hash);
    foreach($hash_keys as $foo) {
       echo "&nbsp;&nbsp;key=$foo<br>";
    }

    echo "<br>Dumping the hash with foreach (\$hash as \$key=>\$data)<br>";
    foreach($hash as $key=>$data) {
       echo "&nbsp;&nbsp;key=$key data=$data<br>";
    }
 }
 else {
    echo "no Arguments to list!!!!";
 }
 return;
}
?>
<table border=22>
<tr valign="top">
<td>
<?php
zargexample();
?>
</td>
<td>
<?php
zargexample('a');
?>
</td>
<td>
<?php
zargexample('fe','fi','fo','fum','you','stink');
?>
</td>
</tr>
</table>
<p>








<?php
function fefifofum($x) 
{
$x=99;
return;
}
function fumfofife(&$x) 
{
$x=99;
return;
}
?>
<table border="9">
<tr>
<td>
&nbsp;
</td>
<td>
by REFERENCE
</td>
</tr>
<tr valign="top">
<td>
<?php
$x=3;
echo "x=$x before<br>";
echo "fefifofum(\$x);<br>";
fefifofum($x);
echo "x=$x after<br>";
?>
<p>
function fefifofum($x) <br> 
&nbsp;{<br> 
&nbsp;&nbsp;&nbsp;$x=99;<br> 
&nbsp;&nbsp;&nbsp;return;<br> 
&nbsp;}
</td>
<td>
<?php
$x=3;
echo "x=$x before<br>";
echo "fumfofife(\$x);<br>";
fumfofife($x);
echo "x=$x after<br>";
?>
<p>
function fumfofife(<b>&</b>$x) <br> 
&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;$x=99;<br>
&nbsp;&nbsp;&nbsp;&nbsp;return;<br>
&nbsp;}
</td>
</tr>
</table>
<p>




<table border="4">
<tr valign="top">
<td>
<table>
<tr valign="top" border="1">
<td>
Hi world
</td>
<td>
wh1t3st4g<br>
whitestag
</td>
<td>
<?php
$foo="frozenfrog";
#
#  this trick also works in PERL
# {$foo}s - a way to concatenate variables with text
# ${foo}s - either way works
#
echo "{$foo}s<br>";
echo "${foo}s</td>";
$foo="fr0z3nfr0g";
echo "<td>";
echo "{$foo}s<br>";
echo "${foo}s</td>";

?>
</tr>
</table>
</td>
<td>
the old<br> 
echo "{$foo}s";
<br>
echo "${foo}s"
<br>
trick
<p>
</td>
<td>
<a href="phpinfo.php">phpinfo(); </a>
</td>
</tr>
</table>
<p>
Some debugging constants!!!!
<blockquote>
<?php
function foo() {
    echo "__function__=".__function__."<br>";
}
?>
<?php
echo "__file__=".__file__."<br>";
echo "__line__=".__line__."<br>";
echo "__function__=".__function__."<br>";
foo();
echo "__class__=".__class__."<br>";
echo "__method__=".__method__."<br>";
?>
</blockquote>


Some other constants!!!!
<blockquote>
<?php
echo "M_PI=".M_PI."<br>";
echo "M_PI_2=".M_PI_2."<br>";
echo "M_PI_4=".M_PI_4."<br>";
echo "M_1_PI=".M_1_PI."<br>";
#echo "M_SQRTPI=".M_SQRTPI."<br>"; # the book lied! this doesn't work!!!!
echo "M_2_SQRTPI=".M_2_SQRTPI."<br>";
echo "M_SQRT2=".M_SQRT2."<br>";
#echo "M_SQRT_3=".M_SQRT_3."<br>"; # the book like! this doesn't work!
?>
</blockquote>









<table border="5">
<tr valign="top">
<td>



Long strings like in UNIX are called HEREDOCS, here document, here-document, and here docs<br>
<blockquote>
foo &lt;&lt;HOTPOOP<br>
data<br>
data<br>
data<br>
HOTPOOP
</blockquote>
</td>
<td>
<?php
$longstring=<<<HOTPOOP
Long strings like in UNIX are called heredocs, here document, here-document, and here docs<br>
<blockquote>
foo &lt;&lt;HOTPOOP<br>
data<br>
data<br>
data<br>
xHOTPOOP
</blockquote>
HOTPOOP;

echo $longstring
?>
</td>
<td>
And this is the PHP that generated the prior long string<br>
Note the TRIPLE &lt;&lt;&lt;
<blockquote>
&lt;?php<br>
$longstring=&lt;&lt;&lt;HOTPOOP<br>
Long strings like in UNIX are called HERE DOCS or heredocs, here document, here-document, and here docs<br>
&lt;blockquote&gt;<br>
foo &lt;&lt;HOTPOOP&lt;br&gt;<br>
data&lt;br&gt;<br>
data&lt;br&gt;<br>
data&ltbr&gt;<br>
&lt;/blockquote&gt;<br>
HOTPOOP;<br>
echo $longstring<br>
?&gt;
</blockquote>
</td>
</tr>
</table>
<p>
PHP elseif is different then PERL elsif
<p>
<blockquote>
<table>
<tr valign="top">
<td>
  echo $i;<br>
  if ($i &gt; 1 ) { <br>
&nbsp;&nbsp;&nbsp;     echo " less then 1";<br>
  } <br>
  elseif ($i &gt;=1 && $i &lt;= 3 ) {<br>
&nbsp;&nbsp;&nbsp;     echo " betweem 1 and 3";<br>
  } <br>
  elseif ($i &gt;=4 && $i &lt;= 7 ) {<br>
&nbsp;&nbsp;&nbsp;     echo " betweem 4 and 7";<br>
  } <br>
  elseif ($i &gt;=8 && $i &lt;= 10 ) {<br>
&nbsp;&nbsp;&nbsp;     echo " betweem 8 and 10";<br>
  }<br>
  else {<br>
&nbsp;&nbsp;&nbsp;     echo " greater then 10";<br>
  } <br>
  echo "&lt;br&gt;";
</blockquote>
</td>
<td>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</td>
<td>
<?php
for($i=0;$i<15;$i++) {
  foofoo($i);
}
function foofoo($i) {
  echo $i;
  if ($i < 1 ) {
     echo " less then 1";
  } 
  elseif ($i >=1 && $i <= 3 ) {
     echo " betweem 1 and 3";
  } 
  elseif ($i >=4 && $i <= 7 ) {
     echo " betweem 4 and 7";
  } 
  elseif ($i >=8 && $i <= 10 ) {
     echo " betweem 8 and 10";
  }
  else {
     echo " greater then 10";
  } 
  echo "<br>";
  return;
}
?>
</td>
</tr>
</table>
<p>
include file;<br>
&nbsp;&nbsp;&nbsp;vs<br>
include_once file;
<p>
<table border=1>
<tr valign="top">
<td>
<b>include</b> file;
</td>
<td>
<b>include_once</b> file;
</td>
</tr>
<tr valign="top">
<td>
&lt;?php<br>
include "hiworld.php";<br>
include "hiworld.php";<br>
include "hiworld.php";<br>
include "hiworld.php";<br>
include "hiworld.php";<br>
?&gt;
<p>
<hr>
<?php
include "hiworld.php";
include "hiworld.php";
include "hiworld.php";
include "hiworld.php";
include "hiworld.php";
?>
</td>
<td>
&lt;?php<br>
include_once "hiworld2.php";<br>
include_once "hiworld2.php";<br>
include_once "hiworld2.php";<br>
include_once "hiworld2.php";<br>
include_once "hiworld2.php";<br>
?&gt;
<p>
<hr>
<?php
include_once "hiworld2.php";
include_once "hiworld2.php";
include_once "hiworld2.php";
include_once "hiworld2.php";
include_once "hiworld2.php";
?>

</td>
</tr>
</table>


</html>

../curl_ftp_stuff/a_curl_stuff.php

TOC

<h3 align="center">CURL - Client URL Request Library</h3>
<center>
<table border=0>
<tr>
<td>
<SPAN style="font-size:250%">C</span><SPAN style="font-size:200%">lient</span>
</td>
<td>
<SPAN style="font-size:250%">U</span><SPAN style="font-size:200%">RL</span>
</td>
<td>
<SPAN style="font-size:250%">R</span><SPAN style="font-size:200%">equest</span>
</td>
<td>
<SPAN style="font-size:250%">L</span><SPAN style="font-size:200%">ibrary</span>
</td>
</tr>
<tr align="center">
<td>
<SPAN style="font-size:250%">C</span>
</td>
<td>
<SPAN style="font-size:250%">U</span>
</td>
<td>
<SPAN style="font-size:250%">R</span>
</td>
<td>
<SPAN style="font-size:250%">L</span>
</td>
</tr>
</table>
</center>
You can do a whole bunch of stuff in CURL.
I am only using CURL to do FTP's.
<p>
At the CURL web site they say
<blockquote>
curl is a command line tool for transferring files with URL syntax, 
supporting FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, LDAP, LDAPS and FILE. 
</blockquote>
Their documentation seemed to suck.
Maybe that is because their documentation
is for the command line version and I
am using the PHP version.
The documentation at <a href="http://php.net">http://php.net</a>
was much better.
And it talks in PHP.
<p>
Curl Documentation
<table border=1>
<tr valign="top">
<td>
<b><i>Good Documentation</b></i>
<blockquote>
<a href="http://us3.php.net/curl">http://us3.php.net/curl</a><br>
<a href="http://us3.php.net/curl-setopt">http://us3.php.net/curl-setopt</a>
</blockquote>
</td>
<td>
<b><i>This documentation sucks!!!</b></i><br>
It's from the idiots who wrote<br>
PHP in a Nutshell
<blockquote>
<a href="http://curl.haxx.se/">curl.haxx.se</a><br>
<a href="http://curl.haxx.se/libcurl/c/curl_easy_setopt.html">curl.haxx.se/.....</a>
</blockquote>
</td>
</tr>
</table>
<ul>
<li>these are done on MY web site
   <ul>
      <li><a href="ftp_list_my_site.php">get a listing of my site</a>
      <li><a href="copy_a_file.php">ftp a file to my site</a>
      <li><a href="copy_g_file.php">ftp a file to my other site</a>
      <li><a href="text_file_to_ftp.txt">a text file to ftp with curl</a>


   </ul>
<li>these are done on the site ftp.gnu.org
   <ul>
      <li><a href="simple_ftp_to_gnu.php">simple ftp to ftp.gnu.org</a>
      <li><a href="verbose.php">simple ftp - with VERBOSE turned on for debugging</a><br>
          &nbsp;&nbsp;&nbsp;looks like <b>VERBOSE</b> doesn't work like defined!<br>
          &nbsp;&nbsp;&nbsp;it all goes to the <b>STDOUT</b>, not the <b>HTML</b>
      <li><a href="ftp_to_gnu.php">ftp to ftp.gnu.org</a> as userid:anonymous@ftp.gnu.org<br>
               &nbsp;&nbsp;&nbsp;again in the book they got it backwards!<br>
               &nbsp;&nbsp;&nbsp;the syntax for the ftp command is<br>
               &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ftp://user:password@host:port/path 
      <li><a href="ftp_to_gnu_wrong_password.php">ftp to ftp.gnu.org with a bad password</a> as wrong_password:your@email.com
   </ul>
</ul>

../a_numbers.php

TOC

<html>
<?php 
   $zheight=50;
   #
   # ztweek is for the space on the right of the number
   #

   #
   # for a clear blackground set clear to something

   $clear='';
   $clear='xxx';

   $ztweek=8;
   for ($i=0;$i<10;$i++) {
      print "<img src=\"a_square_2p.php?text=$i&zheight=$zheight&ztweek=$ztweek&clear=$clear\"><br>";
   }
?> 
</html>



../a_numbers3.php

TOC

<html>
<?php 
   $zheight=50;
   #
   # ztweek is for the space on the right of the number
   #

   #
   # for a clear blackground set clear to something

   $clear='';
   #$clear='xxx';

   $ztweek=8;
   for ($i=0;$i<10;$i++) {
      print "<img src=\"a_square_3p.php?text=$i&zheight=$zheight&ztweek=$ztweek&clear=$clear\"><br>";
   }
?> 
</html>



../a_square.php

TOC

<script language="php">
 $xxwidth=50;
 $xxheight=50;
 #
 # create the image
 #
 $image=ImageCreate($xxwidth, $xxheight);
 #
 # set the R,G,B background color of the imagee (purple)
 #
 $background_color=ImageColorAllocate($image,255,0,255);
 #
 # define RGB black as a color used on the image
 #
 $black=ImageColorAllocate($image,0,0,0);
 #
 # copy the color $black into the image between 0,0 and 50,50
 #
 #ImageFilledRectangle($image,0,0,$xxwidth,$xxheight,$black);
 #
 # convert the $number to an image
 # copy each digit of the number to our image from left to right
 #
 $next_x=0;
 #for ($i=0;$i<strlen($number);$i++) {
 # $thisdigit=substr($number,$i,1);
 # $zfile=$ifiles[$thisdigit];
 # $zhandle=$gif[$thisdigit];
 # #
 # # copy the gif image to our image
 # #
 # $rc=imagecopy ( $image, $zhandle, 
 #                 $next_x, ($xxheight - $gif_height[$thisdigit]) , 
 #                 0, 0,
 #                 $gif_width[$thisdigit],$xxheight);
 # $rc=$rc?"true":"failed";
 # $next_x=$next_x+ $gif_width[$thisdigit];
 #}
 #
 # return the image
 #

 #imagefttext ($image, 10, 0, 5, 5, $black, 'times', 'foo' );
 imagechar ( $image, 5, 10, 10, 'a', $black );




$text = 'Testing...';
$font = 'arial.ttf';
#imagettftext($image, 20, 0, 11, 10, $black, $font, $text);

#// Add the text
#imagettftext($image, 20, 0, 10, 10, $black, $font, $text);





 header("Content-Type: image/png");
 ImagePNG($image);
</script> 

../a_square_2.php

TOC

<script language="php">
 $xxwidth=50;
 $xxheight=60;
 $font_size=40;
 $angle_of_characters=0;
 $y_pixels_below_top=5;
 $x_pixels_to_right=2;
 $xxheight=$font_size+($y_pixels_below_top*2);
 $xxwidth=($x_pixels_to_right*2)+($font_size);
 #
 # create the image
 #
 $image=ImageCreate($xxwidth, $xxheight);
 #
 # set the R,G,B background color of the imagee (purple)
 #
 $background_color=ImageColorAllocate($image,255,0,255);
 #
 # define RGB black as a color used on the image
 #
 $black=ImageColorAllocate($image,0,0,0);
 #
 # copy the color $black into the image between 0,0 and 50,50
 #
 #ImageFilledRectangle($image,0,0,$xxwidth,$xxheight,$black);
 #
 # convert the $number to an image
 # copy each digit of the number to our image from left to right
 #
 $next_x=0;
 #for ($i=0;$i<strlen($number);$i++) {
 # $thisdigit=substr($number,$i,1);
 # $zfile=$ifiles[$thisdigit];
 # $zhandle=$gif[$thisdigit];
 # #
 # # copy the gif image to our image
 # #
 # $rc=imagecopy ( $image, $zhandle, 
 #                 $next_x, ($xxheight - $gif_height[$thisdigit]) , 
 #                 0, 0,
 #                 $gif_width[$thisdigit],$xxheight);
 # $rc=$rc?"true":"failed";
 # $next_x=$next_x+ $gif_width[$thisdigit];
 #}
 #
 # return the image
 #
 #imagechar ( $image, 5, 10, 10, 'a', $black );
 #imagettftext($image, 20, 10, 11, 10, $black, "ARIALN", "testing");
 #imagettftext($image, 'size', 'rotation', 'x', 'y', $black, "arial", "testing");
 #imagettftext($image, 30, 0, 1, 40, $black, "arial", "1");
 #imagettftext($image, $font_size,  $angle_of_characters, 4, 40, $black, "arial", "1");
 imagettftext($image, $font_size,  $angle_of_characters,  $x_pixels_to_right, $font_size+$y_pixels_below_top, $black, "arial", "1");

 
 header("Content-Type: image/png");
 ImagePNG($image);
</script> 

../a_square_2p.php

TOC

<script language="php">
 #
 # to use this you have to download a windows or 
 # any other TTF or True Text Font file to THIS subdirectory
 #
 # in this case i downloaded the file
 #         arial.ttf
 # to this subdirectory and and using it via
 #         'arial'
 # to find all the true text font files on a windows machine go
 #
 #         c:
 #         cd \windows\Fonts
 #         dir *.ttf
 #


 #
 # set the height and width of the image
 #
 $krud=$_GET['zheight'];
 if ($krud == '' ) {
    $font_size=40;
 }
 else {
    $font_size=$krud;
 }


 $krud=$_GET['ztweek'];
 if ($krud == '' ) {
    $x_tweek=8;
 }
 else {
    $x_tweek=$krud;
 }


 #
 # you can have the characters rotated at an angle
 #
 $angle_of_characters=0;


 #
 # set the space above, below and to the left and right of the charcters
 #
 $y_pixels_below_top=5;
 $x_pixels_to_right=2;

 #
 # caculate size of image based on above BS
 #
 $xxheight=$font_size+($y_pixels_below_top*2);
 $xxwidth=($x_pixels_to_right*2)+($font_size)-$x_tweek;


 #
 # get a parm telling us what number to generate
 #
 $text=$_GET['text'];
 if ($text == '' ) {
    $text='1';
 }


 #
 # create the image
 #
 $image=ImageCreate($xxwidth, $xxheight);


 #
 # background color of the image in RGB format
 #
 $background_color=ImageColorAllocate($image,255,0,255);


 #
 # make the background transparent???
 #
 $krud=$_GET['clear'];
 if ($krud != '' ) {
    imagecolortransparent($image,$background_color);
 }


 #
 # color of the letters to be printed
 #
 $black=ImageColorAllocate($image,0,0,0);


 #
 # dont anti-alias text!!!!
 #$black=$black*-1;





 #
 #
 # return the image
 #
 imagettftext($image, $font_size,  
                      $angle_of_characters,  
                      $x_pixels_to_right, 
                      $font_size+$y_pixels_below_top, 
                      $black, 
                      "arial", 
                      $text);


 #
 # print the stupid header
 # this is an IMAGE so we need an IMAGE header
 #
 header("Content-Type: image/png");
 ImagePNG($image);
</script> 

../a_square_3p.php

TOC

<script language="php">
 #
 # to use this you have to download a windows or 
 # any other TTF or True Text Font file to THIS subdirectory
 #
 # in this case i downloaded the file
 #         arial.ttf
 # to this subdirectory and and using it via
 #         'arial'
 # to find all the true text font files on a windows machine go
 #
 #         c:
 #         cd \windows\Fonts
 #         dir *.ttf
 #


 #
 # set the height and width of the image
 #
 $krud=$_GET['zheight'];
 if ($krud == '' ) {
    $font_size=40;
 }
 else {
    $font_size=$krud;
 }


 $krud=$_GET['ztweek'];
 if ($krud == '' ) {
    $x_tweek=8;
 }
 else {
    $x_tweek=$krud;
 }


 #
 # you can have the characters rotated at an angle
 #
 $angle_of_characters=0;


 #
 # set the space above, below and to the left and right of the charcters
 #
 $y_pixels_below_top=5;
 $x_pixels_to_right=2;

 #
 # caculate size of image based on above BS
 #
 $xxheight=$font_size+($y_pixels_below_top*2);
 $xxwidth=($x_pixels_to_right*2)+($font_size)-$x_tweek;


 #
 # get a parm telling us what number to generate
 #
 $text=$_GET['text'];
 if ($text == '' ) {
    $text='1';
 }


 #
 # create the image
 #
 $image=ImageCreate($xxwidth, $xxheight);


 #
 # background color of the image in RGB format
 #
 #$background_colorx=ImageColorAllocate($image,0,255,255);

 $background_color=ImageColorAllocate($image,255,0,255);


    #imagecolortransparent($image,$background_color);

 #
 #I guessed it was being filed with the wrong color
 # my guess was wrong!!!!!
 #
 #imagefilledrectangle($image,0,0,$xxwidth, $xxheight, $background_color);


 #
 # make the background transparent???
 #
 $krud=$_GET['clear'];
 if ($krud != '' ) {
    imagecolortransparent($image,$background_color);
    imagecolortransparent($image,$background_color);

 }


 #
 # color of the letters to be printed
 #
 $black=ImageColorAllocate($image,0,0,0);
 # use RED instead of black
 $black=ImageColorAllocate($image,255,0,0);



 #
 # dont anti-alias text!!!!
 #$black=$black*-1;





 #
 #
 # return the image
 #
 imagettftext($image, $font_size,  
                      $angle_of_characters,  
                      $x_pixels_to_right, 
                      $font_size+$y_pixels_below_top, 
                      $black, 
                      "arial", 
                      $text);


 #
 # print the stupid header
 # this is an IMAGE so we need an IMAGE header
 #
 #header("Content-Type: image/png");
 #ImagePNG($image);
 header("Content-Type: image/gif");
 ImageGIF($image);
 #ImageGIF($image,"images_for_counters/homeless".$text.".gif");
</script> 

../add_ceweekly_email.php

TOC

<?php
 include "0_php_functions.php";
 $invalid_email_addresses="kruddyemail@address.
          xx.xx
'xxx@xxx.com'
\"xxx@xxx2.com\"
,xxx@xxx3.com,
xxx@xxx4.com,
,xxx@xxx5.com
@xxxxxxxxxxxxx.xxx
@xxxxxxxxxxxxx.xxx.com
@xxxxxxxxxxxxx
         @xxxxxxxxxxxxx
xxxxx.xxx@
              xxxx.xxxxx@xxxxx@xx               
xxxxxxxxxxxxxx.xxxx
                 yyyyyyy.yyyyyyyyyyyyyyyy                
             xxxx.xxxx
             xxxx.xxxx.
             .xxxx.xxxx
             .xxxx.xxxx
             .xxxx.@xxxx
             .xxxx@.xxxx
xx..xx
xx.xx.xx.x..xxxx.com
 
frog.cat@badline  
       
xxxxxxx.xxxx
zzzzzzzzzzzzzzzzzzzzzzzzzzz";
 #
 # get the ip address so we can tell where people came from
 #
 $my_ip_address=${REMOTE_ADDR};
 $emails=$_POST["emails"];
 $email_array=array();
?>





<?php






function remove_leading_trailing_spaces($name) {
  #
  # remove leading spaces
  #
  $name=preg_replace("/^ */","",$name);
  #
  # remove trailing spaces
  #
  $name=preg_replace("/ *\$/","",$name);
  return $name;
}


function clean_for_html($data) {
   #
   # remove < > because they can screw up HTML
   #
   $data=preg_replace("/[<>]/","",$data);
   #
   # remove junk that annoys mySQL
   #
   $data=clean_for_sql($data);
   return $data;
}

function clean_for_sql($data) {
   #
   # remove '"\ - they screw up SQL
   #
   $data=preg_replace("/['\"]/","",$data);
   $data=preg_replace("/\\\/","",$data);
   #
   # remove leading spaces
   #
   $data=preg_replace("/^ */","",$data);
   #
   # remove trailing spaces
   #
   $data=preg_replace("/ *$/","",$data);
   #
   # remove extra spaces
   #
   $data=preg_replace("/  */"," ",$data);
   $data=preg_replace("/ *$/","",$data);



   return $data;
}



function validate_email_address ($email) {
   $rc="";
   #
   # the email address must contain at least one period or dot
   #
   if (!preg_match("/\./",$email)) {
      echo "error doesnt have a period<br>";
      $rc.="error does not contain a period (.)<br>";
   }
   #
   # the email address must not contain any spaces
   #
   if (preg_match("/ /",$email)) {
      echo "error contains spaces<br>";
      $rc.="error contains one or more spaces<br>";
   }
   #
   # the email address must not begin or end with an @
   #
   if (preg_match("/^@/",$email)) {
      echo "error begins with an @<br>";
      $rc.="error begins with @<br>";
   }
   if (preg_match("/@$/",$email)) {
      echo "error ends with an @<br>";
      $rc.="error ends with @<br>";
   }
   #
   # the email address must contain only one @
   #
   if (preg_match("/@.*@/",$email)) {
      echo "error ends contains more then one @<br>";
      $rc.="error contains more then one @<br>";
   }
   #
   # the .@ or @. is illegal
   #
   if (preg_match("/\.@/",$email)) {
      echo "error .@ is invalid<br>";
      $rc.="error .@ is invalid<br>";
   }
   if (preg_match("/@\./",$email)) {
      echo "error @. is invalid<br>";
      $rc.="error @. is invalid<br>";
   }



   #
   # the email address must not begin or end with a '.' or a period
   #
   if (preg_match("/^\./",$email)) {
      echo "error begins with a period (.)<br>";
      $rc.="error begins with period (.)<br>";
   }
   if (preg_match("/\.$/",$email)) {
      echo "error ends with an period (.)<br>";
      $rc.="error ends with period (.)<br>";
   }
   #
   # the email address must not contain two periods in a row like ..
   #
   if (preg_match("/\.\./",$email)) {
      echo "error .. is invalid (.)<br>";
      $rc.="error .. or two periods next to each other is invalid<br>";
   }
   #
   # after the @ there must be one dot like
   #       xxxx@frog.com
   # so therefor
   #       xxx@frog
   # is invalid
   if (!preg_match("/@[^@\.]+\./",$email)) {
      echo "error .. is dot must follow @ like @xxx.com<br>";
      $rc.="error (.) dot must follow @ like @xxx.com<br>";
   }








   if ($rc != '') {
      $rc="'".$email."'<br>".$rc;
   }
   return $rc;
}
#
# if anything was entered then check for errors
#
$good_email_address=array();
$good_emails=0;
$bad_emails=0;
#
# if the person enteres one or more
# email addresses in the textarea 
# then process the email addresses
# and verify that they are good or bad 
# email addresses at least the syntax
# of the email address is good
#
if ($emails != ''  ) {
   #
   # split the input date into an array
   #
   $email_array= split ("\r" , $emails );
   #
   # process each email address in the array
   #
   $invalid_email_addresses='';
   foreach ($email_array as $slot) {
      #echo "processing $slot<br>";

      #
      # change commas to spaces
      # this is because i seperate email addresses with a comma
      # then if the comma is on the begining of the email address
      # or if the comma is at the end of the email address the
      # email address will be valid after leading and trailing
      # commas are removed.
      # but if the comma is in the MIDDLE of the email address
      # then it will be converted to a space and the email adress
      # will be invalid.
      # and of course that is good because since the comma key
      # is next to the period key i suspect a lot of times a
      # comma is typed instead of a period.
      #
      $slot=preg_replace("/,/"," ",$slot);
      #
      # remove ' from the email address
      # the textarea makes them \'
      #
      $slot=preg_replace("/\\\'/"," ",$slot);
      #
      # remove " from the email address
      # the textarea makes them \"
      #
      $slot=preg_replace('/\\\"/'," ",$slot);
      $slot=remove_leading_trailing_spaces($slot);
      $slot=preg_replace("/\r/","",$slot);
      $slot=preg_replace("/\n/","",$slot);
      $slot=preg_replace("/^ */","",$slot);
      $slot=preg_replace("/ *$/","",$slot);
      if ($slot != '' ) {
         $rc=validate_email_address ($slot);
         if ($rc == '' ) {
            #echo "Good Email<br>";
            #echo "push the good email address on to this array<br>";
            $good_email_address[$good_emails]=$slot;
            $good_emails++;
         }
         else {
            #echo "BAD EMAIL<br>";
            #echo "$rc<br>";
            $invalid_email_addresses.="\n".$slot;
            $bad_emails++;
         }
      }
   } 
   echo "good emails $good_emails<br>";
   echo "bad emails $bad_emails<br>";
   #
   # if we have one or more good email address
   # then try to insert them into the sql table
   #
   if ($good_emails > 0) {
      #echo "<h1>Good Emails</h1>";
      #foreach ($good_email_address as $x) {
      #   echo "&nbsp;$x<br>";
      #}
      #
      # get all the passwords we need
      #
      require('sql_passwords.php');
      # 
      # connect to SQL 
      # 
      $link = mysql_connect($z_hardcoded_sqlurl,  
                            $z_hardcoded_database,  
                            $z_hardcoded_password ) 
                            or die('Could not connect: ' . mysql_error()); 
      # 
      # select the database I want to use 
      # 
      mysql_select_db($z_hardcoded_database) or die('Could not select database'); 
      #
      # insert each email address the person
      # typed into the text area
      # well try to insert each email address
      # the person type in. some inserts may
      # fail if that email address alread exists
      # in the sql file
      #
      $good_insert=0;
      $bad_insert=0;
      foreach ($good_email_address as $x) {
         #
         # build the insert statement
         #
         $query = "insert into body_shops 
                          set email='$x',
                              date_created=now() ";
         #echo "query=$query<br>";
         #
         # try to insert the email address
         #
         $result = mysql_query($query);  
         if ($result) {  
            #
            # if the insert worked do this
            #
            echo "$x<br>";  
            $good_insert++;
         }  
         else {  
            #
            # if the insert failed it means
            # that email address is already
            # in the file
            # do this for failuers
            #
            #echo "insert failed $x<br>";  
            $bad_insert++;
         }
      }
      echo "$good_insert records inserted<br>";
      echo "$bad_insert records already existed";
      # 
      # close the SQL connection 
      # 
      mysql_close($link); 
   }
}
?>
<h2 align="center">Add CEWEEKLY E-mail addresses</h2>
<form action="add_ceweekly_email.php" method="post">
<input type="submit" name=submit value="SUBMIT">
<br>
<textarea rows="10" cols="50" name="emails">
<?php
   echo $invalid_email_addresses;
?>
</textarea>
</form>

../cellphones.php

TOC

<?php

function phone_hardware_cost($cost,$rows) {
   #
   # this column will usuall span several rows
   #
   echo "<td valign=\"top\" align=\"right\" rowspan=\"$rows\">";
   #
   # if they have 6 phone prices
   # split it into an array of 6 prices
   #
   $prices=explode(' ', $cost);
   #
   # in php you get the size of an array with the count() function
   # in php count() is kind of like sizeof() in C
   # in php count() is kind of like size_of()
   # in PERL you get the size of an array with $#array for $array
   # in php you use the function count() to get the size of an array
   #
   #
   # get how many different prices they have
   #
   $lines=count($prices);
   #
   # count the number of prices printed
   #
   $lines_printed=0;
   foreach($prices as $i) {
      #
      # print the leading $ sign and price
      #
      echo '$';
      echo $i;
      #
      # add 1 to prices printed
      #
      $lines_printed++;
      #
      # for every price execpt the last price
      # print a <br>
      #
      if ($lines_printed < $lines) {
         echo "<br>";
      }
   }
   #
   # close out the table box
   #
   echo "</td>";
}

function stinking_title_line(){
?>
<tr valign="top" style="background-color:yellow;color: black;">
   <td>Phone<br>Cost</td>
   <td>Air<br>Time<br>Cost</td>
   <td>Vendor</td>
   <td>Days</td>
   <td align="right">Number<br>Minutes</td>
   <td align="right">Cost<br>per<br>Min</td>
   <td>Comments</td>
</tr>
<?php
}

function doittoit ($name, $amount, $days, $minutes) {
   echo "<tr>";
   echo "<td align=\"right\">\$$amount</td>";
   echo "<td>$name</td>";
   echo "<td align=\"right\">$days</td>";
   echo "<td align=\"right\">$minutes</td>";

   $per_minute=($amount/$minutes)*1000;
   $per_minute/=10;
   $per_minute=round($per_minute,1);
   $per_minute=sprintf("%.1f",$per_minute);
   echo "<td align=\"right\">$per_minute&cent;</td>";
   echo "<td align=\"right\">&nbsp;</td>";
   echo "</tr>";
}

function topline ($name, $url, $cols) {
   echo "<tr>";
   echo "<td colspan=\"$cols\">";
   if ($url != '' ) {
      echo "<a href=\"http://$url\">";
   }
   echo "$name";
   if ($url != '' ) {
      echo "</a>";
   }
   echo "</td>";
   echo "</tr>";
}


function notes ($cols, $text) {
   #echo "<tr>";
   echo "<td colspan=\"5\">&nbsp;</td>";
   #$colsleft=$cols-5;
   $colsleft=$cols-6;
   echo "<td colspan=\"$colsleft\">";
   if ($text == '' ) {
      echo "&nbsp;";
   }
   else {
      echo "$text";
   }
   echo "</td>";
   echo "</tr>";
}






#$cols=6;
$cols=7;
?>
<table width="100%">
<tr>
<td width="40%">
My criteria for a pay as you go cell phone
is probably different then yours. 
<p>
If I wanted unlimited local calls I would
probably go with cricket because they 
are $30 a month for unlimited local service.
Which is about $360 a year.
<p>
But I seldom make phone calls so 
I would be happy with something that
charges me 10 cents a minute for only
the calls I make. 
<p>
I make long distance calls now and then
so it would be nice is long distance calls
are for the same price. 
But I don't make many long distance
calls so if I can't get them for free it
won't be a deal breaker.
<p>
Initial good buys are Tracfone
because I can get a years worth of
service for $80 or $100, even thought
the minutes are a little bit expensive.
<p>
T Mobile is probably better because I
can get a years service for $100 and
the minutes are only 10 cents each.
A good question is are those 
minutes good for long distance?
<p>
GO ATT is a little better priced
then my Tracfone, but their year
plan costs 2 and one half times
what a T Mobile costs. You get
400 minutes from GO ATT for $100
while T Mobile gives you
1000 minutes for the same $100.
<p>
Boost might be a good plan.
But they give out so little information
it is hard to compare them with the other
phones.
So unless I get more info on them I 
will avoid them.
Because they seem to be trying to hide
their rates.
I don't want to buy their phone and then
find out AFTER the fact that they have
a bunch of hidden charges that are not
listed in their publications.
</td>
<td>
&nbsp;
</td>
</tr>
</table>
<p>
<table border=1>
<?php stinking_title_line();?>


<?php topline('Tracfone','www.tracfone.com',$cols); ?>
<?php phone_hardware_cost('10 15 30 40',13);?>
<?php notes($cols,'You can get a Tracfone on sale for $10'); ?>
<?php doittoit('Tracfone',10,45,30); ?>
<?php doittoit('Tracfone',20,90,60); ?>
<?php doittoit('Tracfone',30,90,120); ?>
<?php doittoit('Tracfone',40,90,200); ?>
<?php doittoit('Tracfone',100,365,400); ?>
<?php doittoit('Tracfone',140,365,800); ?>





<?php doittoit('Tracfone + double',10+50,45,30*2); ?>
<?php doittoit('Tracfone + double',20+50,90,60*2); ?>
<?php doittoit('Tracfone + double',30+50,90,120*2); ?>
<?php doittoit('Tracfone + double',40+50,90,200*2); ?>
<?php doittoit('Tracfone + double',100+50,365,400*2); ?>
<?php doittoit('Tracfone + double',140+50,365,800*2); ?>


<?php topline('Virgin','virginmobileusa.com',$cols); ?>
<?php phone_hardware_cost('15 50 100',14);?>
<?php notes($cols,'The fixed rate Virgin are competive with my Tracfone,<br>even with the $140 high end Tracfone plane which is 17.5 cents vs 18 cents Virgin<br><b>BUT Virgin is only 90 days, Tracfone is 1 year!</b>'); ?>
<?php doittoit('Virgin',20,90,111); ?>
<?php doittoit('Virgin',30,90,166); ?>
<?php doittoit('Virgin',50,90,277); ?>
<?php doittoit('Virgin',90,90,500); ?>



<?php notes($cols,'The monthly fees kill this deal!!!<br>With out the monthly fee it would be a great deal at 10 cents a minute!<br>But when you throw in the monthly fee the 10 cents a minute rate is destoryed'); ?>
<?php doittoit('Virgin $6.99/mo',20,90,130); ?>
<?php doittoit('Virgin $6.99/mo',30,90,230); ?>
<?php doittoit('Virgin $6.99/mo',50,90,430); ?>
<?php doittoit('Virgin $6.99/mo',90,90,830); ?>



<?php doittoit('Virgin $35/mo',35,31,300); ?>
<?php doittoit('Virgin $45/mo',45,31,400); ?>
<?php doittoit('Virgin $60/mo',60,31,600); ?>
<?php doittoit('Virgin $100/mo',100,31,1000); ?>

<?php stinking_title_line();?>

<?php topline('T Mobile','www.t-mobile.com',$cols); ?>
<?php phone_hardware_cost('30 40 70 80 98',5);?>
<?php notes($cols,'Probably the best plan<p>You get a year at 10&cent; a minute'); ?>
<?php doittoit('T Mobile',10,90,30); ?>
<?php doittoit('T Mobile',25,90,130); ?>
<?php doittoit('T Mobile',50,90,400); ?>
<?php doittoit('T Mobile',100,365,1000); ?>


<?php topline('Boost','www.boost-mobile.com',$cols); ?>
<?php phone_hardware_cost('40 100',4);?>
<?php notes($cols,'Boost seems to suck the big one!!!<br>
                   And unknown charges - Will they rip you off?'); ?>


<tr>

<td align="right">?</td>
<td>Boost</td>
<td align="right">30</td>
<td align="right">?</td>
<td align="right">20.0&cent;</td>
<td>35&cent;/day web fee - must call 888-BIIST-4U to shut off</td>
</tr>


<tr>
<td align="right">$50</td>
<td>Boost</td>
<td align="right">90</td>
<td align="right">?</td>
<td align="right">12.5&cent;</td>
<td>$50/mo 35&cent;/day web fee - must call 888-BIIST-4U to shut off</td>
</tr>

<tr>
<td align="right">$90</td>
<td>Boost</td>
<td align="right">90</td>
<td align="right">?</td>
<td align="right">11.7&cent;</td>
<td>$90/mo 35&cent;/day web fee - must call 888-BIIST-4U to shut off</td>
</tr>


<?php topline('GO ATT','',$cols); ?>
<?php phone_hardware_cost('20 50',10);?>
<?php notes($cols,'At 25 cents a minute as good as my trac phone'); ?>
<?php doittoit('GO ATT',15,30,15*4); ?>
<?php doittoit('GO ATT',25,90,25*4); ?>
<?php doittoit('GO ATT',50,90,50*4); ?>
<?php doittoit('GO ATT',100,365,100*4); ?>

<tr>
<?php notes($cols,'The $1 a day stuff sucks!<br>It is a killer!!!'); ?>
<td align="right">$15</td>
<td>GO ATT/daily</td>
<td align="right">30</td>
<td align="right">?</td>
<td align="right">10.0&cent;</td>
<td>$1/day used</td>
</tr>


<tr>
<td align="right">$25</td>
<td>GO ATT/daily</td>
<td align="right">90</td>
<td align="right">?</td>
<td align="right">10.0&cent;</td>
<td>$1/day used</td>
</tr>

<tr>
<td align="right">$50</td>
<td>GO ATT/daily</td>
<td align="right">90</td>
<td align="right">?</td>
<td align="right">10.0&cent;</td>
<td>$1/day used</td>
</tr>


<tr>
<td align="right">$100</td>
<td>GO ATT/daily</td>
<td align="right">365</td>
<td align="right">?</td>
<td align="right">10.0&cent;</td>
<td>$1/day used</td>
</tr>


<?php stinking_title_line();?>
<?php topline('Firefly','www.fireflymobile.com',$cols); ?>
<?php phone_hardware_cost('50',4);?>
<?php notes($cols,'Too many open questions!<br>Whats min $ payment?<br>How long does it last?<br>With lots of days use the 35 cent daily fee could be a pain<br>Other then that 15 cents a minute is reasonsable'); ?>
<tr>
<td align="right">&nbsp;</td>
<td>Firefly minute</td>
<td align="right">?</td>
<td align="right">?</td>
<td align="right">15.0&cent;</td>
<td>35&cent;/day+ how long does it last??? + $ for messages received?</td>
</tr>

<?php notes($cols,'The $15 monthly fee kills this plan'); ?>
<tr>
<td align="right">$15</td>
<td>Firefly monthly</td>
<td align="right">?</td>
<td align="right">?</td>
<td align="right">10.0&cent;</td>
<td>$15/mo + 35&cent;/day+ how long does it last??? + $ for messages received? </td>
</tr>



<?php topline('Kajeet','kajeet.com',$cols); ?>
<?php phone_hardware_cost('60',2);?>
<?php notes($cols,'Too many open questions!<br>Whats min $ payment?<br>How long does it last?<br>With lots of days use the 35 cent daily fee could be a pain<br>Other then that 10 cents a minute is reasonsable'); ?>
<tr>
<td align="right">?</td>
<td>Kajeet</td>
<td align="right">?</td>
<td align="right">?</td>
<td align="right">10.0&cent;</td>
<td>35&cent;/day+ how long does it last??? + 5&cent;/msg received</td>
</tr>



<?php topline('iNpulse','verizonwireless.com',$cols); ?>
<?php phone_hardware_cost('40 120',4);?>
<?php notes($cols,'The $1 a day charge is a deal killer!!!!'); ?>
<tr>
<td align="right">?</td>
<td>iNpulse</td>
<td align="right">?</td>
<td align="right">?</td>
<td align="right">10.0&cent;</td>
<td>$1/day+ how long does it last??? + 10&cent;/msg received</td>
</tr>


<tr>
<td align="right">?</td>
<td>iNpulse</td>
<td align="right">?</td>
<td align="right">?</td>
<td align="right">5.0&cent;</td>
<td>$2/day+ how long does it last??? + 5&cent;/msg received</td>
</tr>


<tr>
<td align="right">?</td>
<td>iNpulse</td>
<td align="right">?</td>
<td align="right">?</td>
<td align="right">2.0&cent;</td>
<td>$3/day+ how long does it last??? + 2&cent;/msg received</td>
</tr>


<?php topline('AllTel','www.alltelu.com/plans/pay-per-minute.php',$cols); ?>
<?php phone_hardware_cost('1 15 20 25 70 80 90',5);?>
<?php notes($cols,'$35 activation fee? That sucks!<br>Well it might not suck that bad since you can buy a phone for $1<br>Also their phones <b>don\'t</b> show your balance! That sucks too!'); ?>
<tr>
<td align="right">$20</td>
<td>AllTel</td>
<td align="right">60</td>
<td align="right"> <?php echo sprintf("%.0f",20/.15);?> </td>
<td align="right">15&cent;</td>
<td>&nbsp;</td>
</tr>

<tr>
<td align="right">$45</td>
<td>AllTel</td>
<td align="right">90</td>
<td align="right"> <?php echo sprintf("%.0f",45/.15);?> </td>
<td align="right">15&cent;</td>
<td>&nbsp;</td>
</tr>


<tr>
<td align="right">$55</td>
<td>AllTel</td>
<td align="right">180</td>
<td align="right"> <?php echo sprintf("%.0f",55/.15);?> </td>
<td align="right">15&cent;</td>
<td>&nbsp;</td>
</tr>

<tr>
<td align="right">$100</td>
<td>AllTel</td>
<td align="right">365</td>
<td align="right"><?php echo sprintf("%.0f",100/.15);?></td>
<td align="right">15&cent;</td>
<td>Text 10&cent; each. Text received free? 59&cent; roam</td>
</tr>



<?php stinking_title_line();?>
</table>

clean_php_form_data.php

TOC

<?php
function clean_php_form_data($data) {
   #
   # for some reason when you enter the characters
   #     ", ', and \
   # into a PHP form they are returned as
   #     \", \', and \\
   #
   # well this function cleans up the data
   # and removes the annoying backslashes
   #
   # oddly data is NOT returned this way in PERL
   #
   $data=preg_replace('/\\\\\'/',"'",$data);
   $data=preg_replace('/\\\\\"/','"',$data);
   $data=preg_replace('/\\\\\\\\/',"\\",$data);
   return $data;
}
?>


../dns_stuff/como.php

TOC

<?php
#
# get the variables they entered on the form
#
$ip=$_POST['ip'];
require('como_form.php');
#print "<form action=\"como.php\" method=\"post\">";
#print "IP:";
#print "<input type=\"text\" name=\"ip\" value=\"$ip\" size=\"60\"><br>";
#print "<input type=\"submit\" name=submit value=\"Como\"></td>";
#print "<p><input type=\"reset\" name=reset value=\"CLEAR MENU\">";
#print "</form>";
echo "<a href=\"../class/whois_this_url.php\">Better DNS stuff</a><br>";
#
# if the IP address is not null convert it to its name and print it!
#
if ($ip != "" ) {
 $name = @gethostbyaddr($ip);
 print "<blockquote><nobr>";
 print "$ip = $name";
 print "</blockquote>";
}
if ($url != "" ) {
 $name = @gethostbyname ( $url );
 print "<blockquote><nobr>";
 print "$url = $name";
 print "</blockquote>";
}








?>

../dns_stuff/como_form.php

TOC

<?php
#
# get the variables they entered on the form
#
print "<form action=\"como.php\" method=\"post\">";
print "IP:";
print "<input type=\"text\" name=\"ip\" value=\"$ip\" size=\"60\"><br>";
print "URL:";
print "<input type=\"text\" name=\"url\" value=\"$url\" size=\"60\"><br>";
print "<input type=\"submit\" name=submit value=\"Como\"></td>";
print "<p><input type=\"reset\" name=reset value=\"CLEAR MENU\">";
print "</form>";
?>

convert_to_mime_base64.php

TOC

<h1 align="center">MIME, Base64 Converter Program</h1>
<a href="convert_to_mime_base64.php?help=help">HELP</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="display_programs_mime_base64.php">Display this programs source code</a>
<br>
<?php
   $help=$_GET['help'];
   if ($help == 'help') {
      display_the_help_menu();
   }
   #
   # this program converts
   #       mime data to ascii or binary data
   # and 
   #       ascii or binary data to mime data
   #
   # some people like to call mime data either
   #   base64 data 
   #     or
   #   mime64 data
   # 
   # so you can also say 
   # this program converts
   #       base64 data to ascii or binary data
   # and 
   #       ascii or binary data to base64 data
   #
   #
   # the data can either be entered on the screen
   # into the html form
   # or a file can be uploaded 
   #



   # 3) for some reason when you type in the data
   #    it converts " to \" 
   #            and ' to \'
   #            and \ to \\
   #    i dont know why it is doing this but i 
   #    have to fix it. 






   # set the default values for this program
   #
   $total_errors=0;
   $size=60;
   $rows=10;
   #
   # grab the data the user typed into the HTML form
   #
   $text=$_POST['text'];
   $debug_button=$_POST['debug_button'];
   $submit_button=$_POST['submit'];
   #
   # for some reason stuff like " becomes \"
   #                        and ' -> \'
   #                        and \ -> \\
   # undo that nonsense
   #
   #$text=preg_replace("/\\\/",'',$text); 



function validate_mime_data($data) {
  #
  # assume no errors
  #
  $error_text="";  
  #
  # this way is kind of kludgy!!!! yuck
  # but I was having trouble debugging the other way
  # so i got it to work using the KISS or
  # Keep It Simple Stupid method
  #
  if (0) {
     #
     # does mime text contain bad characters
     #
     if (preg_match("/[^\+0-9=A-Za-z\n\r\/]/",$data)) {
        #
        # looks like there is invalid characters 
        # in the alleged mime text
        #
        $error_text.="<span style=\"background-color:#ff0000\">";
        $error_text.="Error can't convert from MIME to ASCII";
        $error_text.="<br>Invalid mime data found in text or file";
        $error_text.="<br>Valid MIME characters are";
        $error_text.="<br>&nbsp;&nbsp;&nbsp;+";
        $error_text.="<br>&nbsp;&nbsp;&nbsp;=";
        $error_text.="<br>&nbsp;&nbsp;&nbsp;0 thru 9";
        $error_text.="<br>&nbsp;&nbsp;&nbsp;a thru z";
        $error_text.="<br>&nbsp;&nbsp;&nbsp;A thru Z";
        $error_text.="</span>";
        #
        # show them the garbage characters
        #
        $invalid=$data;
        $invalid=preg_replace("/[\+0-9=A-Za-z\n\r\/]/",'',$invalid);
        $error_text.="<br>The invalid characters found are:<br>";
        $error_text.="<pre>";
        $error_text.="<span style=\"background-color:#00ff00\">";
        $error_text.="$invalid";
        $error_text.="</span>";
        $error_text.="</pre><br>";
     }
  }
  #
  # this way is much better
  # it tells the line number of the errors
  # and what the garbage data is
  # i tried to do this originally but
  # my brain wasnt working!
  #
  if (1) {
     #
     # this way tells them which line  had the error
     #
     #
     # split the data into lines
     #
     $line_number=0;
     $lines=explode("\n",$data);
     foreach($lines as $l) {
        #
        # get the current line number
        #
        $line_number++;
        #
        # does the line have any garbage characters in it?
        #
        if (preg_match("/[^\+0-9=A-Za-z\n\r\/]/",$l)) {
           #
           # yes we have garbage characters
           #
           # first time here build the header error message
           #
           if ($error_text == '' ) {
              $error_text.="<span style=\"background-color:#ff0000\">";
              $error_text.="Error can't convert from MIME to ASCII";
              $error_text.="<br>Invalid mime data found in text or file";
              $error_text.="<br>Valid MIME characters are";
              $error_text.="<br>&nbsp;&nbsp;&nbsp;+";
              $error_text.="<br>&nbsp;&nbsp;&nbsp;=";
              $error_text.="<br>&nbsp;&nbsp;&nbsp;0 thru 9";
              $error_text.="<br>&nbsp;&nbsp;&nbsp;a thru z";
              $error_text.="<br>&nbsp;&nbsp;&nbsp;A thru Z";
              $error_text.="</span>";
              $error_text.="<p>";
           }
           $invalid=preg_replace("/[\+0-9=A-Za-z\n\r\/]/",'',$l);
           #
           # make things like &, <, and > displayable
           #
           $invalid=htmlentities($invalid);
           #
           # make spaces visible
           #
           $invalid=preg_replace("/ /",'&nbsp;',$invalid);
           $error_text.="line $line_number contains invalid data ";
           $error_text.="<span style=\"background-color:#00ff00\">";
           $error_text.="$invalid";
           $error_text.="</span>";
           $error_text.="<br>";
        }
     }
  }
  #
  # return either a null string if no errors
  # or an error message
  #
  return $error_text;
}


function dump_to_disk($file_name,$file_data) {
   $file_name="temporary_image_file_links/".$file_name;
   #echo "dumping to disk $file_name<p>";

   $handle=fopen($file_name,'wb'); 
   $byteswritten=fwrite($handle,$file_data); 
   fclose($handle); 




   return;
}




function dump_data($data) {
  #
  # split into lines
  #
  $lines=explode("\n",$data);
  #
  # print each line
  #
  foreach ($lines as $l ) {
    #
    # remove binary data that doesnt display well
    # or that causes the display end
    #
    $l=preg_replace("/[\\x00-\\x1f]/",".",$l); 
    $l=preg_replace("/[\\x7f-\\xff]/",".",$l);
    #
    # convert > to &gt;
    #         < to &lt;
    #         & to &amp;
    #         .......
    #
    $l=htmlentities($l);
    #
    # display the line
    #
    echo "$l<br>";
  } 
  return;

?>
<table style="background-color:#dddddd">
<tr valign="top">
<td>
<!-- form action="send_an_email.php" method="post" -->
<!-- make it a miltipart/form so we can upload files -->
<FORM action="convert_to_mime_base64.php"  
      method="post" 
      enctype="multipart/form-data"> 
<table border="1">
<tr valign="top">
<td>
<input type="submit" name=submit value="Convert DATA --> MIME or Base64 DATA">
<p>
<input type="submit" name=submit value="Convert MIME or Base64 DATA --> DATA">
</td>
<td>
Created via form<br>
&nbsp;&nbsp;&nbsp;&nbsp;
<a href="temporary_image_file_links/form.txt" TARGET="form_text">form.txt</a>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;
<a href="temporary_image_file_links/form.bin" TARGET="form_bin">form.bin</a>
</td>
<td>
Created via upload<br>
&nbsp;&nbsp;&nbsp;&nbsp;
<a href="temporary_image_file_links/upload.txt" TARGET="upload_text">upload.txt</a>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;
<a href="temporary_image_file_links/upload.bin" TARGET="upload_bin">upload.bin</a>
</td>
<td>
<a href="../mime_exe.html">mime.exe</a><br>&nbsp;A M/S DOS program
<br>&nbsp;to convert mime files
</td>
</tr>
</table>
<input type="checkbox" name="debug_button" value="debug_it"

<?php if ($debug_button != "" ) {echo "checked";} ?>


>
debug
<p>
<table>
<tr>
   <td align="right">&nbsp;</td>
   <td align="left">
        <input type="file" name="file_to_upload"> File to upload and process
   </td>
</tr>
<tr>
   <td colspan="2">
       <textarea name="text" 
       <?php echo "cols=\"$size\" rows=\"$rows\" "; ?>><?php echo "$text"; ?></textarea>  
   </td>
</tr>
</table>
<p>
<input type="hidden" name="hidden_post_variable" value="hidden post data">
<input type="reset" name=reset value="RESET">
</form>
</td>


<?php
   if ($debug_button != "" ) {
       echo "<td style=\"background-color:#ffff00\">";
       echo "<h2>Debug Window</h2>";
   }
   #
   # if text was entered convert dump it for debugging
   #
   if ($text != '' ) {
      #
      # in debug mode dump the data we process
      #
      if ($debug_button != "" ) {
         dump_data($text);
      }
   }
   #
   # if a file was entered convert it to mime
   #
   if ($_FILES['file_to_upload']['name'] != "" ) {
      #
      # read in the file they want to convert to mime
      #      
      $file_data=file_get_contents($_FILES['file_to_upload']['tmp_name']);
      #
      # in debug mode dump the data we process
      #
      if ($debug_button != "" ) {
         dump_data($file_data);
      }
    echo "</td>";
   }
 ?>
</tr>
</table>
<?php
   if ($submit_button == "Convert DATA --> MIME or Base64 DATA" ) {
      #
      # if text was entered convert it to mime
      #
      if ($text != '' ) {
         echo "<h3>Text converted to mime or base64</h3>";
         #
         # convert text to mime format or base64
         #
         $mime_text=imap_binary($text);
         #
         # write the data that was entered in the form and converted to mime to disk
         #
         dump_to_disk('form.txt',$mime_text);
         echo "<tt>";
         echo "<pre>";
         #
         # if the mime text has any html in it
         # convert it to displayable form
         #
         $mime_text=htmlentities($mime_text);
         echo $mime_text;
         echo "</pre>";
         echo "</tt>";
      }
      #
      # if a file was entered convert it to mime
      #
      if ($_FILES['file_to_upload']['name'] != "" ) {
         #
         # read in the file they want to convert to mime
         #      
         $file_data=file_get_contents($_FILES['file_to_upload']['tmp_name']);
         #
         # convert the data to mime
         #
         $file_data=imap_binary($file_data);
         #
         # write the data that was entered in the form and converted to mime to disk
         #
         dump_to_disk('upload.txt',$file_data);
         echo "<h3>File converted to mime or base64</h3>";
         echo "<tt>";
         echo "<pre>";
         echo $file_data;
         echo "</pre>";
         echo "</tt>";
      }
   }
   else {
      if ($text != '' ) {
         echo "<h3>MIME to Ascii Data</h3>";
         #
         # validate mime data for errors
         #
         $rc=validate_mime_data($text);
         if ($rc != "" ) {
            #
            # invalid mime data
            # print an error message
            #
            echo "$rc<p>";
         }
         else {
            #
            # convert MIME data to ascii text or binary data
            #
            $mime_text=imap_base64($text);
            #
            # write the data that was entered in the form and converted to ascii to disk
            #
            dump_to_disk('form.bin',$mime_text);
            echo "<tt>";
            echo "<pre>";
            #
            # if the mime text has any html in it
            # convert it to displayable form
            #
            #$mime_text=htmlentities($mime_text);
            #echo $mime_text;
            #
            # convert back to HTML to display
            #
            dump_data($mime_text);
            echo "</pre>";
            echo "</tt>";
         }
      }
      #
      # if a file was entered convert from MIME or BASE64
      # to ascii or binary data
      #
      if ($_FILES['file_to_upload']['name'] != "" ) {
         #
         # read in the file they want to convert to mime
         #      
         $file_data=file_get_contents($_FILES['file_to_upload']['tmp_name']);
         #
         # validate mime data for errors
         #
         $rc=validate_mime_data($file_data);
         if ($rc != "" ) {
            #
            # invalid mime data
            # print an error message
            #
            echo "$rc<p>";
         }
         else {
            #
            # convert the data to mime
            #
            $file_data=imap_base64($file_data);
            #
            # write the uploaded file that was converted to ascii to disk
            #
            dump_to_disk('upload.bin',$file_data);
            echo "<h3>File converted from MIME to ASCII Data</h3>";
            echo "<tt>";
            echo "<pre>";
            #echo $file_data;
            #
            # convert back to HTML to display
            #
            dump_data($file_data);
            echo "</pre>";
            echo "</tt>";
         }
      }
   }
?>
<?php
function display_the_help_menu() {
?>
<table width="100%">
<tr>
<td width="50%">
<h3>What this program does</h3>
<ul>
<li>This program converts text or binary files to MIME or BASE64 files
<li>This program converts MIME or BASE64 files to text or binary files
</ul>
A text or binary file can be any type of computer file.
A text file could be a simple text list, a web page in html,
or a binary file such as an image, an executable program,
a word document or even a sound file.
<p>
A Multipurpose Internet Mail Extensions 
is a very long word for a MIME or BASE64 file.
As far as this program is concerned
MIME and BASE64 files are the same.
<p>
A large proportion of e-mail is transmitted via SMTP in MIME format.
<p>
MIME files are readable by humans
as opposed to binary files 
which usually contain some readable text
along with a bunch of unreadable binary data.
MIME files only contain the characters
<blockquote>
<ul>
<li>+
<li>/
<li>=
<li>0 thru 9
<li>a thru z
<li>A thru Z
</ul>
</blockquote>
Binary files are often converted to MIME format data
and transported over the internet.
<p>
MIME or base64 files look like this
<blockquote>
<tt>
<pre>
TFRPQQBUTVBOQU0AVU5MSU5LAFNUUkNBVABNRU1DUFkAQ0hNT0RBAENWVEZB
SwBFT0YARkZMVVNIAFBSSU5URgBQVVRDAFJFQUxDVlQAVlBSSU5URVIARlJF
RQBGR0VUUwBGUFJJTlRGAFNDQU5ORVIAU0NBTlRPRABTQ0FOVE9MAFNTQ0FO
RgBMTFNIAExVUlNIAFJFTkFNRQBTUFJJTlRGAFNUUklDTVAA
</pre>
</tt>
</blockquote>
<h3>Entering the data to be translated</h3>
The data to be translated between MIME and binary format
or vise-versa
can either be
<ol>
<li>Pasted or typed into the form
<li>Uploaded as a file using the forms Browse button to select a file
</ol>
<h3>Translating the data from text or binary to MIME format</h3>
The data in the forms text box or 
in the file uploaded is translated
from text or binary data to MIME format
when the
<blockquote>
<input type="button" value="Convert DATA --> MIME or Base64 DATA"> 
</blockquote>
button is clicked on.
<p>
The MIME data is always displayed on the screen.
<p>
The MIME data is also written one or two files.
<p>
If text was entered into the forms textbox
the MIME from that textbox will be written to
the file
<a href="temporary_image_file_links/form.txt">form.txt</a>
which can be viewed by clicking on it.
<p>
If text was created from an uploaded file
the MIME from that textbox will be written to
the file
<a href="temporary_image_file_links/upload.txt">upload.txt</a>
which can be viewed by clicking on it.
<h3>Translating the data from MIME format to text or binary format</h3>
The data in the forms text box or 
in the file uploaded is translated
from  MIME format to text or binary data
when the
<blockquote>
<input type="button" value="Convert MIME or Base64 DATA --> DATA">
</blockquote>
button is clicked on.
<p>
The text or binary data is always displayed on the screen,
however binary or unprintable characters are displayed as
a dot or period (.).
So if your output data is binary data
viewing it on the screen will be a pretty useless task.
However the text in image files and executable programs
often contains interesting text which this program
will let you view.
<p>
If MIME was entered into the forms textbox
the text or binary from that textbox will be written to
the file
<a href="temporary_image_file_links/form.bin">form.bin</a>
which can be downloaded to your computer by clicking on it.
<p>
If text was created from an uploaded file
the MIME from that textbox will be written to
the file
<a href="temporary_image_file_links/upload.bin">upload.bin</a>
which can be downloaded to your computer by clicking on it.
<p>
<h3>Possible errors</h3>
If two or more people are using this program or web page
at the same time, the data written to the files
<blockquote>
<a href="temporary_image_file_links/form.bin">form.bin</a><br>
<a href="temporary_image_file_links/upload.bin">upload.bin</a><br>
<a href="temporary_image_file_links/form.txt">form.txt</a><br>
<a href="temporary_image_file_links/upload.txt">upload.txt</a>
</blockquote>
could be trashed by a second user.
<p>
If your attempting to translate MIME data to binary data or text
and your alleged MIME data contains characters that
are not valid MIME characters I will display the offending
characters and an error message. 
I will not try to translate the alleged MIME data to text or binary data.
<h3>MIME, Base64 Headers</h3>
A header used to send off a MIME or base64 file
looks like this
<blockquote>
<nobr>Content-Type: text/plain; charset=US-ASCII;</nobr><br>
<nobr>Content-transfer-encoding: base64</nobr>
<blockquote>
</td>
<td width="50%">
&nbsp;
</td>
</tr>
</table>
<?php
return;

?>

../curl_ftp_stuff/copy_a_file.php

TOC

<h4>List my site before the ftp</h4>
<?php
#
# include the functions to remove sensitive data
#
include "remove_sensitive_data.php";
#
# get our data
#
include "stuff/passwords.php";
#
# list the stinking files before the ftp
#
include "list_z_files.php";
?>
<h4>Do the FTP my way :)</h4>
we will ftp this file <a href="text_file_to_ftp.txt">text_file_to_ftp.txt</a>
<?php
#
# doesnt look like we get much debug info
# when we do ftp uploads
# we got lots of it when we
$debug_file="a_debug_file.txt";
echo "view debug output <a href=\"$debug_file\">$debug_file</a><br>";
$debug_file_handle=fopen($debug_file,'w');
$file_to_upload="body_parts.txt";
#
# open the file we want to upload
#
$filehandle=fopen($file_to_upload,"r");
#
# define the name of the file to upload
#
$filename_to_upload=$file_to_upload; 
#
# initialize curl
#
$curl=curl_init();
#
# turn on the debug out put
#
curl_setopt($curl,CURLOPT_VERBOSE,1);
curl_setopt($curl,CURLOPT_STDERR,$debug_file_handle);

#
# tell curl to upload the file
#
curl_setopt($curl,CURLOPT_UPLOAD,1);

#
# tell curl to do an ftp
# and the file name at the end is the filename
# that the file will be uploaded as
#
curl_setopt($curl,CURLOPT_URL,"ftp://$site"."/".$filename_to_upload);
#
# tell curl the userid/password to use when doing the ftp
#
curl_setopt($curl,CURLOPT_USERPWD,$userid.":".$password);
#
# we pass curl the FILE HANDLE to upload
# thats the filehandle, not the file name
#
curl_setopt($curl,CURLOPT_INFILE,$filehandle);
#
# tell curl the file size to upload
#
curl_setopt($curl,CURLOPT_INFILESIZE,filesize($file_to_upload));
#
# check if we had any errors
#
$errors = curl_errno($curl);
echo "<p>errors=$errors<p>";

#curl_setopt($curl,CURLOPT_PUT,"text_file_to_ftp.txt");
#
# upload the stinking file
#
$result=curl_exec($curl);
#
# close curl
#
curl_close($curl);
fclose($filehandle); 
fclose($debug_file_handle);
#
# remove all the data i consider sensitive
# duh! like passwords and userids
#
# read in the file
#
$debug_data=file_get_contents($debug_file); 
#
# change the site id to 'my-site'
#
$debug_data=remove_sensitive_data($debug_data, $my_site, "my-site");
#
# change the userid to 'my-userid'
#
$debug_data=remove_sensitive_data($debug_data, $userid, "my-userid");
#
# change the password to '**secret**'
#
$debug_data=remove_sensitive_data($debug_data, $password, "**Secret**");
#
# rewrite the file
#
$byteswritten=file_put_contents ($debug_file,$debug_data); 
?>
<h4>Do the FTP their way :)</h4>
I found this example on the web.
<p>
Oddly you have to tell curl the file to upload
as part of the ftp command.
Like this
<blockquote>
ftp://ftp.ftpsite.com/file_name_to_upload.txt
</blockquote>
Silly me! I though there was a curl command 
to tell it the name of the file to upload.
<p>
<?php
  #
  # this is the code I swiped off of the internet
  # because my code would not work.
  # i am suprised because the reason my code did
  # not work is because the filename of the file
  # to upload must be part of the FTP command
  # ie:
  #
  #      ftp://ftp.site.name.com/filename.txt
  #
  # initialize curl
  $ch = curl_init();
  #
  # set the local file name to upload
  #
  $localfile = "text_file_to_ftp.txt";
  #
  # open the local file to upload
  # because we have to pass the file handle to curl
  # not the file name
  #
  $fp = fopen($localfile, 'r');
  #
  # damn!!!!!!!!!!!!!!!
  # on the ftp line 
  # you end it with the file you want to upload!!!!
  # i wouldn't have thought of that in 1,000 years
  #
  curl_setopt($ch,CURLOPT_URL,"ftp://$site"."/".$localfile);
  #
  # tell curl the userid/password we are using for this upload
  #
  curl_setopt($ch,CURLOPT_USERPWD,$userid.":".$password);
  #
  # tell curl to upload the file
  #
  curl_setopt($ch, CURLOPT_UPLOAD, 1);
  #
  # tell curl the filehandle of
  # the local file to upload
  #
  curl_setopt($ch, CURLOPT_INFILE, $fp);
  #
  # get the size of the file to upload
  # and pass it to curl
  #
  $zfilesize=filesize($localfile);
  echo "filesize=$zfilesize<br>";
  curl_setopt($ch, CURLOPT_INFILESIZE, $zfilesize);
  #
  # upload the file
  #
  curl_exec ($ch);
  #
  # check to see if we had any errors uploading the file
  #
  $error_no = curl_errno($ch);
  #
  # close curl
  #
  curl_close ($ch);
  echo "errors=$error_no";
?>
<h4>List my site <b><i>after</i></b> the ftp</h4>
<?php
#
# list the stinking files after the FTP
#
include "list_z_files.php";
?>

../counter.pl

TOC

#!/usr/bin/perl
$debug_flag=0;
#require TripodCGI;
require CGI;
use CGI;
$cgi = new CGI;
#
# get the digit to display
#
$f=$cgi->param('f');
$d=$cgi->param('d');
if ($debug_flag) {
  print "Content-type: text/html", "\n\n";
  print "<html>\n";
  print "digit=$d<p>";
}
#
# the digit must be a number
# null digits aint allowed
#
if ($d eq "" ) {
   if ($debug_flag) {
      print "\$d is null<br>\n";
   }
   $image="null_not_allowed.jpg";
   goto done;
}



if ($d =~ /^comma$/i ) {
   if ($debug_flag) {
      print "\$d is comma<br>\n";
   }
   $image="comma.jpg";
   goto done;
}
if ($d =~ /^dot$/i ) {
   if ($debug_flag) {
      print "\$d is dot<br>\n";
   }
   $image="dot.jpg";
   goto done;
}



#
# digit must be a one or more digit number
#
if ($d !~ /^[0-9][0-9]*$/ ) {
   if ($debug_flag) {
     print "\$d must be numeric it aint '$d'<br>\n";
   }
   $image="number_required.jpg";
   goto done;
}
#
# digit cant be the number zero
#
if ($d == 0 ) {
   if ($debug_flag) {
     print "\$d must not be zero '$d'<br>\n";
   }
   $image="zero_not_allowed.jpg";
   goto done;
}
$digit_out=$d;
#
# get the name of the counter
#
$n=$cgi->param('n');
if ($debug_flag) {
   print "counter name='$n'<br>";
}
#
# if the counter name is not null
# validate the name of the counter name
# counter names can only be a-z, A-Z, and (_) underscores
#
if ($n ne "" ) {
   if ($debug_flag) {
      print "\$n not NULL='$n'<br>";
   }
   if ($n !~ /^[0-9a-zA-Z_][0-9a-zA-Z_]*$/ ) {
      if ($debug_flag) {
         print "\$n is invalid '$n'<br>\n";
      }
      $image="counter_name_bad.jpg";
      goto done;
   }
}
if ($debug_flag) {
   print "valid counter name='$n'<br>";
}
#
# open the counter file ane read in the counter names
$i=0;
$counter_is_at="";
open(COUNTERS,'counter/counter.txt');
while(<COUNTERS>) {
 chomp($_);
 $kounter[$i]=$_;
 if ($debug_flag) {
    print "$i=$_<br>";
    print "$kounter[$i]<br>";
 }
 if ($n eq "") {
   if ($_ =~ /^[0-9][0-9]*$/ ) {
      $counter_is_at=$i;
      $counter=$_;
      $the_counter=$counter;
      if ($debug_flag) {
         print "COUNTER at $i<br>";
         print "COUNTER=$counter<br>";
      }
   }
 }
 else {
   if ($_ =~ /^$n=[0-9][0-9]*$/ ) {
      $counter_is_at=$i;
      $counter=$_;
      $counter=~s/^.*=//;
      $the_counter=$counter;
      if ($debug_flag) {
         print "COUNTER at $i<br>";
         print "COUNTER=$counter<br>";
      }
   }
 }
 $i++;
 $max_counters=$i;
}
close(COUNTERS);
#
# counter was not found
if ($counter_is_at eq "" ) {
   if ($debug_flag) {
      print "\$n counter '$n' not found<br>\n";
   }
   $image="counter_not_found_in_file.jpg";
   goto done;
}
#
# validate the counter
# it must be a positive number
#
if ($counter eq "" ) {
   if ($debug_flag) {
      print "\$counter cant be NULL<br>\n";
   }
   $image="counter_is_null.jpg";
   goto done;
}
if ($counter !~ /^[0-9][0-9]*$/ ) {
   if ($debug_flag) {
      print "\$counter must be numeric it aint '$counter'<br>\n";
   }
   $image="counter_not_numeric.jpg";
   goto done;
}

$remainder=0;
if ($debug_flag) {
   print "counter=$counter<br>";
}
while ($d > 0 ) {
   $remainder=$counter%10;
   $counter=$counter-$remainder;
   $counter=$counter/10;
   $d--;
}
if ($debug_flag) {
   print "remainter=$remainder<br>";
}
#$image="$remainder".".gif";
$image="$f$remainder".".gif";
#
# all done. get outa here
#
#
# if the digit is the number one (1)
#     add 1 to the counter
#        and write it back to the file
#     later on flock the file so we can handle mutiple users
#
if ( $digit_out== 1) {
 if ($debug_flag) {
    print "digit == 1<br>";
    print "update the counter file!!!<br>";
    print "old counter=$the_counter<br>";
 }
 $the_counter++;
 if ($debug_flag) {
    print "new counter=$the_counter<br>";
    print "old counter=$kounter[$counter_is_at]<br>";
 }
 if ($n eq "") {
  $kounter[$counter_is_at]++;
  if ($debug_flag) {
     print "new counter=$kounter[$counter_is_at]<br>";
  }
 }
 else {
  $kounter[$counter_is_at]=~s/=.*$/=$the_counter/;
  if ($debug_flag) {
     print "new counter=$kounter[$counter_is_at]<br>";
  }
 }
 if ($debug_flag) {
    print "now write out $max_counters counters<br>";
 }
 open(COUNTERS,'>counter/counter.txt');
 for ($i=0;$i<$max_counters;$i++) {
  if ($debug_flag) {
     print "write $kounter[$i]<br>\n";
  }
  #prnters<br>";
 }
 open(COUNTERS,'>counter/counter.txt');
 #flock( COUNTERS , 2);
 for ($i=0;$i<$max_counters;$i++) {
  if ($debug_flag) {
     print "write $kounter[$i]<br>\n";
  }
  print COUNTERS "$kounter[$i]\n";
 }
 close(COUNTERS);

 #
 # this computer is on the east coast and uses New York time
 # f*ck New York time!!! We want Phoenix time!
 #
 #($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
 #
 # 1) subtract 7 hours from GM time to get Phoenix time
 # 2) format Phoenix time into yy/mm/dd/ hh/mm/ss
 #
 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=gmtime(time()-(7*60*60));
 $mon++;
 $mon=($mon<10)?"0$mon":$mon;
 $hour=($hour<10)?"0$hour":$hour;
 $min=($min<10)?"0$min":$min;
 $sec=($sec<10)?"0$sec":$sec;
 $mday=($mday<10)?"0$mday":$mday;
 $year+=1900;
 $zdate="$year/$mon/$mday $hour:$min:$sec";
 #($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);



 #
 # but if it is an IP address I use turn off the logging
 #
 @my_ip_addresses = (
                    # maybe john quintos is making all those posts, not drew
                    #'129.219.244.8', # ASU hayden library  - 2 terminals in front
                    '140.198.72.230', # MCC
                    '140.198.73.170', # MCC
                    '140.198.73.121', # MCC
                    '156.42.68.2',    # maricopa county law library
                    '156.42.68.3'     # maricopa county law library
                    );
 #
 # the default is to write the IP address to the log
 #
 $do_the_stinking_log=1;
 #
 # if the current address is one of my IP addresses don't log it
 #
 foreach (@my_ip_addresses) {
    if ( $ENV{REMOTE_ADDR} eq $_) {
       #
       # turn off logging
       #
       $do_the_stinking_log=0;
    }
 } 
#
# log this IP address with the URL that took us to it
# if it aint one of the IP addresses i use
#
 if ($do_the_stinking_log == 1) {
    open(LOGIPADDRESS,'>>counter/ip_log.txt');
    flock(LOGIPADDRESS, 2);
    print LOGIPADDRESS "$zdate $ENV{REMOTE_ADDR} $ENV{HTTP_REFERER}$ENV{REQUEST_URI}\n";
    #print LOGIPADDRESS "$zdate $ENV{REMOTE_ADDR} $ENV{HTTP_REFERER}\n";




    close(LOGIPADDRESS);
 }





 }
done:;
   if ($debug_flag) {
      print "image='$image'<br>";
      print "<img src=\"counter/$image\"><br>";
   }
   else {
      print "Content-type: image/jpeg\n\n";
      #
      # open the image file
      #
      #$i=open(GIFFILE,$src);
      #$i=open(GIFFILE,"counter/$image");
      $i=open(GIFFILE,"counter/0.gif");
      #
      # do i/o in in binary mode as opposed to text
      #
      $i=binmode(GIFFILE);
      #
      # read the image 
      #
      $i=read(GIFFILE,$text,10000000);
      #
      # print the image to the web site
      #
      print $text;
      #
      # close the image file
      #
      close(GIFFILE);
   }
exit;

disk.php

TOC

<?php
#
# get the function to convert raw html to printable html
#
include "html_to_displayable_html.php";
#
if ($set_cookie == '') {
   setcookie("disk1","hot SPICY iron",time()+333333);
   setcookie("diskfood","iron",time()+333333);
   setcookie("disk2","steel",time()+333333);
}
$set_cookie="si";
#
# this session id stuff is for people who refuse to use cookies
# it keeps track of them on the server side instead of with
# cookies on their PC.
# the session lasts until they close their browser window
#
$mysessionid=session_start();
if ( $_SESSION['diskiron'] == '' ) {
   $_SESSION['diskiron']=1;
}
else {
   $_SESSION['diskiron']++;
}
?>
Playing with PHP learning to use stuff that does disk I/O
<p>
cool looks like I am logged in as
<blockquote>
<?php
 echo `whoami`;
?>
</blockquote>
but even a moron could have figured out that!
<p>
Here we have some fun and use
<blockquote>
<nobr>
ls -ltr /tmp| grep miksup|sed -n "/frozen_frogs/d;s/^.* sess/sess/;p"`;
</nobr>
</blockquote>
to get all the session ID files I own.
<p>
Then I use the function
<blockquote>
$bytes=readfile($file);
</blockquote>
to dump the contents of the file to the screen
<p>
<?php
#
# read the session ID file and dump it to the screen
#
  #
  # write a bash script to get the name of the session id file
  #
  #$foo=`ls -ltr /tmp| grep miksup|sed "s/^.* sess/sess/"`;
  $foo=`ls -ltr /tmp| grep miksup|sed -n "/frozen_frogs/d;s/^.* sess/sess/;p"`;
  #echo "foo=<p>$foo<p>";
  #
  # make each file name an element in an array
  # in perl you would use split() but PHP uses explode()
  #
  # hmmmm..... how do you write a /n in PHP????????
  $files=explode("\n",$foo);
  foreach($files as $zfile) {
     if ($zfile != '' ) {
        $zzfile="/tmp/$zfile";
        echo "dumping session file $zzfile";
        echo "<blockquote style=\"background-color:#00ffff;\">";
        echo "<pre>";
        $bytes=readfile($zzfile);
        echo "</pre>";
        echo "The file has $bytes bytes in it";
        echo "</blockquote>";
     }
  }
?>
<p>
Now I will use the function 
<blockquote>
$data=file_get_contents($file);
</blockquote>
to read the entire file into memory
and then I will print the variable $data
<p>
<?php
#
# read the session ID file and dump it to the screen
#
# which is now
#        sess_0c2c4eb739340d3f032f2268c0e5e572
#
  #
  # write a bash script to get the name of the session id file
  #
  #$foo=`ls -ltr /tmp| grep miksup|sed "s/^.* sess/sess/"`;
  $foo=`ls -ltr /tmp| grep miksup|sed -n "/frozen_frogs/d;s/^.* sess/sess/;p"`;
  #echo "foo=<p>$foo<p>";
  #
  # make each file name an element in an array
  # in perl you would use split() but PHP uses explode()
  #
  # hmmmm..... how do you write a /n in PHP????????
  $files=explode("\n",$foo);
  foreach($files as $zfile) {
     if ($zfile != '' ) {
        $zzfile="/tmp/$zfile";
        echo "reading file $zzfile";
        echo "<blockquote style=\"background-color:#ffff00;\">";
        $data=file_get_contents($zzfile);
        echo $data;
        echo "<p>";
        echo "the file has ".strlen($data)." bytes";
        echo "</blockquote>";
     }
  }
?>
<p>
here we will open the file 
<blockquote>
<nobr>
class/data_file.txt
</nobr>
</blockquote>
and dump it several times!
<?php
 echo "dump the file raw!!!";
 $file='data_file.txt';
 echo "<blockquote style=\"background-color:#ff0000;\">";
 $data=file_get_contents($file);
 echo $data;
 echo "</blockquote>";
 echo "dump the file after changing \\n to &lt;br&gt;!!!";
 $file='data_file.txt';
 echo "<blockquote style=\"background-color:#ff00ff;\">";
 $data=file_get_contents($file);
 $data=preg_replace("/\n/","<p>",$data);
 echo $data;
 echo "</blockquote>";
 echo "Now we will use a function to read the file";
 echo "like PERL does with the";
 echo "<blockquote>while(&lt;file&gt;)</blockquote>";
 echo "this is the function";
 echo "<blockquote>\$array=file('filename');</blockquote>";
 $file='data_file.txt';
 echo "<blockquote style=\"background-color:#00ffff;\">";
 echo "<ol style=\"background-color:#ffff00;\">";
 $array=file($file);
 foreach($array as $line) {
    echo "<li>$line";
 }
 echo "</ol>";
 echo "</blockquote>";
?>
<p>
Now we will go into lecture mode about PHP I/O functions.
<p>
The manual says the PHP supports pretty much
all the I/O functions supported by C like:
<ul>
<li>fopen();
<li>fread();
<li>printf();
<li>fwrite();
<li>feof();
<li>getc();
<li>fgets();
<li>....
</ul>
But if you ask me since C doesn't support any record
oriented I/O like PERL does who needs the crap other
when you have some weirdo stuff you do once every 
couple of years.
<p>
PHP also has a bunch of other functions to copy, move,
and check for the existance of files but I wont play
with them here.
<p>
<hr>
<p>
For the last play pen stuff I will write some stuff to a file.
<p>
It will go like this
<ol>
<li>Check to see if the file /tmp/frozen_frogs exists with<blockquote>file_exists($file)</blockquote>
<li>If the file /tmp/frozen_frogs exists read it with <blockquote>$data=file_get_contents($file)</blockquote>
<li>write the file /tmp/frozen_frogs using<blockquote>$byteswritten=file_put_contents ($file,$writestring)</blockquote>which should work if the program is allowed to write stuff in /tmp<p>But for some reason the function <b>file_put_contents()</b> isn't on this machine and that didn't work!
<li>Since we can't use file_put_contents() to write the file we will use fwrite() like this<blockquote>$handle=fopen($file,'wb');<br>$byteswritten=fwrite($handle,$writestring);<br>fclose($handle);</blockquote>
</ol>
<?php
#
# file to write to
#
$file="/tmp/frozen_frogs";
#
# get the date and time and write it to the file
#
$zdate=date("l F j, Y m/d/y H:i:s h:i:s a T U");
#
# string to write to the file
#
$silly="Just where is the EET timezone???? Thats 9 hours from Phoenix!!<p>Google tells me it is Eastern European Time zone which is Finland down to Greece!<p>this silly little string will be written to the file $file";
$stuff="<pre>Service In Use Available
Domains  0  1
Subdomains  1  4
Aliases  0  3
E-mails  0  3
Mailing Lists  0  0
IPs  0  0
FTPs  1  0
Databases  1  0
MySQL MB  0.09  4.91
Traffic MB  0  3000.00
Storage MB  5.13  94.87
Files  485  49515</pre>";
$endsilly="the end of the silly little string written to the file $file";
$writestring="written at $zdate<p>$silly<p>$stuff<p>$endsilly<p>";
function doittoit ($file) {
  echo "checkint to see if file $file exists<br>";
  if (file_exists($file)) {
     echo "&nbsp;&nbsp;&nbsp$file EXISTS<br>";
     echo "trying to read file $file<br>";
     $data=file_get_contents($file);
     echo "<blockquote style=\"background-color:#00ffff;\">";
     echo "if the read worked the data follows";
     echo "<p>";
     echo "$data";
     echo "</blockquote>";
  } else {
     echo "&nbsp;&nbsp;&nbsp<span style=\"background-color:#ff0000;\">$file DOESN'T EXIST</span><p>";
  }
  return;
}
#
# try to dump the file if it exists
# the first time we run this it wont exist
#
doittoit($file);
echo "Writting to the file $file with file_put_contents()<p>";
#echo "string =$writestring<p>";
if (0) {
   $byteswritten=file_put_contents ($file,$writestring);
   echo "bytes written=$byteswritten<p>";
}
else {
   echo "file_put_contents() can't be used on this machine<p>";
   echo "bytes written=0<p>";
}
echo "Writting to the file $file with fwrite()<p>";
$handle=fopen($file,'wb');
$byteswritten=fwrite($handle,$writestring);
fclose($handle);
echo "bytes written=$byteswritten<p>";
#
# dump the file just written
#
doittoit($file);
?>
<p>
Cool PHP lets you treat URLs as disk files and read them!
<p>
ie: you can treat the URL www.sudoku.com as a disk file and read it!
Hmmm.... doesn't that sound like we are writing a socket?
Here are two ways
<blockquote>
$data=file_get_contents("http://www.sudoku.com");
<p>
&nbsp;&nbsp;&nbsp;&nbsp;or
<p>
$file=fopen("http://azcentral.com","r");<br>
$data=fread($file,20000000);<br>
fclose($file);
</blockquote>
<?php
#
# read the web page with file_get_contents();
#
$data=file_get_contents("http://www.sudoku.com");
#
# convert the HTML to html a human can read
#
$data=html_to_displayable_html($data);
#
#display the web page we read as HTML in a table
#
echo "<p>";
echo "the HTML from http://www.sudoku.com";
echo "<p>";
echo "<table border=\"10\">";
echo "<tr><td>";
echo $data;
echo "</td></tr>";
echo "</table";
#
# now we will the the same thing a 2nd time
# but we will do it the hard way using the
# lower level functions that 
# file_get_contents() uses
#
$file=fopen("http://azcentral.com","r");
$data=fread($file,20000000);
fclose($file);
#
# convert the HTML to html a human can read
#
$data=html_to_displayable_html($data);
#
#display the web page we read as HTML in a table
#
echo "<p>";
echo "the HTML from http://azcentral.com";
echo "<p>";
echo "<table border=\"10\">";
echo "<tr><td>";
echo $data;
echo "</td></tr>";
echo "</table";
?>



<p>
This is causing me to barf and sometimes print the number 54.
Maybe that is when I don't have any files!
<p>
Anyhow what I am doing is going
<blockquote>
$foo=`ls -ltr /tmp`
</blockquote>
which lists all the files in the /tmp subdirectory
<p>
Then I just display the out put of the ls command
<p>
<?php
#
# list all the files in the
#        /tmp
# subdirectory.
# when I upload files they are placed here by default
# if i want to keep the uploaded file i have to copy 
# it to an area i own

#
# the SESSION file i create stay around in this subdirectory
# see the very top of this code for the session code
# sessions are a way around cookies and sessions are
# kept on the server side, ie HERE instead of the
# persons pc.
# it is
#  
#             sess_bc0ae1a6a34b098a8e7f434c05fbcec5
#

# the files I upload seem to stay around for a very short time
#
#
#$foo=`ls -ltr /tmp`;
#$foo=`ls -ltr /tmp| grep miksup`;
echo "<pre>$foo</pre>";
?>

display_functions.php

TOC

<?php
#
# include the function
#        html_to_displayable_html()
# which converts HTML to HTML a human
# can read when the browser displays it
#
include "html_to_displayable_html.php";
function display_code($file) {
  #
  # read in a php or PERL program and display it on a web page
  #
  echo "<a name=\"$file\">";
  echo "<h2>$file</h2>";
  echo "<a href=\"#toc-$file\">TOC</a><p>";
  echo "<tt>";
  #
  # read the file into an array
  #
  $array=file($file);
  foreach ($array as $line) {
     #
     # convert the HTML to HTML that a browser can display
     # ie:
     #       <html>
     # becomes
     #       &lt;html&gt;
     #
     # so a human can see what the html looks like
     #
     $line=html_to_displayable_html($line);
     echo "$line<br>";
  }
  echo "</tt>";
  return;
}
?>

display_programs.php

TOC

<?php
include "display_functions.php";
setcookie("a_class.php","a_class.php",time()+333333);
setcookie("class","everybody loves class",time()+333333);
setcookie("notenoughclasses","and nobody gets enough education",time()+333333);
$set_cookie="si";
#
# this session id stuff is for people who refuse to use cookies
# it keeps track of them on the server side instead of with
# cookies on their PC.
# the session lasts until they close their browser window
#
$mysessionid=session_start();
if ( $_SESSION['displaycode'] == '') {
   $_SESSION['displaycode']=1;
}
else {
   $_SESSION['displaycode']++;
}
?>
<h1>Some PHP programs I have written</h1>
<?php
  #
  # list these programs
  #
  $programss=array();
  $programs=array('display_programs.php',
                  'display_functions.php',
                  'a_class.php',
                  'disk.php',
                  'dump_form.php',
                  'dump_vars.php',
                  'extentions.php',
                  'hiworld.php',
                  'hiworld2.php',
                  'phpinfo.php',
                  'email_address_valid.php',
                  'html_to_displayable_html.php',
                  'sockets_kind_of.php',
                  '../add_ceweekly_email.php',
                  '../list_ceweekly_all.php',
                  '../sql_stuff/sql_select_like_perl.php',
                  '../picture_table_size.php',
                  '../picture_table_size_down.php',
                  '../hours.pl',
                  '../cgi-bin/mod.php',
                  '../cgi-bin/mod.pl',
                  '../a_numbers.php',
                  '../a_numbers3.php',
                  '../a_square.php',
                  '../a_square_2.php',
                  '../a_square_2p.php',
                  '../a_square_3p.php',
                  '../counter.pl',
                  '../dump_dir_file2.pl',
                  '../dump_env_data.pl',  
                  '../dump_env_data.php',  
                  '../dump_ip.php',
                  '../dump_the_log_file.php',  
                  '../dump_universal_counters.php',   
                  '../get_my_ip_address.pl',
                  '../dumpiplog.pl',
                  '../email.php',
                  '../hours.pl',
                  '../ip_address_gif.php',
                  '../jpg.php',
                  '../log_comment.php',
                  '../log_them.php',   
                  '../perl_lwp.pl',
                  '../perl_lwp_edits.pl',
                  '../perl_sendmail.pl', 
                  '../perl_test.pl',     
                  '../perl_test2.pl',     
                  '../perl_use_code.pm',    
                  '../phone.pl',    
                  '../picture_table_size.php',    
                  '../picture_table_size_down.php',    
                  '../show_counter_images2.php', 
                  '../show_counter_images.php',      
                  '../sql_stuff/sql_add_counter.php',     
                  '../sql_stuff/sql_base.php',    
                  '../sql_stuff/sql_i_u_d.php',     
                  '../sql_stuff/sql_i_u_d_from.php',  
                  '../sql_stuff/sql_info.php',     
                  '../sql_stuff/sql_insert_delete.php', 
                  '../sql_stuff/sql_select.php',     
                  '../sql_stuff/sql_select_like_perl.php',     
                  '../sql_stuff/sql_update.php',   
                  '../dns_stuff/como.php',    
                  '../dns_stuff/como_form.php',     
                  '../dns_stuff/dns_stuff.php',  
                  '../dns_stuff/eat_the_cookies.php',
                  '../dns_stuff/feed_them_cookies.php',
                  '../dns_stuff/look_up_ip_addresses.php',
                  '../dns_stuff/look_up_url_addresses.php ',
                  '../cgi-bin/dumpfiles.php',
                  'upload_files.php',
                  "dump_socket_header_data.php",
                  "getsocketdataafterheaders.php",
                  "sockets_real_select.php",
                  "send_an_email.php",
                  "modify_php_ini.php",
                  "get_socket_header_data.php",
                  "get_header_content_type.php",
                  "temporary_file.php",
                  "whois_this_url.php",
                  "convert_to_mime_base64.php",
                  "why.php",
                  "why.pl",
                  "whi.php",
                  "clean_php_form_data.php",
                  "double.pl",
                  "double_form.pl",
                  "protected_file.html",
                  "protected_file.php", 
                  "htaccess_dir_needs_password2/index.html",
                  "htaccess_dir_needs_password/index.html",
                  "refresh.html",
                  "../words.pl",
                  "sql_insert_us_states.php",
                  "email_rulers.php",
                  "../cellphones.php",
                  "../pdf_adobe_pdf/program_name.php",
                  "../pdf_adobe_pdf/doesnt_work.php",
                  "../curl_ftp_stuff/ftp_to_gnu.php",
                  "../curl_ftp_stuff/a_curl_stuff.php",
                  "../curl_ftp_stuff/ftp_to_gnu.php",
                  "../curl_ftp_stuff/ftp_to_gnu_wrong_password.php",
                  "../curl_ftp_stuff/simple_ftp_to_gnu.php",
                  "../curl_ftp_stuff/verbose.php",
                  "../curl_ftp_stuff/copy_a_file.php",
                  "../curl_ftp_stuff/list_z_files.php",
                  "../curl_ftp_stuff/remove_sensitive_data.php",
                  "../curl_ftp_stuff/ftp_list_my_site.php",
                  'dump_uploaded_file_info.php'
                  );
  #
  # fix so they sort by program name, then path name
  # not as they are entered above by path name, program name
  #
  foreach($programs as $i) {
     if (preg_match("/\//",$i)) {
        $i=preg_replace("/^(.*\/)(.*)\$/","\$2 \$1",$i); 
        array_push($programss, $i);
     }
     else {
        array_push($programss, $i);
     }
  }
  #
  # sort the programs before listing them
  # by file name, then path name
  #
  asort($programss);
  #
  # delete the orginal array and reload it
  #
  $programs=array();
  #
  # now we have to reverse the path name again
  # so the file can be read
  #
  foreach($programss as $i) {
     if (preg_match("/\//",$i)) {
        $i=preg_replace("/^(.*) (.*)\$/","\$2\$1",$i); 
        array_push($programs, $i);
     }
     else {
        array_push($programs, $i);
     }
  }
  #
  # generate a table of contents of the programs
  #
  echo "<ul>";
  foreach ($programs as $foo) {
     echo "<li>";
     echo "<a name=\"toc-{$foo}\">";
     echo "<a href=\"#$foo\">$foo</a>";
  }
  echo "</ul>";
  #
  # dump out each of the programs
  #
  foreach ($programs as $foo) {
     display_code($foo);
  }
?>

../dns_stuff/dns_stuff.php

TOC

<h2>DNS stuff</h2>
<ul>
<li><a href="../class/whois_this_url.php">Better DNS stuff</a>
<li><a href="../class/whois_this_url.php">whois command</a>
<li><a href="../class/whois_this_url.php">Find out who owns a URL or IP Address</a>
<li><a href="look_up_url_addresses.php">Look up URL addresses</a>
<li><a href="look_up_ip_addresses.php">Look up IP addresses</a>
<li><a href="feed_them_cookies.php">Feed them cookies</a>
<li><a href="eat_the_cookies.php">Mmmm lets eat cookies we have been fed</a>
<script language="php">
echo "<li>";
require('como_form.php');
</script>
</ul>
<?php
?> 
<script language="php">
</script>

../pdf_adobe_pdf/doesnt_work.php

TOC

<h1>Program to create Adobe PDF file</h1>
This program doesn't work because
the required functions are not installed
at this web site.
<p>
When I find a free web site that supports PHP
AND supports PDF files I should try to get
it working
<p>
<?php
echo "creating pdf file p1.pdf<br>";
$pdf=pdf_new();
echo "pdf_new<br>";
pdf_open_file($pdf,'p1.pdf');
echo "pdf_open_file<br>";
$font=pdf_findfont($pdf, "Times-Roman", "host");
echo "pdf_findfont<br>";
pdf_begin_page($pdf, 595, 842);
echo "pdf_begin_page<br>";
pdf_setfont($pdf, $font, 30);
echo "pdf_setfont<br>";
pdf_show_xy($pdf, "Printing text is easy as frogs", 50, 750);
echo "pdf_show_xy<br>";
pdf_end_page($pdf);
echo "pdf_end_page<br>";
pdf_close($pdf);
echo "pdf_close<br>";
pdf_delete($pdf);
?>
<p>
<a href="p1.php">p1.php</a> <a href="p1.pdf">p1.pdf</a>

double.pl

TOC

#!/usr/bin/perl
# print header stuff
#
print "Content-type: text/html", "\n\n";
print "<html>\n";
print "<pre>\n";
#
#
# faking 2 dimensional arrays in PERL
#
my $i;
my $k;
my $item;
#
# perl only supports single subscripted arrays
# but you can fake 2 dimensional subscripted arrays
# by making a single array with a bunch of arrays in it
#
#
# create an array of 10 elements
# each element in this array is another
# array that also has 10 elements
#
my @array=(
           [  0,  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 ]
          );

#
# print each array on a single line
#
for($i=0;$i<10;$i++) {
   for($k=0;$k<10;$k++) {
      $item=$array[$i][$k];
      if ($item < 10) {
         $item=" $item"; 
      }
      print "$item ";

   }
   print "\n";
}
print "\n";
#
# print each array on a single line
# you can use either
#    $array[$i][$k]
# which is the same as
#
for($i=0;$i<10;$i++) {
   for($k=0;$k<10;$k++) {
      $item=$array[$i]->[$k];
      if ($item < 10) {
         $item=" $item"; 
      }
      print "$item ";

   }
   print "\n";
}
print "</pre>\n";

double_form.pl

TOC

#!/usr/bin/perl
# print header stuff
#
require CGI;
use CGI;
$cgi = new CGI;
#
# get the data they entered in the text box
#
$hiddentext=$cgi->param('hiddentext');
print "Content-type: text/html", "\n\n";
print "<html>\n";
print "<pre>\n";
#
#
# faking 2 dimensional arrays in PERL
#
my $i;
my $k;
my $item;
my $command;
#
# perl only supports single subscripted arrays
# but you can fake 2 dimensional subscripted arrays
# by making a single array with a bunch of arrays in it
#
#
# create an array of 10 elements
# each element in this array is another
# array that also has 10 elements
#
my @array=(
           [  0,  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 ]
          );
#
# first time form is displayed use the above data
#
if ($hiddentext eq "" ) {
   #
   # first time around  use the data i initialized above
   # in the fake 2d array
   #
   $hiddentext="frogs";
}
else {
  #
  # 2nd time around get any data the user enters into the form
  #
  for($i=0;$i<10;$i++) {
   for($k=0;$k<10;$k++) {
      # build the commands to get the input data
      # ie:
      #     $in_cell_0_0=$cgi->param('in_cell_0_0');
      # thru
      #     $in_cell_9_9=$cgi->param('in_cell_9_9');
      #
      $command="\$in_cell_$i";
      $command.="_$k=\$cgi->param('in_cell_";
      $command.=$i."_".$k;
      $command.="');";
      #
      # now execute the command built to get the data
      #
      eval $command;
      #
      # now build a 2nd command to set the array to
      # the value sucked in
      # which will be
      #   $array[0][0]=$in_cell_0_0;
      # thru
      #   $array[9][9]=$in_cell_9_9;
      #
      $command="\$array[".$i."][".$k."]=\$in_cell_".$i."_".$k.";";
      #
      # now execute the 2nd command
      #
      eval $command;
   }
  }
}
#
# build the HTML to display 
#
$heredoc = <<THISSHOULDNTMATCHANYTHING;
<FORM action="double_form.pl" method="post"> 
<input type="submit" name=submit value="Submit">
<input type="hidden" name="hiddentext" value="$hiddentext">
<table border="1">
THISSHOULDNTMATCHANYTHING
#
# display the stinking html
#
print $heredoc;
#
# print each array on a single line
#
for($i=0;$i<10;$i++) {
   print "   <tr>\n";
   for($k=0;$k<10;$k++) {
      $item=$array[$i][$k];
      # but this code is the same as the above code
      #       $item=$array[$i]->[$k];
      #
      print "   <td align=\"right\">\n";
      print "      <input type=\"text\" ";
      print " name=\"in_cell_$i";
      print "_$k\" ";
      print "value=\"$item\" size=\"3\">\n";
      print "   </td>\n";

   }
   print "   </tr>\n";
}
print "</table>";

../dump_dir_file2.pl

TOC

#!/usr/bin/perl
require CGI;
use CGI;
$cgi = new CGI;
#
# get the file to print
#
$f=$cgi->param('f');
print "Content-type: text/html", "\n\n";
print "<html>\n";
print "$f<p>";
#
# they can only dump the file if it ends in .txt
#
if (!$f =~ /.*\.txt$/) {
 exit;
}
open(COUNTERS,$f);
while(<COUNTERS>) {
 chomp($_);
 print "$_ <br>";
}
close(COUNTERS);
exit;

../dump_env_data.php

TOC

<h1>PHP ENV variables</h1>
These are in both
<blockquote>
$_SERVER<br>
$HTTP_ENV_VARS<br>
$_ENV
</blockquote>
<table border="1">
<?
function dumpthepuppy($data, $color) {
   #
   # for this variable build a table
   #
   echo "<table border=\"1\" style=\"background-color:$color;\">";
   #
   # list the name of each thing and the 
   # value of each thing in the hash
   #
   foreach ($data as $slot => $value) {
      echo "<tr valign=\"top\">";
      echo "<td>";
      echo "$slot";
      echo "</td>";
      echo "<td>";
      #
      # if the value of the thing is an array
      # then list out the array
      # else display the value of the thing
      #
      if (is_array ($value)) {
         #
         # its an array. build a table to list the array
         #
         echo "<table border=\"1\">";
         #
         # if no elements in the table tell them 
         # when we are done
         #
         $things=0;
         #
         # list each element in the array
         #
         foreach ($value as $thing) {
            #
            # count things listed
            # and list each thing as a row in a table
            #
            $things++;
            echo "<tr>";
            echo "<td>$thing</td>";
            echo "</tr>";
         }
         #
         # its an empty array tell them
         #
         if ($things == 0 ) {
            echo "<tr><td>Empty Array</td></tr>";
         }
         #
         # close the inner table
         #
         echo "</table>";
      }
      else {
         #
         # it is a scalar item.
         # list it
         #
         echo $value;
      }
      #
      # close out this row
      #
      echo "</td>";
      echo "</tr>";
   }
   #
   # end this table
   #
   echo "</table>";
}
#
# the environment variables can be
# listed with any of these 3 things
# the first one $_SERVER is the
# prefered thing to use
#
echo "<table border=\"5\">";
echo "<tr valign=\"top\">";
echo "<td>\$_SERVER";
dumpthepuppy($_SERVER,'#ff0000');
echo "</td>";
echo "<td>\$HTTP_ENV_VARS";
dumpthepuppy($HTTP_ENV_VARS,'#ffff00');
echo "</td>";
echo "<td>\$_ENV";
dumpthepuppy($_ENV,'#ff00ff');
echo "</td>";
echo "</tr>";
echo "</table>";
?>

../dump_env_data.pl

TOC

#!/usr/bin/perl
#$ENV{REMOTE_ADDR}
$debug_flag=0;
#require TripodCGI;
require CGI;
use CGI;
$cgi = new CGI;
#
# get the digit to display
#
print "Content-type: text/html", "\n\n";
print "<html>\n";
print "<h1>PERL ENV variables</h1>\n";
print "<table border=\"1\">\n";
foreach (keys(%ENV)) {
  print "<tr valign=\"top\"><td>$_</td><td>$ENV{$_} &nbsp;</td></tr>";
}
print "</table>";
exit;
  

dump_form.php

TOC

<?php
setcookie("FancyFrogFood","hot SPICY food",time()+333333);
setcookie("food","everybody loves food",time()+333333);
setcookie("notenough","and nobody gets enough of it",time()+333333);
$set_cookie="si";
#
# this session id stuff is for people who refuse to use cookies
# it keeps track of them on the server side instead of with
# cookies on their PC.
# the session lasts until they close their browser window
#
$mysessionid=session_start();
?>
<?php
#
# include this function to clean up the
# data returned from PHP forms
# those annoying forms return
#    ", ', and \
# as
#    \",  \', and \\
#
include "clean_php_form_data.php";
#
# this function builds a SELECT statement 
# that returns a SINGLE selected item
# the next function builds a SELECT statement
# that can return multiple items
#
function build_select($me) {
 #
 # save this in their session id file
 # remember sessions replace cookies but on the server side
 #
 $_SESSION[$me]=$me;
 $select_name="select_".$me;
 #echo "select_name=$select_name<br>";
 if ($me == 'post') {
    $selected_lasttime=$_POST[$select_name];
 }
 if ($me == 'get') {
    $selected_lasttime=$_GET[$select_name];
 }
 #
 # if they selected something save it in the session file
 # remember sessions replace cookies but on the server side
 # count how many times the selected stuff
 #
 if ($selected_lasttime != '' ) {
     if ( $_SESSION['selection'.$selected_lasttime] == '') {
        $_SESSION['selection'.$selected_lasttime]='1';
     }
     else {
        $_SESSION['selection'.$selected_lasttime]++;
     }
 }



 $select_stuff=array('Phoenix','Tucson','Los Angeles','San Francisco', 'Chicago',
                     'Mazatlan','Puerto Vallarta','Tijuana','Ciudad Juarez',
                     'Las Vegas','Santa Ana','East Moline','Moline',
                     'Rock Island','Rocky Point, Sonora',
                     'Davenport, Iowa','Bettendorf, Iowa',
                     'Tokyo','Osaka','Kobe','Henderson','Wickenburg',
                     'Pahrump','Death Valley','Beatty Junction',
                     'Nye','Area 51', 'Groom Lake, Nevada','Ajo, Arizona');
 asort($select_stuff);
 echo "<select name=\"$select_name\">";
 foreach ($select_stuff as $foo) {
    $was_it_me="";
    if ($foo == $selected_lasttime) {
       $was_it_me=" selected ";
    }
    echo "<option value=\"$foo\" $was_it_me >$foo</option>";
 }
 echo "</select>";
 echo "<br>";
 return;
}
#
# this function builds a SELECT statement 
# that returns MULTIPLE selected items
# the prior function builds a SELECT statement
# that can return a single item
#
function build_select_multiple($me) {
 #
 # we are telling it to put the selected items in an array for the multiple select 
 #
 $multiple_select=array();
 #
 #  here we are getting an ARRAY, not a scalar variable
 #  because they can select more then one item
 #
 if ($me == 'post') {
    $multiple_select=$_POST['multiple_select'];
 }
 if ($me == 'get') {
    $multiple_select=$_GET['multiple_select'];
 }



 #
 # in the session file which replaces cookies 
 # but is used on the server side
 # count how many times they selected stuff
 #
 if ($multiple_select != '' ) {
    foreach ($multiple_select as $selectedfood) {
       #echo "$selectedfood<br>";
       if ( $_SESSION['selection'.$selectedfood] == '') {
          $_SESSION['selection'.$selectedfood]=1;
       }
       else {
          $_SESSION['selection'.$selectedfood]++;
       }
    }
 }

 $select_stuff=array('Taco','Sushi','Gram Masala', 'M & Ms', 'Milky Way',
                     'Hamburger','Grilled Cheese','French Fries',
                     'Chicken Burrito','Chorizo Hamburger',
                     'Steak','Baked Potato','Chicken Rice Soup','Barley Soup',
                     'Chile','Potato Chips','Ice Cream','Milkshake',
                     'Jelly Beans','French Bread','Sour Cream and Chives');
 asort($select_stuff);
 #
 # on the multiple select we define an ARRAY as
 #     multiple_select[]
 # to return all the values selected
 #
 echo "<select name=\"multiple_select[]\" MULTIPLE>";
 #
 # loop thru each of the items we want to allow them to select
 #
 foreach ($select_stuff as $foo) {
    #
    # loop thru each of the items they selected
    # and set it as selected if they clicked on it
    # last time
    #
    $was_it_me=" ";
    foreach($multiple_select as $clickedon) {
       if ($clickedon == $foo) {
          $was_it_me=" selected ";
       }
       echo "clicked on $clickedon<br>";
    }
    echo "<option value=\"$foo\" $was_it_me >$foo</option>";
 }
 echo "</select>";
 echo "<br>";
 return;
}
?>
<html>
<table>
<tr valign="top">
<td style="background-color:#00ff00;">
POST FORM
<p>
<form action="dump_form.php" method="post">
<input type="submit" name=submit value="Submit as POST">
<p>
<?php
$il=$_POST['post_input_line'];
$il=clean_php_form_data($il);



$r=$_POST['post_radio'];
$r1="";
$r2="";
$r3="";
if ($r == 'p1' ) {
 $r1=" checked ";
}
if ($r == 'p2' ) {
 $r2=" checked ";
}
if ($r == 'p3' ) {
 $r3=" checked ";
}
$password=$_POST['post_password'];
$password=clean_php_form_data($password);
$cb1=$_POST['post_check_box_1'];
$cb2=$_POST['post_check_box_2'];
$cb3=$_POST['post_check_box_3'];
if ($cb1 == 'on' ) {
   $cb1=" checked ";
}
if ($cb2 == 'on' ) {
   $cb2=" checked ";
}
if ($cb3 == 'on' ) {
   $cb3=" checked ";
}
build_select('post');
build_select_multiple('post');
?>
<input type="password" name="post_password"  <?php echo "value=\"$password\""; ?> >
<br>
<input type="text" name="post_input_line"  <?php echo "value=\"$il\""; ?> >
<br>
<input type="checkbox" name="post_check_box_1"  <?php echo $cb1; ?> >
<input type="checkbox" name="post_check_box_2"  <?php echo $cb2; ?> >
<input type="checkbox" name="post_check_box_3"  <?php echo $cb3; ?> >
<br>
<input type="radio" name="post_radio" value="p1" <?php echo $r1; ?> >1&nbsp;
<input type="radio" name="post_radio" value="p2" <?php echo $r2; ?> >2&nbsp;
<input type="radio" name="post_radio" value="p3" <?php echo $r3; ?> >3&nbsp;
<p>
<input type="hidden" name="hidden_post_variable" value="hidden post data">
<input type="reset" name=reset value="RESET">
</form>
</td>
<td>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</td>
<td  style="background-color:#ffff00;">
GET FORM
<p>
<form action="dump_form.php" method="get">
<input type="submit" name=submit value="Submit as GET">
<p>
<?php
$il=$_GET['get_input_line'];
$il=clean_php_form_data($il);


$r=$_GET['get_radio'];
$r1="";
$r2="";
$r3="";
if ($r == 'g1' ) {
 $r1=" checked ";
}
if ($r == 'g2' ) {
 $r2=" checked ";
}
if ($r == 'g3' ) {
 $r3=" checked ";
}
$password=$_POST['get_password'];
$password=clean_php_form_data($password);
$cb1=$_GET['get_check_box_1'];
$cb2=$_GET['get_check_box_2'];
$cb3=$_GET['get_check_box_3'];
if ($cb1 == 'on' ) {
   $cb1=" checked ";
}
if ($cb2 == 'on' ) {
   $cb2=" checked ";
}
if ($cb3 == 'on' ) {
   $cb3=" checked ";
}
build_select('get');
build_select_multiple('get');
?>
<input type="password" name="get_password"  <?php echo "value=\"$password\""; ?> >
<br>
<input type="text" name="get_input_line"  <?php echo "value=\"$il\""; ?> >
<br>
<input type="checkbox" name="get_check_box_1"  <?php echo $cb1; ?> >
<input type="checkbox" name="get_check_box_2"  <?php echo $cb2; ?> >
<input type="checkbox" name="get_check_box_3"  <?php echo $cb3; ?> >
<br>
<input type="radio" name="get_radio" value="g1" <?php echo $r1; ?> >1&nbsp;
<input type="radio" name="get_radio" value="g2" <?php echo $r2; ?> >2&nbsp;
<input type="radio" name="get_radio" value="g3" <?php echo $r3; ?> >3&nbsp;
<p>
<input type="hidden" name="hidden_get_variable" value="hidden get data">
<input type="reset" name=reset value="RESET">
</form>
</td>
<td>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</td>
<td  style="background-color:#00ffff;">
POST MULTIPART FORM
<p>
<FORM action="dump_form.php" 
      method="post"
      enctype="multipart/form-data">
<INPUT type="submit" value="Submit as POST MULTI-PART"> 
<P>
<INPUT type="file" name="file1">
<BR>
<INPUT type="file" name="file2">
<BR>
<INPUT type="file" name="file3">
<BR>
<INPUT type="file" name="file4">
<p>
<input type="reset" name=reset value="RESET">
 </FORM>
</td>
</tr>
</table>
<?php
#
# this doesnt work
#
##
## dump the stuff in file 1
##
#$file1=array();
#$file1=$_POST['file1'];
#foreach($file1 as $foo) {
#   echo "$foo<br>";
#}
?>






<?php
include "dump_vars.php";
?>
</html>

../dump_ip.php

TOC

<h2>Dump $_ENV with a ForEach into a Table</h2>
<script language="php">
print "<table border=1>";
foreach ($_ENV as $k => $v) {
 print "<tr>";
 #print "\$_='$_'\n";
 print "<td>$k{$_}</td>\n";
 print "<td>$v{$_}</td>\n";
 print "</td>";
 print "</tr>";

print "</table>";
</script>
<h2>Dump $_ENV with print statements</h2>
<script language="php">
echo "xxxxxxxxxxxx<br>";
#print "$_ENV['HTTP_X_FORWARDED_FOR']"; 
echo "xxxxxxxxxxxxxxxxxx<br>";

#$logvar=openlog ("log message", LOG_NDELAY , LOG_USER );
#echo "logvar=$logvar<br>";

$F=fopen("log_file.txt","a");
$logout="";
$seperator="";
print "opening file [\$F=$F]<br>";
foreach ($_ENV as $k => $v) {
 if ($k == 'REMOTE_ADDR' ||
     $k == 'REMOTE_PORT' ||
     $k == 'HTTP_REFERER' ||
     $k == 'HTTP_USER_AGENT' ||
     $k == 'HTTP_VIA' ||
     $k == 'HTTP_X_FORWARDED_FOR' ||
     $k == 'SERVER_ADDR' ||
     $k == 'REQUEST_URI' ||
     $k == 'SERVER_ADDR' ||
     $k == 'HTTP_X_FORWARDED_FOR' ) {
    print "$k $v <br>\n";
    $logout.=$seperator.$k."=".$v;
    $seperator=" ";
 }

#
# dump the data to the log file
#
fwrite ( $F, "$logout\n" );
$rc=fclose($F);
print "<p>closing file [\$F $F] rc=$rc<br>";


#
# now try to do it with $_ENV

echo "<hr>";
echo "SERVER_ADDR=${SERVER_ADDR}<br>";
echo "REMOTE_ADDR=${REMOTE_ADDR}<br>";
echo "REMOTE_PORT=${REMOTE_PORT}<br>";
echo "HTTP_X_FORWARDED_FOR=${HTTP_X_FORWARDED_FOR}<br>";
echo "HTTP_REFERER=${HTTP_REFERER}<br>";
echo "HTTP_USER_AGENT=${HTTP_USER_AGENT}<br>";
echo "HTTP_VIA=${HTTP_VIA}<br>";
echo "REQUEST_URI=${REQUEST_URI}<br>";
echo "SERVER_ADDR=${SERVER_ADDR}<br>";
echo "<hr>";
$logout="";
$logout.=" SERVER_ADDR=${SERVER_ADDR} ";
$logout.=" REMOTE_ADDR=${REMOTE_ADDR} ";
$logout.=" REMOTE_PORT=${REMOTE_PORT} ";
$logout.=" HTTP_X_FORWARDED_FOR=${HTTP_X_FORWARDED_FOR} ";
$logout.=" HTTP_REFERER=${HTTP_REFERER} ";
$logout.=" HTTP_USER_AGENT=${HTTP_USER_AGENT} ";
$logout.=" HTTP_VIA=${HTTP_VIA} ";
$logout.=" REQUEST_URI=${REQUEST_URI} ";
$logout.=" SERVER_ADDR=${SERVER_ADDR} ";
echo "logout=$logout<br>";
$F=fopen("log_file.txt","a");
print "opening file [\$F=$F]<br>";
fwrite ( $F, "log $logout\n" );
$rc=fclose($F);
print "<p>closing file [\$F $F] rc=$rc<br>";



</script>

dump_socket_header_data.php

TOC

<?php
function dump_socket_header_data ($data) {
   $dataheader=explode("\n", $data);
   foreach($dataheader as $theline) {
      #
      # display the header information
      # it ends with a blank line or \r
      #
      if ($theline == "\r") {
         break;
      }
      #
      # display each header line
      #
      $thehtml=html_to_displayable_html($theline);
      echo "$thehtml<br>";
   }
   return;
}
?>

../dump_the_log_file.php

TOC

<?php
require('sql_passwords.php');
#
# get the variables they entered on the form
#
$xpassword=$_POST['password'];
$comment_as_logged="";
if ( $z_hardcoded_password != $xpassword ) {

      $comment_as_logged="<SPAN style=\"font-size: 300%; background-color: rgb(255,0,0);\"><b><i>Invalid Password</i></b></span>";
   }
#
# print the form
#
print "<form action=\"dump_the_log_file.php\" method=\"post\">";
print "<br>";
print "<table>";
print "<tr>";
print "<td>Password:</td>";
print "<td><input type=\"password\" name=\"password\" value=\"$xpassword\"></td>";
print "</tr>";
print "<tr>";
print "<td>&nbsp;</td>";
print "<td><input type=\"submit\" name=submit value=\"Dump the Log File\"></td>";
print "</tr>";
#
# if we wrote something to the log file display it
#
if ($comment_as_logged != "" ) {
   print "<tr>";
   print "<td>&nbsp;</td>";
   print "<td>";
   print "<blockquote><nobr>";
   print "$comment_as_logged";
   print "</blockquote></nobr>";
   print "</td>";
   print "</tr>";
}
print "<tr>";
print "</table>";
?>
<script language="php">
if ( $z_hardcoded_password != $xpassword ) {
     exit;
   }
echo "<h1>Dump of the Log File</h1>";
$file="log_file.txt";
$F=fopen($file,"r");
$contents = fread($F, filesize($file)); 
$rc=fclose($F);
#echo "<h1>Dump</h1>";
#echo "$contents";
#echo "<h1>Split the string</h1>";
$lines = preg_split("/\n/", $contents);
#echo "$lines";

#echo "<h1>Split the string 2</h1>";




echo "<table border=1>";

 echo "<tr>";
 echo "<td>Date</td>";
 echo "<td>Time</td>";
 echo "<td>IP<br>Address</td>";
 echo "<td>URL</td>";
 echo "<td>Port</td>";
 echo "<td>Forward</td>";
 echo "<td>Agent</td>";
 echo "<td>other</td>";
 echo "<td>other</td>";
 echo "<td>other</td>";
 echo "</tr>";



foreach($lines as $x){
 list($d, $t, $i, $u, $p, $f, $o, $l, $m, $n, $q)= preg_split("/ /", $x);
 echo "<tr>";
 echo "<td>$d</td>";
 echo "<td>$t</td>";
 echo "<td>$i</td>";
 echo "<td>$u</td>";
 echo "<td>$p</td>";
 echo "<td>$f</td>";
 echo "<td>$o</td>";
 echo "<td>$l</td>";
 echo "<td>$m</td>";
 echo "<td>$n</td>";
 echo "<td>$q</td>";
 echo "</tr>";
}
echo "</table>";

</script>

../dump_universal_counters.php

TOC

<script language="php">
 #
 # include the passwords and stuff
 #
 include 'sql_passwords.php';
 #
 # connect to SQL
 #
 $link = mysql_connect($z_hardcoded_sqlurl, 
                       $z_hardcoded_database, 
                       $z_hardcoded_password )
                       or die('Could not connect: ' . mysql_error());
 #
 # select the database I want to use
 #
 mysql_select_db($z_hardcoded_database) or die('Could not select database');


 $query = 'SELECT web_page,hits FROM `counters_universal` ';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 #$line = mysql_fetch_array($result, MYSQL_ASSOC);
 echo "<table border=1>";
 while($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    #
    # how to read like PERL does in PHP
    # the name of each selected value is used as a subscript or hash value
    #
    $hits=$line['hits'];
    $url=$line['web_page'];
    #echo "$url $hits ";
    echo "<tr><td>$url</td><td>$hits</td></tr>";
    #foreach ($line as $col_value) {
    #    $zcounter_value=$col_value;
    #}
    #echo "HITS=$zcounter_value<br>";
    $number=$zcounter_value;
    #echo "\$number=$number<br>";
 }
 echo "</table>";



 echo "<p>";
 echo "sorted by name";
 echo "<p>";
 $query = 'SELECT web_page,hits FROM `counters_universal` order by web_page, hits';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 #$line = mysql_fetch_array($result, MYSQL_ASSOC);
 echo "<table border=1>";
 while($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    #
    # how to read like PERL does in PHP
    # the name of each selected value is used as a subscript or hash value
    #
    $hits=$line['hits'];
    $url=$line['web_page'];
    #echo "$url $hits ";
    echo "<tr><td>$url</td><td>$hits</td></tr>";
    #foreach ($line as $col_value) {
    #    $zcounter_value=$col_value;
    #}
    #echo "HITS=$zcounter_value<br>";
    $number=$zcounter_value;
    #echo "\$number=$number<br>";
 }
 echo "</table>";




echo "<p>";
 echo "sorted by hits, name";
 echo "<p>";
 $query = 'SELECT web_page,hits FROM `counters_universal` order by hits, web_page';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 #$line = mysql_fetch_array($result, MYSQL_ASSOC);
 echo "<table border=1>";
 while($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    #
    # how to read like PERL does in PHP
    # the name of each selected value is used as a subscript or hash value
    #
    $hits=$line['hits'];
    $url=$line['web_page'];
    #echo "$url $hits ";
    echo "<tr><td>$url</td><td>$hits</td></tr>";
    #foreach ($line as $col_value) {
    #    $zcounter_value=$col_value;
    #}
    #echo "HITS=$zcounter_value<br>";
    $number=$zcounter_value;
    #echo "\$number=$number<br>";
 }
 echo "</table>";


 // Free resultset
 #
 # close the SQL connection
 #
 // Closing connection
 mysql_close($link);
</script>
<!-- count the counters :) -->
<img src="counter_any_web_site_gif.php" alt="count the counters">

dump_uploaded_file_info.php

TOC

<?php
function dump_uploaded_file_info ($filename) {
   #
   # file name the user at the remote PC selected
   #
   $remotefilename=$_FILES[$filename]['name'];
   #
   # file size
   # 
   $filesize=$_FILES[$filename]['size'];
   #
   # file type
   # 
   $filetype=$_FILES[$filename]['type'];
   # 
   # where the file is stored on this computer
   # and we must move it from there to my
   # local area
   #             cgi-bin/webpages/*
   #
   $localfilename=$_FILES[$filename]['tmp_name'];
   #
   # any errors? errors during upload?
   #
   $errors=$_FILES[$filename]['error'];
   echo "<table border=\"1\" style=\"background-color:#01ffff;\">";
   #
   # file name on the html <input statement
   #
   # if no file uploaded use &nbsp;
   # so the table looks pretty
   #
   $nada="";
   if ($remotefilename == '' ) {
      $nada="&nbsp;";
   }
   #
   # always display filename
   #
   echo "<tr><td>$filename</td><td><nobr>$remotefilename $nada</nobr></td></tr> "; 
   #
   # only display file size, type, unix filename
   # and errors if they uploaded a file
   #
   if ($remotefilename != '' ) {
      echo "<tr><td>&nbsp;</td><td>$filesize bytes</td></tr>"; 
      echo "<tr><td>&nbsp;</td><td><nobr>$filetype</nobr></td></tr>"; 
      echo "<tr><td>&nbsp;</td><td><nobr>$localfilename</nobr></td></tr>"; 
      echo "<tr><td>&nbsp;</td><td><nobr>$errors errors</nobr></td></tr>"; 
   }
   echo "</table>";
   return;
}
?>

dump_vars.php

TOC

<?php
#
# session ids are like cookies
# but sessions are kept on the server side
# the data is stored in a file in the
#       /tmp
# directory so remember ANYBODY can view this data
# also the session is closed when the user closes
# his browser.
# sessions are usefull when people refuse to use cookies
#
# now in the case now i have two different browsers in use
# IE is open in one window and Mozilla is open in another
# thus the session manager treats these as 2 different sessions
#
$mysessionid99=session_start();
if ( $set_cookie == "" ) {
   setcookie("FancyFrogFood","hot SPICY food",time()+333333);
   setcookie("children","everybody loves children",time()+333333);
   setcookie("notmoney","nobody has enough of money",time()+333333);
}
$set_cookie="si";
?>
<p>
Dump some PHP variables!!!! (for  <a href="#ext">PHP extentions</a>)
<?php
#
# session data replaces cookie data
# but session data is kept on the server side
# set a session data value that says they used this code
#
# here we count how many times they have run this program - Cool!
#
if ( $_SESSION['dump_vars.php'] == '' ) {
   $_SESSION['dump_vars.php']=1;
}
else {
   $_SESSION['dump_vars.php']++;
}
function dumpthevars($name, $table) {
   echo "<p>";
   echo "<table border=\"1\">";
   echo "<tr valign=\"top\">";
   echo "<td>$name</td>";
   echo "<td>";
   echo "<table border=\"1\">";
   #foreach($_GET as $key=>$data) {
   foreach($table as $key=>$data) {
      #
      # get the data type of the variable
      #
      $datatype=gettype($data);
      #
      # if the datatype is an array dump out the array
      #
      if ( is_array($data) ) {

         echo "<tr valign=\"top\">";
         echo "<td>$key</td><td><b>$datatype</b>";
         #
         # dump the array as a table
         #
         echo "<table>";
         foreach($data as $lineofdata) {
            echo "<tr><td>$lineofdata</td></td>";
         }
         echo "</table>";


         echo "</td></tr>";
      }
      else {
         echo "<tr><td>$key</td><td>$data</td></tr>";
      }
   }
   echo "</table>";
   echo "</td>";
   echo "</tr>";
   echo "</table>";
return;
}
dumpthevars('$_SESSION', $_SESSION);
dumpthevars('$_GET', $_GET);
dumpthevars('$_POST', $_POST);
dumpthevars('$_FILES', $_FILES);
dumpthevars('$_COOKIE', $_COOKIE);
dumpthevars('$_REQUEST', $_REQUEST);
dumpthevars('$_ENV', $_ENV);
dumpthevars('$_SERVER', $_SERVER);
dumpthevars('$GLOBALS', $GLOBALS);
?>
<p>
<a name="ext">
Dump some loaded PHP extentions!!!!

<?php
  include "extentions.php";
?>


<?php
#echo "<p>";
#$stinking_extensions=0;
#$ext=get_loaded_extensions();
#foreach($ext as $foo) {
#   $stinking_extensions++;
#   echo "&nbsp;&nbsp;&nbsp;$foo<br>";
#   $functions=get_extension_funcs($foo);
#   foreach($functions as $foofoo) {
#      echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$foofoo()<br>";
#   }
#
#}
#if ($stinking_extensions == 0 ) {
#   echo "No extensions loaded<br>";
#}
#echo "<p>";
?>
</html>

../cgi-bin/dumpfiles.php

TOC

<?php
   echo "dumping files<p>";
   $foo=`ls webpages/*`;
   if ($foo != '' ) {
      $array=explode("\n",$foo);
      echo "<ol>";
      foreach ( $array as $li) {
         if ($li != '' ) {
            #
            # is it an images?
            #
            if (preg_match("/.jpg\$/i",$li) || 
                preg_match("/.jpeg\$/i",$li) ||
                preg_match("/.gif\$/i",$li) ||
                preg_match("/.png\$/i",$li)    ) {
               echo "<li><img  src=\"$li\">"; 
            }
            else {
               echo "<li><a href=\"$li\">$li</a>";
            }


         }
      }
      echo "</ol>";
   }
   else {
      echo "no files to list";
   }
   return;
?>

../dumpiplog.pl

TOC

#!/usr/bin/perl
print "Content-type: text/html", "\n\n";
print "<html>\n";
print "<body background=\"nevada.gif\">\n";
print "<table>\n";
print "<tr>\n";
print "<td valign=\"top\">\n";
print "<h2 align=\"center\">Raw</h1>\n";
open(COUNTER,'counter/counter.txt');
print "<table border=1>";
while (<COUNTER>) {
  chomp();
  if ($_ =~ /^[0-9][0-9]*$/) {
     $k=$_;
     $n="&nbsp;";
  }
  else {
     $k=$_;
     $k=~s/^.*=//;
     $n=$_;
     $n=~s/=.*$//;
  }
  print "<tr>\n";
  #print "<td>$_</td>\n";
  print "<td align=right>$k</td>\n";
  print "<td>$n</td>\n";
  print "</tr>\n";
}
close(COUNTER);
print "</table>\n";
print "</td>\n";
print "<td valign=\"top\">\n";








print "<h2 align=\"center\">Name</h1>\n";
open(COUNTER,'counter/counter.txt');
@table=<COUNTER>;
close(COUNTER);
print "<table border=1>";
#for($i=0;$i<$#table;$i++) {
foreach(sort @table) {
  #$_=$table[$i];
  chomp();
  if ($_ =~ /^[0-9][0-9]*$/) {
     $k=$_;
     $n="&nbsp;";
  }
  else {
     $k=$_;
     $k=~s/^.*=//;
     $n=$_;
     $n=~s/=.*$//;
  }
  print "<tr>\n";
  #print "<td>$_</td>\n";
  print "<td align=right>$k</td>\n";
  print "<td>$n</td>\n";
  print "</tr>\n";



  if ($_ =~ /^[0-9][0-9]*$/) {
     while(length($_) < 20 ) {
       $_="0".$_;
     }
  }
  else {
     while(length($k) < 20 ) {
       $k="0".$k;
     }
     $_="$k"."="."$n";
  }
  push(@table2, $_);
}
print "</table>\n";
print "</td>\n";
print "<td valign=\"top\">\n";




print "<h2 align=\"center\">Kount</h1>\n";
#@table2=@table;
print "<table border=1>";
foreach(sort @table2) {
  #$_=$table[$i];
  chomp();
  if ($_ =~ /=/) {
    $_=~s/([0-9][0-9]*)=(.*)/$2=$1/;
  }
  if ($_ =~ /^[0-9][0-9]*$/) {
     $k=$_;
     $k=$k+0;
     $n="&nbsp;";
  }
  else {
     $k=$_;
     $k=~s/^.*=//;
     $n=$_;
     $n=~s/=.*$//;
     $k=$k+0;
  }
  print "<tr>\n";
  #print "<td>$_</td>\n";
  print "<td align=right>$k</td>\n";
  print "<td>$n</td>\n";
  print "</tr>\n";
}
print "</table>\n";

print "</td>\n";


print "</tr>\n";
print "</table>\n";

#print "<h2 align=\"center\">Dump Log File</h1>\n";
#print "<table border=1>";
open(LOGIPADDRESS,'counter/ip_log.txt');
while (<LOGIPADDRESS>) {
  #print "$_<br>";
  #print "<tr valign=\"top\">\n";
  #
  # allow comments in the log file
  # just skip over them
  #
  if ($_ =~ /^ *#/ ) {
     #continue;
     #print "skipping $_ <br>";
     goto sinfull;
  }
  #
  # split the record into
  # date, time, ip-address, and URL
  #
  ($d, $t, $ip, $url)=split(' ',$_);
  $ip3=$ip;
  $ip3=~s/\.[0-9]*$//;
  $hour=$t;
  $hour=~s/:.*$//;
  if ( $url =~ /^ *$/ ) {
     $url="&nbsp;";
  }
  else {
     $url=~s/.*/<a href="$&">$&<\/a>/;
  }
  #print "<td>$d</td>\n";
  #print "<td>$t</td>\n";
  #print "<td>$ip</td>\n";
  #print "<td>$url</td>\n";
  #print "</tr>\n";
  #
  # count each unique date
  #
  if ($date{$d} eq "" ) {
   $date{$d}=1;
  }
  else {
   $date{$d}++;
  }
  #
  # count each unique URL
  #
  if ($urls{$url} eq "" ) {
   $urls{$url}=1;
  }
  else {
   $urls{$url}++;
  }


  #
  # count each unique IP address
  #
  if ($ips{$ip} eq "" ) {
   $ips{$ip}=1;
  }
  else {
   $ips{$ip}++;
  }
  #
  # count each unique 3 digit IP address
  #
  if ($ip3s{$ip3} eq "" ) {
   $ip3s{$ip3}=1;
  }
  else {
   $ip3s{$ip3}++;
  }
  #
  # count the hits in each hour
  #
  if ($hours{$hour} eq "" ) {
   $hours{$hour}=1;
  }
  else {
   $hours{$hour}++;
  }
sinfull:;
}
close(LOGIPADDRESS);
#print "</table>\n";




print "<h2 align=\"center\">Count by Date</h1>\n";
print "<table border=1>";
foreach (keys %date) {
 print "<tr>\n";
 print "<td align=right>$date{$_}</td>\n";
 print "<td>$_</td>";
 print "</tr>\n";

print "</table>";




#####################################################
#####################################################

print "<h2>Hits by Date</h2>\n";
print "<h4>This is from the file ip_log.txt and it is the number of hits your web site(s) received each day</h4>\n";
print "<h4>Sort Date is sorted by date, Count is sorted by the number of hits, Raw Date is how PERL stores the data internally in a hash and is for debugging</h4>\n";
print "<table border=1>";
print "<tr>";

print "<td>";
print "<h2 align=\"center\">Raw Date</h1>\n";
print "<table border=1>";
@datetable=();
@kountdatetable=();
foreach (keys %date) {
 $datekount=$date{$_};



 #while (length($datekount) < 10 ) {
 #  $datekount="0".$datekount;
 #}


 $datekount=&add_leading_zeros($datekount,10);





 push(@datetable, $_.":".$date{$_});
 push(@kountdatetable, $datekount.":".$_);
 print "<tr>\n";
 print "<td align=right>$date{$_}</td>\n";
 print "<td>$_</td>";
 print "</tr>\n";

print "</table>";
print "</td>";








@datetable2=sort(@datetable);
$i=0;
print "<td>";
print "<h2 align=\"center\">Sort Date</h1>\n";
print "<table border=1>";
foreach (keys %date) {
#foreach(sort @table2) {
 print "<tr>\n";
 #print "<td align=right>$date{$_}</td>\n";
 #print "<td>$_</td>";
 #print "<td>$datetable2[$i]</td>";
 ($k,$j)=split(':', $datetable2[$i]);
 #print "<td>$j $k</td>";
 print "<td align=\"right\">$j</td>";
 print "<td>$k</td>";
 $i++;
 print "</tr>\n";

print "</table>";
print "</td>";








@datetable3=sort(@kountdatetable);
$i=0;
print "<td>";
print "<h2 align=\"center\">Count Date</h1>\n";
print "<table border=1>";
foreach (keys %date) {
#foreach(sort @table2) {
 print "<tr>\n";
 #print "<td align=right>$date{$_}</td>\n";
 #print "<td>$_</td>";
 #print "<td>$datetable3[$i]</td>";
 ($j,$k)=split(':', $datetable3[$i]);
 #print "<td>$j $k</td>";
 #while ($j =~ /^0/) {
 # $j=s/^0//;
 #}
 $j=$j*1;
 print "<td align=\"right\">$j</td>";
 print "<td>$k</td>";
 $i++;
 print "</tr>\n";

print "</table>";
print "</td>";





print "</tr>";
print "</table border=1>";



#####################################################
#####################################################













#
# only print the count by URL after sorting
# it by the number of hits on the URL
#
print "<h2 align=\"center\">Count by URL</h1>\n";
print "<table border=1>";
foreach (keys %urls) {
 print "<tr valign=\"top\">\n";
 print "<td align=right>$urls{$_}</td>\n";
 print "<td>$_</td>";
 print "</tr>\n";

print "</table>";

























#
# sort by the number of hits on the url's
# grab the data
#
$kount=0;
foreach (keys %urls) {
 $names[$kount]=$_;
 $values[$kount]=$urls{$_};
 $kount++;

#
# sort the puppies
#
$kount2=$kount;
$changed="y";
while ($kount2 > 1 && $changed eq "y") {
 $changed="n";
 for ($i=0;$i<$kount2;$i++) {
  #print "compare $i $kount2<br>";
  #
  # if the 2nd count is greater 
  # then the first counter then swap them
  #
  if ($values[$i] > $values[$i+1] ) {
    $temp=$values[$i];
    $values[$i]=$values[$i+1];
    $values[$i+1]=$temp;
    $temp=$names[$i];
    $names[$i]=$names[$i+1];
    $names[$i+1]=$temp;
    $changed="y";
  }
  #
  # if the counters are equal
  # AND the second URL less then the first URL
  # then switch the URL's
  #
  if ($values[$i] == $values[$i+1] ) {
     if ($names[$i] gt $names[$i+1] ) {
        $temp=$names[$i];
        $names[$i]=$names[$i+1];
        $names[$i+1]=$temp;
        $changed="y";
     }
  }
 }
 $kount2--;
}

print "<h2 align=\"center\">Count by URL hits</h1>\n";
print "<table border=1>";
for ($i=0;$i<=$kount;$i++) {
 print "<tr>\n";
 print "<td align=right valign=top>$urls{$names[$i]}</td>\n";
 print "<td valign=top>$names[$i]</td>";
 print "</tr>\n";

print "</table>";





for ($i=0;$i<=24;$i++) {
 $zhour[$i]=0;
}

#
# only print hours after sorting them
#
#print "<h2 align=\"center\">Count by Hour</h1>\n";
#print "<table border=1>";
foreach (keys %hours) {
 #print "<tr>\n";
 #print "<td align=right>$hours{$_}</td>\n";
 $zhour[$_]=$hours{$_};
 #print "<td>$_</td>";
 #print "</tr>\n";

#print "</table>";




print "<h2 align=\"center\">Count by Hour</h1>\n";
print "<table border=1>";
$k=-12;
$part="a.m.";
$part2="";
for ($i=0;$i<=24;$i++) {
 if ($i == 12 ) {
    $part="p.m.";
 }
 if ($i > 12 ) {
    $part2=" $k p.m.";
 }
 if ($zhour[$i] != 0 ) {
    print "<tr>\n";
    print "<td align=right>$zhour[$i]</td>\n";
    $x="";
    if ($i < 10 ) {
      $x="0";
    }
    print "<td>$x$i $part$part2</td>";
    print "</tr>\n";
 }
 $k++;
 

print "</table>";




#
# zero the table of IP to be sorted by number IP hits
# and by IP address
@iptable=();
@kountiptable=();


print "<h2 align=\"center\">Count by IP address</h1>\n";



print "<table border=1>";
print "<tr>";
print "<td>";
print "Raw";
print "<table border=1>";
foreach (keys %ips) {
 #
 # get the count
 #
 $ipkount=$ips{$_};
 #
 # convert the count into a 10 digit number so we can sort it
 #



 #while (length($ipkount) < 10 ) {
 #  $ipkount="0".$ipkount;
 #}

 $ipkount=&add_leading_zeros($ipkount,10);






 #print "debug1x". $_.":".$ips{$_};
 #print "debug2x". $ipkount.":".$_;
 #
 # convert the IP into 3 digits for each node so it sorts
 # 
 $ips3=&lenthen_ip_address($_);
 #
 # save two versions - one with IP first - to be sorted by IP
 #                     one with hits first - to be sorted by hits
 push(@iptable, $ips3.":".$ips{$_});
 push(@kountiptable, $ipkount.":".$ips3);
 #
 # dump out the data as it is coming to us
 #
 print "<tr>\n";
 print "<td align=right>$ips{$_}</td>\n";
 print "<td>$_</td>";
 print "</tr>\n";

print "</table>";
print "</td>";
print "<td>";
print "IP Address";
#
#sort by the IP address
#
print "<table border=\"1\">";
foreach(sort @iptable) {
 ($k,$j)=split(':', $_);
 #
 # remove the leading zeros from the IP address before printing
 #
 $k=&shorten_ip_address($k);
 print "<tr><td align=\"right\">$j</td><td>$k</td></tr>\n";
}
print "</table>";
print "</td>";
print "<td>";
print "Kount";
#
# sort by the number of hits per IP address
#
print "<table border=\"1\">";
foreach(sort @kountiptable) {
 ($k,$j)=split(':', $_);
 #
 # the next RE is OK because we will never have (0) zero hits
 #
 $k=~s/^0*//g;
 #
 # remove the leading zeros from the IP address
 #
 $j=&shorten_ip_address($j);
 print "<tr><td align=\"right\">$k</td><td>$j</td></tr>\n";
}
print "</table>";




print "</td>";
print "</tr>";


print "</table>";





print "<h2 align=\"center\">Count by 1st 3 bytes of IP address</h1>\n";
print "<table border=1>";
foreach (keys %ip3s) {
 print "<tr>\n";
 print "<td align=right>$ip3s{$_}</td>\n";
 print "<td>$_</td>";
 print "</tr>\n";

print "</table>";



exit;



sub shorten_ip_address() {
 #
 # remove the leading zeros in an IP address
 # 001.001.001.001 ->     1.1.1.1
 # 099.099.099.099 -> 99.99.99.99
 # 100.099.099.001 -> 100.99.99.1
 # 100.099.001.001 ->  100.99.1.1
 #
 my $oldip=@_[0];
 my $j=$oldip;
 #print "oldip=$oldip<br>";
 #
 # remove leading zeros from the first digit of the IP address
 #
 $j=~s/^00([0-9])\./$1./;
 $j=~s/^0([0-9][0-9])\./$1./;
 #
 # remove leading zeros from the middle two digits of the IP address
 # for some reason the s///g doesnt work
 #
 $j=~s/\.00([0-9])\./.$1./;
 $j=~s/\.00([0-9])\./.$1./;
 $j=~s/\.0([0-9][0-9])\./.$1./;
 $j=~s/\.0([0-9][0-9])\./.$1./;
 #
 # remove leading zeros from the last part of the IP address
 #
 $j=~s/\.00([0-9])$/.$1/;
 $j=~s/\.0([0-9][0-9])$/.$1/;
 #print "j=$j<br>";
 return $j;
}





sub lenthen_ip_address() {
 #
 # remove the leading zeros in an IP address
 # 1.1.1.1     -> 001.001.001.001     
 # 99.99.99.99 -> 099.099.099.099 
 # 100.99.99.1 -> 100.099.099.001
 # 100.99.1.1  -> 100.099.001.001  
 #
 my $oldip=@_[0];
 my  $ips3=$oldip;
 #print "ips3=$ips3<br>";
 #
 # convert the last ip digit from
 #    0 -> 000
 #   10 -> 010
 #  xxx -> no change
 #
 $ips3=~s/(\.)([0-9])$/.0$2/;
 $ips3=~s/(\.)([0-9][0-9])$/.0$2/;
 #
 # do the middle two digits
 # for some reason s///g did not work
 # so i had to use two s///'s
 #
 $ips3=~s/(\.)([0-9])(\.)/.0$2./;
 $ips3=~s/(\.)([0-9])(\.)/.0$2./;
 $ips3=~s/(\.)([0-9][0-9])(\.)/.0$2./;
 $ips3=~s/(\.)([0-9][0-9])(\.)/.0$2./;
 #
 # convert the first IP digit
 #
 $ips3=~s/^([0-9])\./0$1./;
 $ips3=~s/^([0-9][0-9])\./0$1./;
 #print "ips3=$ips3<br>";
 return $ips3;
}










sub add_leading_zeros() {
 #
 # convert an integer to a long number with leading zeros so we can sort it as ascii text
 #

 my $num=@_[0];
 my $digits=@_[1];
 #print "in=$num<br>";
 if ($digits !~ /^[0-9][0-9]*$/ ) {
   print "error digits must be numeric. digits='$digits'<br>\n";
 }
 if ($digits < 1 ) {
   print "error digits must be one or more. digits='$digits'<br>\n";
 }
 while(length($num) < $digits ) {
    $num="0".$num;
 }
 #print "out=$num<br>";
 return $num;
}

../dns_stuff/eat_the_cookies.php

TOC

<h1>List my cookies</h1>
<table border=1>
<?php
 foreach ($_COOKIE as $k => $v) {
    echo "<tr><td>$k</td><td>$v</td></tr>";
 }
?>
</table>
<p>
A hack to print them quickly
<p> 
 print_r($_COOKIE);
<p>
<?php
 print_r($_COOKIE);
?>

../email.php

TOC

<?php
echo "<h1>it doesnt look like this mail stuff works - MAYBE</h1>";
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: snail@aztec.asu.edu' . "\r\n" .
   'Reply-To: doghair@whitehouse.gov' . "\r\n" .
   'X-Mailer: PHP/' . phpversion();

$rc=mail($to, $subject, $message, $headers);
echo "<table border=1>";

echo "<tr><td>rc</td><td>$rc</td></tr>";
echo "<tr><td>to</td><td>$to</td></tr>";
echo "<tr><td>subject</td><td>$subject</td></tr>";
echo "<tr><td>headers</td><td>$headers</td></tr>";
echo "<tr><td>message</td><td>$message</td></tr>";




echo "</table>";
?>

email_address_valid.php

TOC

<html>
<h1>Is this E-mail Address Valid?</h1>
Add a server to the list
<form action="email_address_valid.php" method="post">
<input type="text" name="stinkingserver"
<?php 
$stinkingserver=$_POST['stinkingserver'];
$stinkingserver=preg_replace("/^ */","",$stinkingserver);  
$stinkingserver=preg_replace("/ *\$/","",$stinkingserver); 
echo "value=\"$stinkingserver\""; 
?>
>
<input type="submit" name=submit value="Submit">
<p>
</form>
<p>
Use this little snippet of code to find out
<blockquote>
<pre>
   $rc=getmxrr($host,$results,$weight);
   $i=0;
   foreach($results as $foo) {
      echo " $foo  $weight[$i] ";
      $i++;
   }
</pre>
</blockquote>
<table border=1>
<tr><th>Server</th><th colspan=2>&nbsp;</th></tr>
<tr><th>&nbsp;</th><th colspan=2>Records Exist</th></tr>
<tr><th>&nbsp;</th><th>MX Record</th><th>Weight</th></tr>
<?php

#
# create a null array
#
$hosts=array();
#
# if they entered something add it to the front of the array
#
if ($stinkingserver != "" ) {
   array_push($hosts, $stinkingserver);
}
#
# create the 2nd array
#
$hosts2=array("yahoo.com",
             "aztec.asu.edu",
             "asu.edu",
             "fastq.com",             
             "gmail.com",
             "arizona.gov",
             "az.gov",
             "az.us",
             "state.az.us",
             "azleg.state.az.us",
             "tempe.gov",
             "tempe.com",
             "tempe.us",
             "tempe.az.us",
             "aol.com",
             "bust.com",
             "searchbigdaddy.com",
             "emerchantdirect.com",
             "maricopa.gov",
             "maricopa.edu",
             "whitehouse.gov",
             "whitehouse.com",
             "whitehouse.org",
             "whitehouse.net",
             "whitehouse.edu",
             "ibm.com",
             "microsoft.com",
             "microsnot.com",
             "army.mil",
             "navy.mil",
             "marines.mil",
             "airforce.mil",
             "usaf.mil",
             "senate.gov",
             "congress.gov",
             "house.gov",
             "president.gov",
             "1stcounsel.com"
             );
#
# sort the 2nd array
#
asort($hosts2);
#
# merge the 2 arrays
#
$hosts=array_merge($hosts, $hosts2);
#
# for each host name get the mail exchange information
#
foreach ($hosts as $host) {
   echo "<tr><td><b>$host</b></td><td colspan=2>&nbsp;</td></tr>";
   #
   # get the mail exchange information
   #
   $rc=getmxrr($host,$results,$weight);
   #
   # if the rc is null i dont think the URL exists
   #
   if ($rc=="") {
      $records="<span style=\"background-color=#ff0000\">NONE</span>";
   }
   else {
      #
      # if the rc is 1 i think the site has a e-mail
      # even if no names are returned
      #
      if ($rc == 1 ) {
         $records="&nbsp;";
      }
      else {
         $records="span style=\"background-color=#ffff00\">$rc</span>";
      }
   }
   
   echo "<tr><td>&nbsp;</td><td colspan=2>$records</td></tr>";
   #
   # list each MX name for this server along with the weight
   # wonder what weight is?
   #
   $i=0;
   foreach($results as $foo) {
      echo "<tr><td>&nbsp;</td><td>$foo</td><td>$weight[$i]</td></tr>";
      $i++;
   }
}
?>
</table>

email_rulers.php

TOC

<?php
   #
   # get the country code and state code
   # so we can figure out which screens to display
   #
   $country_code=$_POST['country_code'];
   $state_code=$_POST['state_code'];
   $state_entities=array();
   $state_entities=$_POST['state_entities'];
   $county_entities=array();
   $county_entities=$_POST['county_entities'];
   $city_entities=array();
   $city_entities=$_POST['city_entities'];
   $other_entities=array();
   $other_entities=$_POST['other_entities'];
   #
   # federal rulers that are only to peole in the state selected
   # such as federal senators for arizona
   #         federal house members for arizona
   #
   $federal_entities=array();
   $federal_entities=$_POST['federal_entities'];
   #
   # federal rulers that are common to the
   # people in every state in the country
   # ie: stuff like president, vice-president
   #
   $federal_all=array();
   $federal_all=$_POST['federal_all'];
   #
   # set up the stuff we need to talk to MySQL 
   #
   require('../sql_passwords.php');
  #
  # connect to SQL
  #
  $link = mysql_connect($z_hardcoded_sqlurl, 
                        $z_hardcoded_database, 
                        $z_hardcoded_password )
                        or die('Could not connect: ' . mysql_error());
  #
  # select the database I want to use
  # 
  mysql_select_db($z_hardcoded_database) or die('Could not select database');




function is_item_selected ($stuff_checked, $item) {
   #
   # if they checked or selected a option in a select clause
   # return the word
   #
   #    ' selected ' 
   # which can be used to put into the <option selected value=""> html
   #
   # to say they selected the item the last time around
   #
   $is_it_checked="";
   #
   # do we have any items that were checked
   #
   if (is_array($stuff_checked)) {
      #
      # some checked items exist
      # loop thru them and see if this one was one of them
      #
      foreach ($stuff_checked as $i ) {
         #
         # was this item checked?
         #
         if ($i == $item) {
            #
            # set the puppy as checked
            # and return to caller
            #
            $is_it_checked=" selected ";
            return $is_it_checked;
         }
      }
   }
   #
   # nothing checked
   # get outta here!
   #
   return $is_it_checked;
}



function is_box_checked($stuff_checked, $item) {
   #
   # if they checked a checkbox return the word
   #    ' checked ' 
   # which can be used to put into the checkbox
   # to say they checked the box the last time around
   #
   $is_it_checked="";
   #
   # do we have any items that were checked
   #
   if (is_array($stuff_checked)) {
      #
      # some checked items exist
      # loop thru them and see if this one was one of them
      #
      foreach ($stuff_checked as $i ) {
         #
         # was this item checked?
         #
         if ($i == $item) {
            #
            # set the puppy as checked
            # and return to caller
            #
            $is_it_checked=" checked ";
            return $is_it_checked;
         }
      }
   }
   #
   # nothing checked
   # get outta here!
   #
   return $is_it_checked;
}




function get_state_code($country_code) {
   #
   # get all the states for this country
   #
   $query = "SELECT ns, state FROM rulers_states where n=$country_code order by state";
   $result = mysql_query($query) or die('Query failed: ' . mysql_error());
   #
   # display the selected stuff
   #
?>
<form action="<?php
       #
       # tell it to run the name of this script
       # when they click on the submit button
       # 
       # get the FULL name of this script 
       #
       $this_script=$_SERVER['SCRIPT_FILENAME'];
       # 
       # rip off the leading subdirectories 
       #
       $this_script=preg_replace("/^.*\//","",$this_script);
       # 
       # print the name to use in the submit button 
       #
       echo $this_script;?>" 
      method="post">  
<input type="submit" name=submit value="Send">
<br>
<?php
   $rows=mysql_num_rows($result);
   if ($rows < 1 ) {
      echo "<p>";
      echo "Error $rows rows returned<br>";
      echo "By this query";
      echo "<blockquote>$query</blockquote>";
      echo "in Function";
      exit; 
   }
   #
   # get all the states for this country
   #
   while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {   
      echo '<input type="radio" name="state_code"  value="';
      echo $line['ns'];
      echo '">';
      echo $line['state'];
      echo "<br>";
   }
   #
   # make the country_code a hidden input so
   # we get it on the next pass
   #
   echo '<input type="hidden" name="country_code" value="';
   echo $country_code;
   echo '">';
?>
</form>
<?php
   #
   # i am not sure but i think this frees the
   # stuff associated with the current select so
   # you can do a new select
   #
   // Free resultset
   mysql_free_result($result);
   return;
}




















function get_country_code() {
   $query = 'SELECT n, country FROM rulers_countries order by country ';
   $result = mysql_query($query) or die('Query failed: ' . mysql_error());
   #
   # display the selected stuff
   #
?>
<form action="<?php
       #
       # tell it to run the name of this script
       # when they click on the submit button
       # 
       # get the FULL name of this script 
       #
       $this_script=$_SERVER['SCRIPT_FILENAME'];
       # 
       # rip off the leading subdirectories 
       #
       $this_script=preg_replace("/^.*\//","",$this_script);
       # 
       # print the name to use in the submit button 
       #
       echo $this_script;?>" 
      method="post"> 
<input type="submit" name=submit value="Send">
<br>
<?php
 $rows=mysql_num_rows($result);
 if ($rows < 1 ) {
    echo "<p>";
    echo "Error $rows rows returned<br>";
    echo "By this query";
    echo "<blockquote>$query</blockquote>";
    echo "in Function";
    exit; 
 }
 #
 # display all the countries that exist
 #
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {    
    $select_item_1=$line['n'];  # 'name' is the value selected 
    $select_item_2=$line['country']; # 'count' is the value selected
    echo '<input type="radio" name="country_code"  value="';
    echo $line['n'];
    echo '">';
    echo $line['country'];
    echo "<br>";
 }
?>
</form>
<?php
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 return;
}


function dump_file_length_header($data) {
}
function tell_em_about_attached_file($fname,$attachment,$name) {
}
function build_tr_for_file($file) {
}
function get_blank_lines($count) {
}
function tell_about_file_uploaded_to_us ($file) {
}

function setup_call_to_attach_file ($zname, $attachment, $attachmentname, $cr_before, $cr_after, $dump_flength, $dont_use_imap) {
}
function attach_a_file_to_headers($file, $attachment, $name, $filename, $cr_before, $cr_after, $dump_flength, $dont_use_imap) {
}
?>
<html>
<?php

if ($country_code == '' ) {
   #
   # ask them what country they want to email
   #
   get_country_code();
   exit;
}
else {
   #
   # if we dont have a state code
   # get a state code
   #
   if ($state_code == '' ) {
      get_state_code($country_code);
      exit;
   }
   else {
      #
      # we have a country and a state code
      # so we can ask them who they want to 
      # send emails to!
      #echo "GOT state code $state_code<p>";
   }
}








#
# print our ip address
#
if (0) {
   echo "IP Address=";
   echo ${REMOTE_ADDR};
   echo "<p>";
}
#
# if we are at the lycos site print
# a few blank lines at the top to
# get around their annoying headers
#
if (${REMOTE_ADDR} == '156.42.68.5') {
   for ($i=0;$i<3;$i++) {
      echo "&nbsp;<p>";
   }
}
?>
<p>
<?php
#
# include this function to clean up the
# data returned from PHP forms
# those annoying forms return
#    ", ', and \
# as
#    \",  \', and \\
#
#
# since i am giving this to grey DONT
# include the function. hard code it
#
#include "clean_php_form_data.php";
function clean_php_form_data($data) {
   #
   # for some reason when you enter the characters
   #     ", ', and \
   # into a PHP form they are returned as
   #     \", \', and \\
   #
   # well this function cleans up the data
   # and removes the annoying backslashes
   #
   # oddly data is NOT returned this way in PERL
   #
   $data=preg_replace('/\\\\\'/',"'",$data);
   $data=preg_replace('/\\\\\"/','"',$data);
   $data=preg_replace('/\\\\\\\\/',"\\",$data);
   return $data;
}
#
function sum_total_errors($data, $total_errors) {
   if ($data != '' ) {
      $total_errors++;
   }
   return $total_errors;
}
function clean_up_to_lines($data) {
    #
    # remove leading and trailing spaces
    #
    $data=preg_replace("/^ */","",$data);
    $data=preg_replace("/ *\$/","",$data);
    #
    # remove extra spaces
    #
    $data=preg_replace("/  */"," ",$data);
    #
    # remove leading and trail spaces from
    #       < frog@dog.com   >
    $data=preg_replace("/ *< */","<",$data);
    $data=preg_replace("/ *> */",">",$data); 
    #
    # remove leading and trail spaces from commas that
    # seperate email addresses
    #      frog@god.com     ,   me@superman.gov
    #
    $data=preg_replace("/ *, */",",",$data);
    return $data;
}
function get_address_errors($data) {
    $errors="";
    if ($data != '' ) {
       $names=explode(",",$data);
       foreach ($names as $n) {
          #
          # remove leading and trailing spaces
          #
          $n=preg_replace("/^ */","",$n);
          $n=preg_replace("/ *\$/","",$n);
          #
          # if you have
          #        tom jones <you@email.com>
          # we have to validate the stuff enclosed in <>
          # as the email address and ignore the other stuff
          # this code should do that
          #
          $nn=$n;
          if (preg_match("/<.*>/",$nn)) {
             $nn=preg_replace("/^.*</","",$nn);
             $nn=preg_replace("/>.*\$/","",$nn);  
          }
          #
          # now validate the email address
          # if the email address contains spaces
          # it is invalid
          #
          if (preg_match("/ /",$nn)) {
             if ($errors == '' ) {
                $errors=$n;
             }
             else {
                $errors.=" $n";
             }
          }
          else {
             #
             # if the email address is not in the form
             #     something@somewhere.xxx
             # it is invalid
             #
             if (! preg_match("/[^@]+@[^@]+\.[^@]+/",$nn)) {
                if ($errors == '' ) {
                   $errors=$n;
                }
                else {
                   $errors.=" $n";
                }
             }
             else {
                #
                # and it cant end or begin with
                # these letters
                # nor can it have @....@ in it
                # nor can it have .. or 2 dots next to each other
                #
                $nonos="\.@";
                if (preg_match("/^[$nonos]/",$nn)  || 
                    preg_match("/[$nonos]\$/",$nn) || 
                    preg_match("/\.\./",$nn) || 
                    preg_match("/@.*@/",$nn)) {
                   #
                   # we have either
                   #    illegal begining or ending characters
                   #    multiple @ signs
                   #
                   if ($errors == '' ) {
                      $errors=$n;
                   }
                   else {
                      $errors.=" $n";
                   }
                }
             }
          }
       }
    }
    #
    # if email addresses have stuff like
    #        tom & bob <thoseguyes@email.com>
    # convert it so it is displayable
    #
    $errors=htmlentities($errors);
    #
    # make it red and tell them it is an error
    if ($errors != '' ) {
    $errors="<span style=\"background:#ff0000;\">ERROR $errors</span>";
    }
    return $errors;
}

   #
   # set the default values for this program
   #
   $total_errors=0;
   $size=80;
   $rows=10;
   #
   # the size of attachment names
   # used like
   #           <img src="attachment name">
   #
   $anamesize=10;
   #
   # grab the data the user typed into the HTML form
   #

   #
   # use this to figure out the first time we are called
   # so we can initialize stuff
   #
   $hidden_post_variable=$_POST['hidden_post_variable'];









   $from=$_POST['from'];
   $to=$_POST['to'];
   $cc=$_POST['cc'];
   $bcc=$_POST['bcc'];
   $rto=$_POST['rto'];
   $text=$_POST['text'];
   $cr_before=$_POST['cr_before'];
   $cr_after=$_POST['cr_after'];
   $subject=$_POST['subject'];
   $how_to_attach=$_POST['how_to_attach'];
   $send_as_html=$_POST['send_as_html'];
   $dump_header_in_debug_window=$_POST['dump_header_in_debug_window'];
   $dont_use_imap=$_POST['dont_use_imap'];
   $put_debug_info_in_email=$_POST['put_debug_info_in_email'];

   $rulers_selected=array();
   $rulers_selected=$_POST['rulers_to_email'];
   #echo "rulers to email=$rulers_selected<br>";
   $list_of_federal_email_addresses="";
   $list_of_state_email_addresses="";
   #
   # build two lists of names they selected from
   # the menu where they can selecte individual names
   # one list is for the state names 
   # and the 2nd list is for the federal names
   # we will use these lists to get the email addresses
   # to send the emails to
   #
   $hits_state=0;
   $hits_federal=0;
   if (is_array($rulers_selected)) {
      foreach($rulers_selected as $x) {
         #echo "ruler=$x<br>";
         if (substr($x,0,1) == 'F') {
            #echo "fed<br>";
            #echo "fedlist $list_of_federal_email_addresses<br>";
            if (   $list_of_federal_email_addresses == '' ) {
               $list_of_federal_email_addresses=" ( i=".substr($x,1);
            }
            else {
               $list_of_federal_email_addresses.=" or i=".substr($x,1);
            }
            $hits_federal++;
         }
         else {
            #echo "state<br>";
            #echo "statelist $list_of_state_email_addresses<br>";
            if (   $list_of_state_email_addresses == '' ) {
               $list_of_state_email_addresses=" ( i=".$x;
            }
            else {
               $list_of_state_email_addresses.=" or i=".$x;
            }
            $hits_state++;
         }
      }
   }
   if ($hits_federal > 0 ) {
      $list_of_federal_email_addresses.=" ) ";
   }
   if ($hits_state > 0 ) {
      $list_of_state_email_addresses.=" ) ";
   }






   #
   # now get the list of federal offices they selected
   #
   if (is_array($federal_all)) {
      foreach($federal_all as $x) {
         if (   $list_of_federal_email_addresses == '' ) {
            $list_of_federal_email_addresses=" name_entity='".$x."'";
         }
         else {
            $list_of_federal_email_addresses.=" or name_entity='".$x."'";
         }
      }
   }



   #
   # now get the list of federal offices they selected
   # which are only for that state
   # such as federal senate members from arizona
   #         federal house members from arizona
   #
   $hits=0;
   $and_entity=' ( entity_type=\'Federal\' and ( ';
   if (is_array($federal_entities)) {
      foreach($federal_entities as $x) {
         if ($list_of_state_email_addresses == '' ) {
            $list_of_state_email_addresses="$and_entity  name_entity='".$x."'";
         }
         else {
            if ($hits == 0 ) {
               $list_of_state_email_addresses.=" or ".$and_entity." name_entity='".$x."'";
            }
            else {
               $list_of_state_email_addresses.=" or name_entity='".$x."'";
            }
         }
         $hits++;
      }
   }
   #
   # if we got hits add end ending " ) " 
   # to close out the list
   #
   if ($hits > 0 ) {
      $list_of_state_email_addresses.=" ) ) ";
   }



   echo "write ONE subroutine and all it for the 4 following things<p>";

   #
   # now get the list of STATE offices they selected for the STATE level
   #
   $hits=0;
   $and_entity=' ( entity_type=\'State\' and ( ';
   if (is_array($state_entities)) {
      foreach($state_entities as $x) {
         if ($list_of_state_email_addresses == '' ) {
            $list_of_state_email_addresses="$and_entity  name_entity='".$x."'";
         }
         else {
            if ($hits == 0 ) {
               $list_of_state_email_addresses.=" or ".$and_entity." name_entity='".$x."'";
            }
            else {
               $list_of_state_email_addresses.=" or name_entity='".$x."'";
            }
         }
         $hits++;
      }
   }
   #
   # if we got hits add end ending " ) " 
   # to close out the list
   #
   if ($hits > 0 ) {
      $list_of_state_email_addresses.=" ) ) ";
   }



   #
   # now get the list of STATE offices they selected for the COUNTY level
   #
   $hits=0;
   $and_entity=' ( entity_type=\'County\' and ( ';
   if (is_array($county_entities)) {
      foreach($county_entities as $x) {
         if ($list_of_state_email_addresses == '' ) {
            $list_of_state_email_addresses="$and_entity  name_entity='".$x."'";
         }
         else {
            if ($hits == 0 ) {
               $list_of_state_email_addresses.=" or ".$and_entity." name_entity='".$x."'";
            }
            else {
               $list_of_state_email_addresses.=" or name_entity='".$x."'";
            }
         }
         $hits++;
      }
   }
   #
   # if we got hits add end ending " ) " 
   # to close out the list
   #
   if ($hits > 0 ) {
      $list_of_state_email_addresses.=" ) ) ";
   }



   #
   # now get the list of STATE offices they selected for the CITY level
   #
   $hits=0;
   $and_entity=' ( entity_type=\'City\' and ( ';
   if (is_array($city_entities)) {
      foreach($city_entities as $x) {
         if ($list_of_state_email_addresses == '' ) {
            $list_of_state_email_addresses="$and_entity  name_entity='".$x."'";
         }
         else {
            if ($hits == 0 ) {
               $list_of_state_email_addresses.=" or ".$and_entity." name_entity='".$x."'";
            }
            else {
               $list_of_state_email_addresses.=" or name_entity='".$x."'";
            }
         }
         $hits++;
      }
   }
   #
   # if we got hits add end ending " ) " 
   # to close out the list
   #
   if ($hits > 0 ) {
      $list_of_state_email_addresses.=" ) ) ";
   }


   #
   # now get the list of STATE offices they selected for the OTHER level
   #
   $hits=0;
   $and_entity=' ( entity_type=\'Other\' and ( ';
   if (is_array($other_entities)) {
      foreach($other_entities as $x) {
         if ($list_of_state_email_addresses == '' ) {
            $list_of_state_email_addresses="$and_entity  name_entity='".$x."'";
         }
         else {
            if ($hits == 0 ) {
               $list_of_state_email_addresses.=" or ".$and_entity." name_entity='".$x."'";
            }
            else {
               $list_of_state_email_addresses.=" or name_entity='".$x."'";
            }
         }
         $hits++;
      }
   }
   #
   # if we got hits add end ending " ) " 
   # to close out the list
   #
   if ($hits > 0 ) {
      $list_of_state_email_addresses.=" ) ) ";
   }
   #
   # if we have any requests to email at the federal level
   # add on the country code so we can fetch the email addresses
   #
   if ($list_of_federal_email_addresses != '' ) {
      $list_of_federal_email_addresses=" ( $list_of_federal_email_addresses ) and n=$country_code";
   }
   #
   # if we have any requests to email at the state, county, city  levels
   # add on the state code so we can fetch the email addresses
   #
   if ($list_of_state_email_addresses != '' ) {
      $list_of_state_email_addresses="( $list_of_state_email_addresses ) and ns=$state_code";
   }

   #
   # these two will be used to select
   #     1) the names of government nannies we emailed
   #        so we can tell the user
   #     2) the email address of the government nannies
   #        so we can send the email
   #echo "fedlist $list_of_federal_email_addresses<br>";
   #echo "statelist $list_of_state_email_addresses<br>";







   $dump_flength=$_POST['dump_flength'];
   #echo "\$dump_flength='$dump_flength'<br>";



   #
   # if first time set the date to current time
   #
   if ($hidden_post_variable == '' ) {
      #
      # get unix time ie: base January 1 1970 00:00:00 GMT
      #
      $ztime=time();
      #
      # convert to Phoenix time
      #
      $ztime-=(60*60*9);
      #
      # 1st time use date and time in Phoenix Arizona
      # the -9000 i think it says we are 9 hours
      # before London time.
      #
      $zdate=date("D, d M Y H:i:s -0900", $ztime);
      $zdate.=" (MST)";
      #
      # also set the flag to dump the 
      # debug info into the body of the email
      #
      $put_debug_info_in_email='y';
   }
   else {
      #
      # 2nd time use date they entered on form
      #
      $zdate=$_POST['zdate'];
   }


   #
   # clean up the data returned from the form
   # ', ", and \ 
   # are returned as 
   # \', \" and \\
   #
   $text=clean_php_form_data($text);
   $from=clean_php_form_data($from);
   $to=clean_php_form_data($to);
   $cc=clean_php_form_data($cc);
   $bcc=clean_php_form_data($bcc);
   $rto=clean_php_form_data($rto);
   $subject=clean_php_form_data($subject);
   #
   # verify all the FROM: email addresses are valid
   #
   $from=clean_up_to_lines($from);
   $from_errors=get_address_errors($from);
   $total_errors=sum_total_errors($from_errors, $total_errors);
   #
   # verify all the TO: email addresses are valie
   #
   $to=clean_up_to_lines($to);
   $to_errors=get_address_errors($to);
   $total_errors=sum_total_errors($to_errors, $total_errors);
   #
   # a to field is required,
   # if other data was entered
   #
   if ( $from != '' || $cc != '' || $bcc != '' || $text != '') {
      #
      # a TO: address is NOT required.
      # we will use the FROM: field for the TO: field
      # all the government nannies they entered will
      # be placed in the BCC:
      # thus a TO: address is being used like a CC: address
      #
      #if ($to == '' ) {
      #   $total_errors++;
      #   $to_errors.=" a TO address is required";
      #}
      $subject_errors="";
      if ($subject == '' ) {
         $total_errors++;
         $subject_errors="<span style=\"background:#ff0000;\">A subject is required</span>";
      }
      $text_errors="";
      #
      # they must enter something in the body of the email
      #
      #if ($text == '' ) {
      if (preg_match("/^ *\$/m",$text)) {
         $total_errors++;
         $text_errors="<span style=\"background:#ff0000;\">You must enter something in the body or text of the e-mail</span>";
      }
   }
   else {
      $total_errors=-1;
   }
   #
   # verify all the CC: email addresses are valid
   #
   $cc=clean_up_to_lines($cc);
   $cc_errors=get_address_errors($cc);
   $total_errors=sum_total_errors($cc_errors, $total_errors);
   #
   # verify all the BCC: email addresses are valid
   #
   $bcc=clean_up_to_lines($bcc);
   $bcc_errors=get_address_errors($bcc);
   $total_errors=sum_total_errors($bcc_errors, $total_errors);
   #
   # verify all the Reply To: email addresses are valid
   #
   $rto=clean_up_to_lines($rto);
   $rto_errors=get_address_errors($rto);
   $total_errors=sum_total_errors($rto_errors, $total_errors);
   #
   # if errors dont send the stinking email
   #
   if ($total_errors > 0 ) {
      echo "ERROR(s) E-MAIL NOT SENT!  total errors=$total_errors<br>";
   }

?>
<table style="background-color:#dddddd">
<tr valign="top">
<td>
<!-- form action="send_an_email.php" method="post" -->
<!-- make it a miltipart/form so we can upload files -->
<!-- form action="email_rulers.php"  
      method="post" 
      enctype="multipart/form-data" --> 


<form action="<?php
       #
       # tell it to run the name of this script
       # when they click on the submit button
       # 
       # get the FULL name of this script 
       #
       $this_script=$_SERVER['SCRIPT_FILENAME'];
       # 
       # rip off the leading subdirectories 
       #
       $this_script=preg_replace("/^.*\//","",$this_script);
       # 
       # print the name to use in the submit button 
       #
       echo $this_script;?>" 
      method="post"
      enctype="multipart/form-data">








<input type="submit" name=submit value="Send">



     <input type="checkbox" name="dump_header_in_debug_window"  value="y"
     <?php if ($dump_header_in_debug_window == 'y'  ){echo "checked"; } ?>>
     <a href="#dump_headers">dump headers</a>







<table>
<tr>
   <td align="right">From:</td>
   <td align="left"><input type="text" name="from"  
       <?php echo " size=\"$size\" value=\"$from\""; ?> >
       <?php
            #
            # if they entered a from address
            # and the from address has errors tell them
            #
            if ($from != '' ) { 
               echo "$from_errors";
            }
            else {
               #
               # they must enter a from address
               #
               if ($hidden_post_variable != '') {
                  echo " <span style=\"background:#ff0000;\">";
                  echo "You must enter a from address";
                  echo "</span>";
               }
            } 
       ?>
   </td>
</tr>
<tr>
   <td align="right">To:</td>
   <td align="left"><input type="text" name="to"  
       <?php echo " size=\"$size\" value=\"$to\""; ?> >
       <?php echo "$to_errors"; ?>
   </td>
</tr>
<tr>
   <td align="right">CC:</td>
   <td align="left"><input type="text" name="cc"  
       <?php echo " size=\"$size\" value=\"$cc\""; ?> >
       <?php echo "$cc_errors"; ?>
   </td>
</tr>
<tr>
   <td align="right">BCC:</td>
   <td align="left"><input type="text" name="bcc"  
       <?php echo " size=\"$size\" value=\"$bcc\""; ?> >
       <?php echo "$bcc_errors"; ?>
   </td>
</tr>

<tr>
   <td align="right">Reply To:</td>
   <td align="left"><input type="text" name="rto"  
       <?php echo " size=\"$size\" value=\"$rto\""; ?> >
       <?php echo "$rto_errors"; ?>
   </td>
</tr>



<tr>
   <td align="right">
      <a href="#the_date_info">Date</a> :)
   </td>
   <td align="left"><input type="text" name="zdate"  
       <?php echo " size=\"$size\" value=\"$zdate\""; ?> >
   </td>
</tr>


<tr>
   <td align="right">Subject:</td>
   <td align="left"><input type="text" name="subject"  
       <?php echo " size=\"$size\" value=\"$subject\""; ?> >
       <?php echo "$subject_errors"; ?>
   </td>
</tr>
<tr>
   <td align="right">&nbsp;</td>
   <td align="left">
        Send as TEXT
        <input type="radio" name="send_as_html"  value="text"
       <?php if ($send_as_html == 'text' || $send_as_html == '' ) {echo "checked"; } ?> >,
       <a href="#html_text">HTML</a>
        <input type="radio" name="send_as_html"  value="html"
       <?php if ($send_as_html == 'html' ) { echo "checked";}       ?> >
   </td>
</tr>

<?php
if ($text_errors != '' ) {
?>
<tr>
   <td colspan="2"> 
       <?php echo "$text_errors";?>  
   </td>
</tr>
<?php
}
?>


<tr>
   <td colspan="2">
       <textarea name="text" 
       <?php echo "cols=\"$size\" rows=\"$rows\" "; ?>><?php echo "$text"; ?></textarea>  
   </td>
</tr>
</table>
<p>
<table border="10">
<tr valign="top">
<td>
<h4><?php
   #
   # display the COUNTRY name
   #
   $query = "SELECT country FROM rulers_countries where n=$country_code ";
   $result = mysql_query($query) or die('Query failed: ' . mysql_error());
   #
   # display the selected stuff
   #
   $rows=mysql_num_rows($result);
   if ($rows != 1 ) {
      echo "<p>";
      echo "Error $rows rows returned<br>";
      echo "By this query";
      echo "<blockquote>$query</blockquote>";
      echo "in Function";
      exit; 
   }
   #
   # get all the states for this country
   #
   while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {   
      echo $line['country'];
   }
?></h4>
<?php
   #
   # display all the checkboxes at the FEDERAL level
   #
   # theses are federal rulers that report to everyone
   # in the whole country
   # such as PRESIDENT
   #         Vice-Present
   # who in theory are elected by people in
   # all the states
   #
   $query = "SELECT distinct name_entity 
                    FROM rulers_federal 
                    where n=$country_code 
                    order by  sort,name_entity 
                    ";
   $result = mysql_query($query) or die('Query failed: ' . mysql_error());
   #
   # display the selected stuff
   #
   #$rows=mysql_num_rows($result);
   #if ($rows < 0 ) {
   #   echo "<p>";
   #   echo "Error $rows rows returned<br>";
   #   echo "By this query";
   #   echo "<blockquote>$query</blockquote>";
   #   echo "in Function";
   #   exit; 
   #}
   #
   # get all the states for this country
   #
   while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {   
      echo '<nobr><input type="checkbox" name="federal_all[]"  value="';
      echo $line['name_entity'];
      echo '"';
      #
      # was the box checked last time around
      #
      $box_is_checked=is_box_checked($federal_all, $line['name_entity']);
      echo $box_is_checked;
      echo '>';
      echo $line['name_entity'];
      echo '</nobr><br>';
   }











   # these are federal rulers that come from the
   # persons state
   # ie: Arizona House Members
   #     Arizona Senate Members
   #     and that is probably it.
   # 
   #
   $query = "SELECT distinct entity_type, name_entity 
                    FROM rulers_rulers 
                    where ns=$state_code and entity_type='Federal' 
                    order by  name_entity 
                    ";
   $result = mysql_query($query) or die('Query failed: ' . mysql_error());
   #
   # display the selected stuff
   #
   #$rows=mysql_num_rows($result);
   #if ($rows < 0 ) {
   #   echo "<p>";
   #   echo "Error $rows rows returned<br>";
   #   echo "By this query";
   #   echo "<blockquote>$query</blockquote>";
   #   echo "in Function";
   #   exit; 
   #}
   #
   # get all the states for this country
   #
   while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {   
      echo '<nobr><input type="checkbox" name="federal_entities[]"  value="';
      echo $line['name_entity'];
      echo '"';
      #
      # was the box checked last time around
      #
      $box_is_checked=is_box_checked($federal_entities, $line['name_entity']);
      echo $box_is_checked;
      echo '>';
      echo $line['name_entity'];
      echo '</nobr><br>';
   }
?>
</td>
<td>
<h4><?php
   #
   # display the state name
   #
   $query = "SELECT state FROM rulers_states where ns=$state_code ";
   $result = mysql_query($query) or die('Query failed: ' . mysql_error());
   #
   # display the selected stuff
   #
   $rows=mysql_num_rows($result);
   if ($rows != 1 ) {
      echo "<p>";
      echo "Error $rows rows returned<br>";
      echo "By this query";
      echo "<blockquote>$query</blockquote>";
      echo "in Function";
      exit; 
   }
   #
   # get all the states for this country
   #
   while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {   
      echo $line['state'];
   }
?></h4>
<?php
   #
   # display all the checkboxes at the STATE level
   #
   #
   # allow them to select ANY ruler or
   # all rulers from this state for
   # federal, state, county, city and other
   # offices
   #
   $query = "SELECT distinct entity_type, name_entity 
                    FROM rulers_rulers 
                    where ns=$state_code and entity_type='State' 
                    order by  name_entity 
                    ";
   $result = mysql_query($query) or die('Query failed: ' . mysql_error());
   #
   # display the selected stuff
   #
   #$rows=mysql_num_rows($result);
   #if ($rows < 1 ) {
   #   echo "<p>";
   #   echo "Error $rows rows returned<br>";
   #   echo "By this query";
   #   echo "<blockquote>$query</blockquote>";
   #   echo "in Function";
   #   exit; 
   #}
   #
   # get all the states for this country
   #
   while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {   
      echo '<nobr><input type="checkbox" name="state_entities[]"  value="';
      echo $line['name_entity'];
      echo '"';
      #
      # was the box checked last time around
      #
      $box_is_checked=is_box_checked($state_entities, $line['name_entity']);
      echo $box_is_checked;
      echo '>';
      echo $line['name_entity'];
      echo '</nobr><br>';
   }
?>
</td>
<td>
<h4>Counties</h4>






<?php
   #
   # display all the checkboxes at the COUNTY level
   #
   $query = "SELECT distinct entity_type, name_entity 
                    FROM rulers_rulers 
                    where ns=$state_code and entity_type='County' 
                    order by  name_entity 
                    ";
   $result = mysql_query($query) or die('Query failed: ' . mysql_error());
   #
   # display the selected stuff
   #
   #$rows=mysql_num_rows($result);
   #if ($rows < 1 ) {
   #   echo "<p>";
   #   echo "Error $rows rows returned<br>";
   #   echo "By this query";
   #   echo "<blockquote>$query</blockquote>";
   #   echo "in Function";
   #   exit; 
   #}
   #
   # get all the states for this country
   #
   while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {   
      echo '<nobr><input type="checkbox" name="county_entities[]"  value="';
      echo $line['name_entity'];
      echo '"';
      #
      # was the box checked last time around
      #
      $box_is_checked=is_box_checked($county_entities, $line['name_entity']);
      echo $box_is_checked;
      echo '>';
      echo $line['name_entity'];
      echo '</nobr><br>';
   }
?>
</td>
<td>
<h4>Cities</h4>





<?php
   #
   # display all the checkboxes at the CITY level
   # note government schools like the
   # government grade schools or high schools
   # will be under OTHER because school districts
   # often cross city lines.
   # universitys and colleges will either
   # at the State level like Arizona State University
   # or the County level like Maricopa County Community Colleges
   #
   $query = "SELECT distinct entity_type, name_entity 
                    FROM rulers_rulers 
                    where ns=$state_code and entity_type='City' 
                    order by  name_entity 
                    ";
   $result = mysql_query($query) or die('Query failed: ' . mysql_error());
   #
   # display the selected stuff
   #
   #$rows=mysql_num_rows($result);
   #if ($rows < 1 ) {
   #   echo "<p>";
   #   echo "Error $rows rows returned<br>";
   #   echo "By this query";
   #   echo "<blockquote>$query</blockquote>";
   #   echo "in Function";
   #   exit; 
   #}
   #
   # get all the states for this country
   #
   while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {   
      echo '<nobr><input type="checkbox" name="city_entities[]"  value="';
      echo $line['name_entity'];
      echo '"';
      #
      # was the box checked last time around
      #
      $box_is_checked=is_box_checked($city_entities, $line['name_entity']);
      echo $box_is_checked;
      echo '>';
      echo $line['name_entity'];
      echo '</nobr><br>';
   }
?>
</td>



<td>
<h4>Other</h4>
<?php
   #
   # display all the checkboxes at the OTHER level
   # these are typical school districts like
   # scottsdale school district or
   # property districts like some people
   # want to build a road from pine lake
   # to crater resort across the gila
   # indian reservation
   #
   $query = "SELECT distinct entity_type, name_entity 
                    FROM rulers_rulers 
                    where ns=$state_code and entity_type='Other' 
                    order by  name_entity 
                    ";
   $result = mysql_query($query) or die('Query failed: ' . mysql_error());
   #
   # display the selected stuff
   #
   #$rows=mysql_num_rows($result);
   #if ($rows < 1 ) {
   #   echo "<p>";
   #   echo "Error $rows rows returned<br>";
   #   echo "By this query";
   #   echo "<blockquote>$query</blockquote>";
   #   echo "in Function";
   #   exit; 
   #}
   #
   # get all the states for this country
   #
   while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {   
      echo '<nobr><input type="checkbox" name="other_entities[]"  value="';
      echo $line['name_entity'];
      echo '"';
      #
      # was the box checked last time around
      #
      $box_is_checked=is_box_checked($other_entities, $line['name_entity']);
      echo $box_is_checked;
      echo '>';
      echo $line['name_entity'];
      echo '</nobr><br>';
   }
?>
</td>


<td>
<?php
   echo '<select MULTIPLE name="rulers_to_email[]"  size="25">';
   #
   # select the federal people to email
   # that serve the whole country
   # such as President, Vice-President
   #
   $query = "SELECT name_entity, name_ruler, i, district, email 
                    FROM rulers_federal 
                    where n=$country_code 
                    order by  sort, name_entity, name_ruler 
                    ";
   $result = mysql_query($query) or die('Query failed: ' . mysql_error());


   $last_office="";
   $last_entity_type="";
   $last_title="";
   while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {   
      #
      # new office type
      #
      #$this_title=$line['entity_type']." ".$line['name_entity'];
      $this_title=$line['name_entity'];
      #if ($last_office != $line['name_entity'] ) {
      if ($this_title != $last_title ) {
         #
         # tell them the new office type
         #
         echo '<optgroup label="';
         echo $this_title;
         echo '">';
         echo "\n";
         $last_office=$line['name_entity'];
         #$last_title=$line['entity_type']." ".$line['name_entity'];
         $last_title=$line['name_entity'];
      }
      #
      # list each and every government ruller
      #
      #
      # this is how we will get their email address
      #
      echo '<option ';
      #$ruler_is_selected=is_item_selected($rulers_selected, $line['i']);
      $ruler_is_selected=is_item_selected($rulers_selected, "F".$line['i']);
      echo $ruler_is_selected;
      echo ' value="F';
      echo $line['i'];
      echo '">';
      #
      # this is the data we show the user
      #
      echo $line['name_ruler'];
      if ( $line['district'] != '' ) {
         echo " District ";
         echo $line['district'];
      }
      echo "</option>";
      echo "\n";
   }
   #echo '</select>';
   #echo "\n";












   #
   # allow them to select ANY ruler or
   # all rulers from this state for
   # federal, state, county, city and other
   # offices
   #
   $query = "SELECT i, entity_type, name_entity, district, name_ruler, email 
                    FROM rulers_rulers 
                    where ns=$state_code
                    order by entity_type, name_entity, district, name_ruler, email 
                    ";
   $result = mysql_query($query) or die('Query failed: ' . mysql_error());
   #
   # display the selected stuff
   #
   # aqui?
   #$rows=mysql_num_rows($result);
   #if ($rows < 1 ) {
   #   echo "<p>";
   #   echo "Error $rows rows returned<br>";
   #   echo "By this query";
   #   echo "<blockquote>$query</blockquote>";
   #   echo "in Function";
   #   exit; 
   #}
   #
   # get all the states for this country
   #
   #echo '<select MULTIPLE name="rulers_to_email[]">';
   #echo '<select MULTIPLE name="rulers_to_email[]"  size="25">';
   echo "\n";
   $last_office="";
   $last_entity_type="";
   $last_title="";
   while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {   
      #echo '<input type="radio" name="state_code"  value="';
      #echo $line['ns'];
      #echo '">';
      #echo $line['state'];
      #echo "<br>";
      #
      # new office type
      #
      $this_title=$line['entity_type']." ".$line['name_entity'];
      #if ($last_office != $line['name_entity'] ) {
      if ($this_title != $last_title ) {
         #
         # tell them the new office type
         #
         #echo "<optgroup label=\"$line['name_entity']\">";
         echo '<optgroup label="';
         echo $this_title;
         #echo $line['name_entity'];
         echo '">';
         echo "\n";
         $last_office=$line['name_entity'];
         $last_title=$line['entity_type']." ".$line['name_entity'];
      }
      #
      # list each and every government ruller
      #
      #
      # this is how we will get their email address
      #
      echo '<option ';
      $ruler_is_selected=is_item_selected($rulers_selected, $line['i']);
      echo $ruler_is_selected;
      echo ' value="';
      echo $line['i'];
      echo '">';
      #
      # this is the data we show the user
      #
      echo $line['name_ruler'];
      echo " District ";
      echo $line['district'];
      echo "</option>";
      echo "\n";
   }
   echo '</select>';
   echo "\n";
?>
</td>
</tr>
</table>

<p>
<input type="hidden" name="hidden_post_variable" value="hidden post data">
<?php
   #
   # make the country_code a hidden input so
   # we get it on the next pass
   # same for the state_code
   #
   echo '<input type="hidden" name="country_code" value="';
   echo $country_code;
   echo '">';
   echo "\n"; # makes debugging easy
   echo '<input type="hidden" name="state_code" value="';
   echo $state_code;
   echo '">';
   echo "\n";  # makes debugging easy
?>
<input type="reset" name=reset value="RESET">
</form>
</td>
<td style="background-color:#ffff00">
<h2>Debug Window</h2>
<?php
  #
  # dont send any email
  # we have errors
  #
  if ($total_errors != 0 ) {
      
  }
  else {
     #
     # send mail with DEFAULT from:
     # which at greys site is
     #   anonymous@ hosting2.fastq.com
     #
     # this is the default on my server
     # which doesnt even send the mail
     #   me@localhost.com
     #
     # modify the DEFAULT from to this $from
     # and send the email again
     #
     # again this works so stop sending the
     # email each time i test new stuff
     #
     #
     # now build a header record to use as the from:
     # and send the email with it
     #
     #
     # save $text and later restore it
     #
     $oldtext=$text;
     $status_messages="";
     if ($send_as_html == 'html' ) {
       $status_messages.="Sending as HTML\n";
       $status_messages=preg_replace("/\n/","<br>\n",$status_messages);
     }
     else {
       $status_messages.="NOT sending as HTML\n";
     }


     #
     # if this variable is set to a y then
     # put the debug information into the
     # body of the email.
     # this way I can turn off the debugging
     # and use it to send homeland security 
     # messages to cartoonists like benson :)
     #
     if ($put_debug_info_in_email == 'y') {
        $text=$status_messages.$text;
     }
     $header="";
     #
     # build the from: header
     #
     if ($from != "" ) {
        $header.="From: $from\r\n";  
     }
     #
     # build the CC: header
     #
     if ($cc != "" ) {
        $header.="CC: $cc\r\n";
     }
     #
     # get the emails to send to and send them as BCC's
     #
     $rulers_to_bcc="";
     if ($bcc != '' ) {
        $rulers_to_bcc=$bcc;
     }
     $rulers_names="";
     $rulers_we_have_valid_email_address=0;
     $rulers_they_want_to_email=0;
     #
     # get the FEDERAL rulers like President
     #
     if ($list_of_federal_email_addresses != '' ) {
        $query = "SELECT distinct email, name_ruler 
                         FROM rulers_federal 
                         where $list_of_federal_email_addresses 
                         order by name_ruler 
                         ";
        $result = mysql_query($query) or die('Query failed: ' . mysql_error());
        while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { 
           #
           # add the rulers email address to the list if we have one
           # if its blank don't add it
           # if its none don't add it
           #
           if (!(preg_match("/^ *$/",$line['email']) || preg_match("/^ *none *$/i",$line['email'])) ) {
              if ($rulers_to_bcc == '' ) {  
                 $rulers_to_bcc=$line['email'];
                 $rulers_we_have_valid_email_address++;
              }
              else {
                 $rulers_to_bcc.=",".$line['email'];
                 $rulers_we_have_valid_email_address++;
              }
           }
           #
           # add the rulers name to the list 
           # so we can tell the user the names 
           # of all the government nannies we sent
           # emails to
           #
           if ($rulers_names == '' ) {
              $rulers_names=$line['name_ruler'];
              $rulers_they_want_to_email++;
           }
           else {
              $rulers_names.="<br>".$line['name_ruler'];
              $rulers_they_want_to_email++;
           }
           #
           # if we dont have the rulers email address on file
           # or if it is listed as none 
           # tell the user that this government nanny
           # refused to give us their email address
           #
           if (preg_match("/^ *$/",$line['email']) || preg_match("/^ *none *$/i",$line['email']) ) {
              $rulers_names.=" - Refused to give us his email address";
           }
        }
     }
     #
     # get the STATE, county, city and other state rulers
     # this includes STATE rulers who are
     # in federal offices like u.s. senators for arizona
     # or U.S. congressmen for arizona
     #
     if ($list_of_state_email_addresses != '' ) {
        $query = "SELECT distinct email, name_ruler 
                         FROM rulers_rulers 
                         where $list_of_state_email_addresses 
                         order by name_ruler 
                         ";
        #echo "<pre>$query</pre>";
        $result = mysql_query($query) or die('Query failed: ' . mysql_error());
        while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { 
           #
           # add the rulers email address to the list if we have one
           # if its blank don't add it
           # if its none don't add it
           #
           if (!(preg_match("/^ *$/",$line['email']) || preg_match("/^ *none *$/i",$line['email'])) ) {
              if ($rulers_to_bcc == '' ) {  
                 $rulers_to_bcc=$line['email'];
                 $rulers_we_have_valid_email_address++;
              }
              else {
                 $rulers_to_bcc.=",".$line['email'];
                 $rulers_we_have_valid_email_address++;
              }
           }
           #
           # add the rulers name to the list 
           # so we can tell the user the names 
           # of all the government nannies we sent
           # emails to
           #
           if ($rulers_names == '' ) {
              $rulers_names=$line['name_ruler'];
              $rulers_they_want_to_email++;
           }
           else {
              $rulers_names.="<br>".$line['name_ruler'];
              $rulers_they_want_to_email++;
           }
           #
           # if we dont have the rulers email address on file
           # or if it is listed as none 
           # tell the user that this government nanny
           # refused to give us their email address
           #
           if (preg_match("/^ *$/",$line['email']) || preg_match("/^ *none *$/i",$line['email']) ) {
              $rulers_names.=" - Refused to give us his email address";
           }
        }
     }
     #echo "Rulers to BCC =$rulers_to_bcc<br>";
     #echo "Rulers names =$rulers_names<br>";
     #
     # build the BCC: header
     # in this case we merged their BCC list
     # with our BCC list of government nannies
     #
     #if ($bcc != "" ) {
     if ($rulers_to_bcc != "" ) {
        $header.="BCC: $rulers_to_bcc\r\n";
     }
     #
     # build the Reply To: header
     #
     if ($rto != "" ) {
        #
        # "reply to:" doesnt work
        # try using
        # "reply-to:"
        #
        if (0) {
           $header.="Reply To: $rto\r\n";
        }
        else {
           $header.="Reply-To: $rto\r\n";
        } 
     }
     #
     # build the Date: header
     #
     if ($zdate != "" ) {
        $header.="Date: $zdate\r\n"; 
     }
     if ($how_to_attach == "after" ) {
        #
        # if we are sending it as HTML 
        # build the html header before the FILES
        #
        if ($send_as_html == 'html' ) {
           $header.="Content-type: text/html\r\n";
        }
        #
        # add the file they uploaded as an attachment to the e-mail
        #
        echo "<p>make sure the header has been attached AFTER this<p>";
        #
        # add each file entered to the header information
        # 
     }
     if ($how_to_attach == "before" ) {
        #
        # add the file they uploaded as an attachment to the e-mail
        #
        echo "<p>make sure the header has been attached BEFORE this<p>";



        #
        # add each file entered to the header information
        #



        # if we are sending it as HTML 
        # build the html header after the FILES
        #
        if ($send_as_html == 'html' ) {
           $header.="Content-type: text/html\r\n";
        }
     }
     #
     # dump the headers ?
     #
     if ($dump_header_in_debug_window == 'y') {
        echo "<b>dumping headers</b>";
        echo "<pre>";
        echo $header;
        echo "</pre>";
     }
     #
     # only send the email ONCE and send it here
     # before I was sending it after I built
     # each and every header
     #
     echo "SENDING the E-MAIL now!<br>";
     if ($to == '' ) {
        $to=$from;
     }
     $rc=mail($to,$subject,$text,$header);
     #
     # we have sent the email but
     # print some information in the debug window
     # about how we sent the email
     #
     echo "<table border=1>";
     $x=htmlentities($to);
     echo "<tr><td align=\"right\">To:</td><td>$x &nbsp;</td></tr>";
     $x=htmlentities($cc);
     echo "<tr><td align=\"right\">CC:</td><td>$x &nbsp;</td></tr>";
     $x=htmlentities($bcc);
     echo "<tr><td align=\"right\">BCC:</td><td>$x &nbsp;</td></tr>";
     $x=htmlentities($rto);
     echo "<tr><td align=\"right\">Reply To:</td><td>$x &nbsp;</td></tr>";
     $x=htmlentities($from);
     echo "<tr><td align=\"right\">From:</td><td>$x &nbsp;</td></tr>";




     $x=htmlentities($subject);
     echo "<tr><td align=\"right\">Subject:</td><td>$x &nbsp;</td></tr>";
     $x=$text;
     #
     # if they are sending it as text
     # convert the krud in the message
     # to html stuff so we can view
     # it in netscape
     # ie 
     #     > becomes &gt;
     #     < becomes &lt;
     #     .....
     #
     if ( $send_as_html == 'text' ) {
        $x=htmlentities($text);
        #
        # make the spaces display correctly with &nbsp;
        #
        $x=preg_replace("/ /","&nbsp;",$x);
        #
        # make line breaks display correctly with <br>
        #
        $x=preg_replace("/\n/","<br>",$x);
     }
     echo "<tr><td colspan=2>$x&nbsp;</td></tr>";
     echo "<tr><td align=\"right\">RC</td><td>$rc&nbsp;</td></tr>";

     if ($rc != 1 ) {
        echo "<tr><td colspan=\"2\">Hmmm... Something has changed. The rc used to be set to one</td></tr>";
     }
     echo "</table>";
  }   
?>
</td>
</tr>
</table>
<?php
if ($rulers_we_have_valid_email_address == 0 ) {
   echo "<h2 style=\"background:#ff0000;\">Error! No Emails were sent!!!!</h2>";
   if ($rulers_they_want_to_email == 0 ) {
      echo "You did not select any government rulers";
   }
   else {
      echo "You did selected $rulers_they_want_to_email government rulers<br>";
      echo "and they all refused to give us their email address<br>";
      echo $rulers_names;
   }
}
if ($rulers_we_have_valid_email_address > 0 ) {

   #
   # some of the emails could not be sent because
   # we dont have the email address
   #
   if ($rulers_we_have_valid_email_address != $rulers_they_want_to_email) {
      $emails_not_sent=$rulers_they_want_to_email-$rulers_we_have_valid_email_address;
      echo "<h2 style=\"background:#ff0000;\">Error $emails_not_sent Emails were not sent!!!!</h2>";
      echo "Some government rulers have refused to give us their email address<br>";
   }




   echo "<h2>$rulers_we_have_valid_email_address Emails sent to</h2>";
   echo $rulers_names;
}
?>

extentions.php

TOC

<?php
if ($set_cookie == "") {
   setcookie("PHP.ext","hot SPICY PHP extentions",time()+333333);
   setcookie("PHP.Ext.love","everybody loves PHP extentions",time()+333333);
   setcookie("PHP.EXT.not.enough","and nobody gets enough PHP extentions",time()+333333);
}
$set_cookie="si";
#
# this session id stuff is for people who refuse to use cookies
# it keeps track of them on the server side instead of with
# cookies on their PC.
# the session lasts until they close their browser window
#
$mysessionid=session_start();
$_SESSION[dump.extens]="PHP extentions";
if ($_SESSION[phpextsfrogs] == '' ) {
   $_SESSION[phpextsfrogs]=1;
}
else {
   $_SESSION[phpextsfrogs]++;
}
?>
<html>
<p>
Dump some loaded PHP extentions!!!!
<?php
echo "<p>";
$stinking_extensions=0;
$ext=get_loaded_extensions();
foreach($ext as $foo) {
   $stinking_extensions++;
   echo "<span style=\"background-color:#00ff00;\">&nbsp;&nbsp;&nbsp;$foo</span><br>";
   $functions=get_extension_funcs($foo);
   foreach($functions as $foofoo) {
      echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background-color:#ffff00;\">$foofoo()</span><br>";
   }

}
if ($stinking_extensions == 0 ) {
   echo "No extensions loaded<br>";
}
echo "<p>";
?>








</html>

../dns_stuff/feed_them_cookies.php

TOC

<?php
#
# cookies are like kind of like gifs
# you can print tuff untill after you set the cookie
#
#echo "<h2>Mmmm Cookies</h2>";
$c="";
$cookienum=0;
$c.=foo('chocolate' , 'mint');
$c.=foo('chili' , 'taco');
$c.=foo('icecream' , 'green');
$c.=foo('turkey' , 'roasted');
$c.=foo('onions' , 'white');
$c.=foo('beef' , 'roast');
echo "<table border=1>";
echo "<tr><td>cookie<br>name</td><td>value</td><td>rc</td></tr>";
echo "$c";
echo "</table>";
?> 
<script language="php">
function foo($name, $value) {
 $c="<tr><td>$name</td><td>$value</td>";
 $rc=setcookie($name , $value);
 $c.="<td>$rc</td></tr>";
 return $c;
}
</script>

../curl_ftp_stuff/ftp_list_my_site.php

TOC

<h1>using CURL to do an FTP to my site</h1>
<h4>curl_setopt($curl,CURLOPT_FTPLISTONLY,1);</h4>
Short listing
<p>

<?php
#
# include the functions to remove sensitive data
#
include "remove_sensitive_data.php";
#
# get our data
#
include "stuff/passwords.php";
#
# initialize curl
#
$curl=curl_init();
#
# do a ftp to $site and list the files
#
curl_setopt($curl,CURLOPT_URL,"ftp://$site");
#
# i think this means to list all the files
# 1 - says give SHORT listing
#
curl_setopt($curl,CURLOPT_FTPLISTONLY,1);
#
# this is the syntax of the ftp command
#
#    ftp://user:password@host:port/path
#
# ftp to my site and get a listing
#
curl_setopt($curl,CURLOPT_USERPWD,$userid.":".$password);
#
# i think this says go get the data
#
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
#
# i think this says run all the stuff we just defined
# and place the data received in $result
#
$result=curl_exec($curl);
#
# close curl
#
curl_close($curl);
#
# print the data we got with the ftp to ftp.gnu.org
#
echo "<pre>";
print $result;
echo "</pre>";
#
# the first time i ran this my listing looked like this
#
#     cgi-bin
#     _private
#     index.html
?>
<h4>curl_setopt($curl,CURLOPT_FTPLISTONLY,0);</h4>
Long listing
<p>
<?php
#
# do it a 2nd time to get a long listing of the files
#






#
# initialize curl
#
$curl=curl_init();
#
# do a ftp to $site and list the files
#
curl_setopt($curl,CURLOPT_URL,"ftp://$site");
#
# i think this means to list all the files
# 0 - says give LONG listing - ls -l 
#
curl_setopt($curl,CURLOPT_FTPLISTONLY,0);
#
# this is the syntax of the ftp command
#
#    ftp://user:password@host:port/path
#
# ftp to my site and get a listing
#
curl_setopt($curl,CURLOPT_USERPWD,$userid.":".$password);
#
# i think this says go get the data
#
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
#
# i think this says run all the stuff we just defined
# and place the data received in $result
#
$result=curl_exec($curl);
#
# close curl
#
curl_close($curl);
#
# remove my userid and sitename for security
#
$result=remove_sensitive_data($result, $my_site, "my-site");
$result=remove_sensitive_data($result, $userid, "my-site");
#
# print the data we got with the ftp to ftp.gnu.org
#
echo "<pre>";
print $result;
echo "</pre>";
#
# the first time around the long listing shows
#
#     drwxr-xr-x   1 friends-devils my-site          0 Jan 25 11:26 cgi-bin
#     drwxr-xr-x   1 friends-devils my-site          0 Jan 25 11:26 _private
#     -rw-r--r--   1 friends-devils my-site        227 Jan 25 11:29 index.html
#     
?>

../curl_ftp_stuff/ftp_to_gnu.php

TOC

<?php
#
# initialize curl
#
$curl=curl_init();
#
# do a ftp to
#    ftp.gnu.org
#
curl_setopt($curl,CURLOPT_URL,"ftp://ftp.gnu.org");
#
# i think this means to list all the files
#
curl_setopt($curl,CURLOPT_FTPLISTONLY,1);
#
# ftp in with the userid/password of
#   anonymous:your@email.com
#
curl_setopt($curl,CURLOPT_USERPWD,"anonymous:your@email.com");
#
# i think this says go get the data
#
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
#
# use this command to debut CURL stuff
# it makes curl become VERBOSE and 
# tell you about everything it does
#  1 to turn on VERBOSE
#  0 to turn off VERBOSE
#
curl_setopt($curl,CURLOPT_VERBOSE,1);
#
# i think this says run all the stuff we just defined
# and place the data received in $result
#
$result=curl_exec($curl);
#
# close curl
#
curl_close($curl);
#
# print the data we got with the ftp to ftp.gnu.org
#
echo "<pre>";
print $result;
echo "</pre>";
#
# the first time i ran this the results looked like this
#
#      CRYPTO.README
#      MISSING-FILES
#      MISSING-FILES.README
#      README
#      before-2003-08-01.md5sums.asc
#      find.txt.gz
#      gnu
#      gnu+linux-distros
#      lpf.README
#      ls-lrRt.txt.gz
#      mirrors
#      non-gnu
#      old-gnu
#      pub
#      savannah
#      third-party
#      welcome.msg
?>

../curl_ftp_stuff/ftp_to_gnu.php

TOC

<?php
#
# initialize curl
#
$curl=curl_init();
#
# do a ftp to
#    ftp.gnu.org
#
curl_setopt($curl,CURLOPT_URL,"ftp://ftp.gnu.org");
#
# i think this means to list all the files
#
curl_setopt($curl,CURLOPT_FTPLISTONLY,1);
#
# ftp in with the userid/password of
#   anonymous:your@email.com
#
curl_setopt($curl,CURLOPT_USERPWD,"anonymous:your@email.com");
#
# i think this says go get the data
#
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
#
# use this command to debut CURL stuff
# it makes curl become VERBOSE and 
# tell you about everything it does
#  1 to turn on VERBOSE
#  0 to turn off VERBOSE
#
curl_setopt($curl,CURLOPT_VERBOSE,1);
#
# i think this says run all the stuff we just defined
# and place the data received in $result
#
$result=curl_exec($curl);
#
# close curl
#
curl_close($curl);
#
# print the data we got with the ftp to ftp.gnu.org
#
echo "<pre>";
print $result;
echo "</pre>";
#
# the first time i ran this the results looked like this
#
#      CRYPTO.README
#      MISSING-FILES
#      MISSING-FILES.README
#      README
#      before-2003-08-01.md5sums.asc
#      find.txt.gz
#      gnu
#      gnu+linux-distros
#      lpf.README
#      ls-lrRt.txt.gz
#      mirrors
#      non-gnu
#      old-gnu
#      pub
#      savannah
#      third-party
#      welcome.msg
?>

../curl_ftp_stuff/ftp_to_gnu_wrong_password.php

TOC

This code will do NOTHING!!!
<p>
That is because we logged in with the wrong password<br>
as opposed to using <a href="ftp_to_gnu.php">ftp_to_gnu.php</a><br>
which logs in with the correct password of anonymous
<p>
We used
<blockquote>
wrong_password
</blockquote>
instead of the correct password which is
<blockquote>
anonymous
</blockquote>
<?php
#
# here we log in with the WRONG password
# as opposed to 
#       ftp_to_gnu.php
# which logs in with the correct password
# of course when we log in with the WRONG password
# it will do NOTHING
#
#
# initialize curl
#
$curl=curl_init();
#
# do a ftp to
#    ftp.gnu.org
#
curl_setopt($curl,CURLOPT_URL,"ftp://ftp.gnu.org");
#
# i think this means to list all the files
#
curl_setopt($curl,CURLOPT_FTPLISTONLY,1);
#
# ftp in with the userid/password of
#   anonymous:your@email.com
#
curl_setopt($curl,CURLOPT_USERPWD,"wrong_password:your@email.com");
#
# i think this says go get the data
#
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
#
# i think this says run all the stuff we just defined
# and place the data received in $result
#
$result=curl_exec($curl);
#
# close curl
#
curl_close($curl);
#
# print the data we got with the ftp to ftp.gnu.org
#
# of course since we used the WRONG password 
# it will get nothing back
# and NOTHING will be printed
echo "<pre>";
print $result;
echo "</pre>";
?>

get_header_content_type.php

TOC

<?php
function get_header_content_type ($data) {
   #
   # find the header line that says 
   #    content-type: xxxx/xxxx
   # and return a 3 line array such as
   #          text/html
   #          text
   #          html
   #
   # set the default to we found nothing as sgt shultz would say
   #
   $content_type=array('unknown/unknown','unknown','unknown');
   #
   # for each line in the header data search for
   #         content-type:
   # at the begining of the line
   #
   foreach ($data as $line) {
     #
     # got a match?
     #
     if (preg_match("/^ *content-type:  */i",$line)) {
        #
        # extract the 3 parts we return as stated above
        #
        #    text/html
        #    text
        #    html
        #
        #echo "content=$line<br>";
        $line=preg_replace("/[\r\n]/","",$line);
        #
        # rip out any semicolens too
        # the republic web site returns this
        #    text/html; charset=iso-8859-1
        # and we dont want the stuff after the ;
        #
        $line=preg_replace("/;.*\$/i","",$line);
        $this_content=preg_replace("/^ *content-type:  */i","",$line);

        #echo "new content=$this_content<br>";
        $content_type[0]=$this_content;
        $content_type[1]=preg_replace("/\/.*/i","",$this_content);
        $content_type[2]=preg_replace("/.*\//i","",$this_content);
        #
        # all done! get outta here!
        #
        break;
     } 
   }
   #
   # return a 3 line array to the caller
   # with the content type
   #
   return $content_type;
}
?>

../get_my_ip_address.pl

TOC

#!/usr/bin/perl
require CGI;
use CGI;
$cgi = new CGI;
#
# get the digit to display
#
#$f=$cgi->param('f');
#$d=$cgi->param('d');
#
# print required header information
#
print "Content-type: text/html", "\n\n";
print "<html>\n";
print "<h1>$ENV{REMOTE_ADDR}</h1>\n";
print "<img src=\"ip_address_gif.php\">";
exit;

get_socket_header_data.php

TOC

<?php
function get_socket_header_data ($data) {
   #
   # this function returns an array
   # which contains all the header
   # information the socket gave us
   #
   $header=array();
   $i=0;
   $dataheader=explode("\n", $data);
   foreach($dataheader as $theline) {
      #
      # get all the data up to the 1st blank line
      # ie the line that is only a \r
      #
      if ($theline == "\r") {
         break;
      }
      $header[$i]=$theline;
      $i++;
   }
   return $header;
}
?>

getsocketdataafterheaders.php

TOC

<?php
function get_socket_data_after_headers ($data) {
   #
   # delete the header information from the data
   #
   $gotendheaders=0;
   while($gotendofheaders==0) {
      #
      # the last header is a null line with 
      # have we found it yet?
      #
      if (substr($data,0,4) == "\r\n\r\n" ) {
         #
         # delete last part of the headers
         # which is 4 bytes and we are done!
         #
         $data=substr($data,4);
         $gotendofheaders=1;
      }
      else {
         #
         # delete the 1st byte till we get to end of header
         #
         $data=substr($data,1);
      }  
   }
   return $data;
}
?>

hiworld.php

TOC

<?php
echo "hi world<br>";
?>

hiworld2.php

TOC

<?php
echo "hi world<br>";
?>

../hours.pl

TOC

#!/usr/bin/perl
require CGI;
use CGI;
$cgi = new CGI;
#
# get the digit to display
#


$d1bh1=$cgi->param('d1bh1');
$d1bm1=$cgi->param('d1bm1');

$d1eh1=$cgi->param('d1eh1');
$d1em1=$cgi->param('d1em1');




$d=$cgi->param('d');
print "Content-type: text/html", "\n\n";
print "<html>\n";
print "<body background=\"nevada.gif\">\n";
print "<form action=\"hours.pl\" method=\"post\">";
print "<input type=\"submit\" name=submit value=\"SUBMIT\">";



#
# validate the begining time
#
#
# clean up the hours
#
$d1bh1=clean_hours($d1bh1);
#
# clean up the minutes
#
$d1bm1=clean_minutes($d1bh1,$d1bm1);
#
# validate hours and minutes
#
$d1b1e=check_hour_minute($d1bh1,$d1bm1);



#
# validate the ending time
#
#
# clean up the hours
#
$d1eh1=clean_hours($d1eh1);
#
# clean up the minutes
#
$d1em1=clean_minutes($d1eh1,$d1em1);
#
# validate hours and minutes
#
$d1e1e=check_hour_minute($d1eh1,$d1em1);


#
# caculate the first time
#
($d1th1, $d1tm1)=caculate_time($d1bh1,$d1bm1,$d1eh1,$d1em1);


 
print "<input type=\"text\" name=\"d1bh1\" maxlength=\"2\" size=\"2\" value=\"$d1bh1\">";
print ":";
print "<input type=\"text\" name=\"d1bm1\" maxlength=\"2\" size=\"2\" value=\"$d1bm1\">";
print "$d1b1e";

print " thru ";

print "<input type=\"text\" name=\"d1eh1\" maxlength=\"2\" size=\"2\" value=\"$d1eh1\">";
print ":";
print "<input type=\"text\" name=\"d1em1\" maxlength=\"2\" size=\"2\" value=\"$d1em1\">";
print "$d1e1e";

print "time=$d1th1:$d1tm1";


print "</form>";





exit;


sub caculate_time {
 my $hour1=@_[0];
 my $min1=@_[1];
 my $hour2=@_[2];
 my $min2=@_[3];
 my $errormessage="";
 my @rc=('','');
 my $minutes_worked=0;
 my $hours_worked=0;
 #
 # if any of the times are blank then
 # dont waste our time trying to caculate something
 # just return to the caller
 #
 if ($hour1 eq "" || $min1 eq "" || $hour2 eq "" || $min2 eq "") {
    return @rc;
 }
 #
 # if the begining hour and minute is not valid return and do nothing
 #
 $errormessage=check_hour_minute($hour1,$min1);
 if ( $errormessage ne "" ) {
    return @rc;
 }
 #
 # if the ending hour and minute is not valid return and do nothing
 #
 $errormessage=check_hour_minute($hour2,$min2);
 if ( $errormessage ne "" ) {
    return @rc;
 }
 #print "caculate hours";
 #
 # if the hours are the SAME
 # assume they worked a 12 hour day
 #
 if ($hour1 == $hour2 ) {
   if ($min2 <= $min1 ) {
      $hour2+=12;
   }
 }
 #
 # if they first hour is greater then the 2nd hour
 # add 12 to the 2nd hour
 #
 if ($hour1 > $hour2 ) {
    $hour2+=12;
 }
 #print "caculate hours $hour2:$min2 - $hour1:$min1";
 $minutes_worked=$min2-$min1;
 if ( $minutes_worked < 0 ) {
   $minutes_worked+=60;
   $hour2--;
 }
 if ( $minutes_worked < 10 ) {
    $minutes_worked="0".$minutes_worked;
 }
 $hours_worked=$hour2-$hour1;






 return ($hours_worked,$minutes_worked );
}

sub check_hour_minute {
 my $hour=@_[0];
 my $min=@_[1];
 my $rc="";
 #print "hour=$hour<br>min=$min<br>";
 #
 # if they didnt enter hours or minutes it is OK
 # just return
 #
 if ($hour eq "" && $min eq "" ) {
    #
    # hour and minute are spaces - return
    #
    return $rc;
 }
 if ($hour eq "") {
    #
    # hour not entered
    #
    $rc.=" Hours must be entered";
 }
 else {
    #
    # at this point we know the hour has SOMETHING in it
    #
    if ($hour =~ /[^0-9]/) {
       #
       # if the hour has something other then digits in it
       # then it is an error
       #
       $rc.=" Hour must only contains digits 0-9";
    }
    else {
       #
       # at this point the hour IS a number
       # the question is the hour a number between
       # 0 and 24
       #
       if (! ($hour >=0 && $hour <= 24)) {
          #
          # hour must be a 2 digit number
          #
          $rc.=" Hour must be a number between 0 and 24";
       }
    }
 }
 #
 # now verify the minutes are valid 
 #
 if ($min eq "" ) {
    #
    # if the minutes have not been entered dont validate them
 }
 else {
    if ($min =~ /[^0-9]/) {
       #
       # if the minutes has something other then digits in it
       # then it is an error
       #
       $rc.=" Minutes must only contains digits 0-9";
    }
    else {
       #
       # at this point we know the minutes are a number
       # now we must verify it is a number from 0 to 59
       #
       if (! ($min >=0 && $min <= 59)) {
          #
          # minutes must be between 0 and 59
          #
          $rc.=" Minute must be a number between 0 and 59";
       }
 
    }
 }
 return $rc;
}


sub clean_hours {
 my $hour=@_[0];
 #
 # remove leading spaces
 #
 $hour=~s/^ *//;
 #
 # remove trailing spaces
 #
 $hour=~s/ *$//;
 return $hour;
}





sub clean_minutes {
 my $hour=@_[0];
 my $min=@_[1];
 #
 # remove leading and trailing spaces
 # like we do for the hours
 #
 $min=clean_hours($min);
 #
 # if the minute is one numeric digit then add a leading zero
 #
 if ($min =~ /^[0-9]$/ ) {
    $min="0".$min;
 }
 #
 # if the minutes are null and
 # the hour is 0 to 24 then
 # set minutes to 00
 if ($min eq "" ) {
     #
     # hours must be all numbers
     #
     if ($hour ne "" && $hour =~ /^[0-9]*[0-9]$/ ) {
       #
       # hour must be 0 to 24
       #
       if ($hour >= 0 && $hour <= 24 ) {
          $min="00";
       }
     }
 }
 return $min;
}

../hours.pl

TOC

#!/usr/bin/perl
require CGI;
use CGI;
$cgi = new CGI;
#
# get the digit to display
#


$d1bh1=$cgi->param('d1bh1');
$d1bm1=$cgi->param('d1bm1');

$d1eh1=$cgi->param('d1eh1');
$d1em1=$cgi->param('d1em1');




$d=$cgi->param('d');
print "Content-type: text/html", "\n\n";
print "<html>\n";
print "<body background=\"nevada.gif\">\n";
print "<form action=\"hours.pl\" method=\"post\">";
print "<input type=\"submit\" name=submit value=\"SUBMIT\">";



#
# validate the begining time
#
#
# clean up the hours
#
$d1bh1=clean_hours($d1bh1);
#
# clean up the minutes
#
$d1bm1=clean_minutes($d1bh1,$d1bm1);
#
# validate hours and minutes
#
$d1b1e=check_hour_minute($d1bh1,$d1bm1);



#
# validate the ending time
#
#
# clean up the hours
#
$d1eh1=clean_hours($d1eh1);
#
# clean up the minutes
#
$d1em1=clean_minutes($d1eh1,$d1em1);
#
# validate hours and minutes
#
$d1e1e=check_hour_minute($d1eh1,$d1em1);


#
# caculate the first time
#
($d1th1, $d1tm1)=caculate_time($d1bh1,$d1bm1,$d1eh1,$d1em1);


 
print "<input type=\"text\" name=\"d1bh1\" maxlength=\"2\" size=\"2\" value=\"$d1bh1\">";
print ":";
print "<input type=\"text\" name=\"d1bm1\" maxlength=\"2\" size=\"2\" value=\"$d1bm1\">";
print "$d1b1e";

print " thru ";

print "<input type=\"text\" name=\"d1eh1\" maxlength=\"2\" size=\"2\" value=\"$d1eh1\">";
print ":";
print "<input type=\"text\" name=\"d1em1\" maxlength=\"2\" size=\"2\" value=\"$d1em1\">";
print "$d1e1e";

print "time=$d1th1:$d1tm1";


print "</form>";





exit;


sub caculate_time {
 my $hour1=@_[0];
 my $min1=@_[1];
 my $hour2=@_[2];
 my $min2=@_[3];
 my $errormessage="";
 my @rc=('','');
 my $minutes_worked=0;
 my $hours_worked=0;
 #
 # if any of the times are blank then
 # dont waste our time trying to caculate something
 # just return to the caller
 #
 if ($hour1 eq "" || $min1 eq "" || $hour2 eq "" || $min2 eq "") {
    return @rc;
 }
 #
 # if the begining hour and minute is not valid return and do nothing
 #
 $errormessage=check_hour_minute($hour1,$min1);
 if ( $errormessage ne "" ) {
    return @rc;
 }
 #
 # if the ending hour and minute is not valid return and do nothing
 #
 $errormessage=check_hour_minute($hour2,$min2);
 if ( $errormessage ne "" ) {
    return @rc;
 }
 #print "caculate hours";
 #
 # if the hours are the SAME
 # assume they worked a 12 hour day
 #
 if ($hour1 == $hour2 ) {
   if ($min2 <= $min1 ) {
      $hour2+=12;
   }
 }
 #
 # if they first hour is greater then the 2nd hour
 # add 12 to the 2nd hour
 #
 if ($hour1 > $hour2 ) {
    $hour2+=12;
 }
 #print "caculate hours $hour2:$min2 - $hour1:$min1";
 $minutes_worked=$min2-$min1;
 if ( $minutes_worked < 0 ) {
   $minutes_worked+=60;
   $hour2--;
 }
 if ( $minutes_worked < 10 ) {
    $minutes_worked="0".$minutes_worked;
 }
 $hours_worked=$hour2-$hour1;






 return ($hours_worked,$minutes_worked );
}

sub check_hour_minute {
 my $hour=@_[0];
 my $min=@_[1];
 my $rc="";
 #print "hour=$hour<br>min=$min<br>";
 #
 # if they didnt enter hours or minutes it is OK
 # just return
 #
 if ($hour eq "" && $min eq "" ) {
    #
    # hour and minute are spaces - return
    #
    return $rc;
 }
 if ($hour eq "") {
    #
    # hour not entered
    #
    $rc.=" Hours must be entered";
 }
 else {
    #
    # at this point we know the hour has SOMETHING in it
    #
    if ($hour =~ /[^0-9]/) {
       #
       # if the hour has something other then digits in it
       # then it is an error
       #
       $rc.=" Hour must only contains digits 0-9";
    }
    else {
       #
       # at this point the hour IS a number
       # the question is the hour a number between
       # 0 and 24
       #
       if (! ($hour >=0 && $hour <= 24)) {
          #
          # hour must be a 2 digit number
          #
          $rc.=" Hour must be a number between 0 and 24";
       }
    }
 }
 #
 # now verify the minutes are valid 
 #
 if ($min eq "" ) {
    #
    # if the minutes have not been entered dont validate them
 }
 else {
    if ($min =~ /[^0-9]/) {
       #
       # if the minutes has something other then digits in it
       # then it is an error
       #
       $rc.=" Minutes must only contains digits 0-9";
    }
    else {
       #
       # at this point we know the minutes are a number
       # now we must verify it is a number from 0 to 59
       #
       if (! ($min >=0 && $min <= 59)) {
          #
          # minutes must be between 0 and 59
          #
          $rc.=" Minute must be a number between 0 and 59";
       }
 
    }
 }
 return $rc;
}


sub clean_hours {
 my $hour=@_[0];
 #
 # remove leading spaces
 #
 $hour=~s/^ *//;
 #
 # remove trailing spaces
 #
 $hour=~s/ *$//;
 return $hour;
}





sub clean_minutes {
 my $hour=@_[0];
 my $min=@_[1];
 #
 # remove leading and trailing spaces
 # like we do for the hours
 #
 $min=clean_hours($min);
 #
 # if the minute is one numeric digit then add a leading zero
 #
 if ($min =~ /^[0-9]$/ ) {
    $min="0".$min;
 }
 #
 # if the minutes are null and
 # the hour is 0 to 24 then
 # set minutes to 00
 if ($min eq "" ) {
     #
     # hours must be all numbers
     #
     if ($hour ne "" && $hour =~ /^[0-9]*[0-9]$/ ) {
       #
       # hour must be 0 to 24
       #
       if ($hour >= 0 && $hour <= 24 ) {
          $min="00";
       }
     }
 }
 return $min;
}

html_to_displayable_html.php

TOC

<?php
#
# convert HTML that a browser can display
# to HTML a human can view on the browser
# ie:
#       <html>
#           <h1>frog dog</h1>
#           <a href="foo.html">foo</a>
#       </html>
#
# becomes
#
#       &lt;html&gt;
#       &nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;frog&nbsp;dog&lt;/h1&gt;
#       &nbsp;&nbsp;&nbsp;&nbsp;&lt;a&nbsp;href="foo.html"&gt;foo&lt;/a&gt;
#       &lt;/html&gt;
#
# which of ourse displayed by a browser shows
#
#       <html>
#           <h1>frog dog</h1>
#           <a href="foo.html">foo</a>
#       </html>
#
function html_to_displayable_html($text) {
     #
     # & becomes &amp;
     #
     $text=preg_replace("/&/","&amp;",$text);
     #
     # < becomes &lt;
     #
     $text=preg_replace("/</","&lt;",$text);
     #
     # > becomes &gt;
     #
     $text=preg_replace("/>/","&gt;",$text);
     #
     # SPACE or '' becomes &nbsp;
     #
     $text=preg_replace("/ /","&nbsp;",$text);
     #
     # TAB becomes &nbsp;&nbsp;&nbsp;
     #
     #$text=preg_replace("/\t/","&nbsp;",$text);
     return $text;
}
?>

htaccess_dir_needs_password/index.html

TOC

<html>
<table width="100%">
<tr valign="top">
<td width="50%">
<h1>Protected with new fangled .htacl</h1>
<h2>.htpasswd and .htaccess files</h2>
After I get this working you will need
a htaccess password and user id to 
get into here.
<p>
Normally to protect files with .htaccess
you would use these two files
<ul>
<li>.htpasswd 
<li>.htaccess 
</ul>
But these people at 100webspace.net
seem to do it slightly different
and they use these two files
<ul>
<li><a href=".htacl">.htacl</a>   
<li><a href=".htaclu">.htaclu</a>
</ul>
<h2>.htaccess file</h2>
The first file 
<ul>
<li>.htacl   
</ul>
seems to replace the file 
<ul>
<li>.htaccess 
</ul>
And contains this stuff
<blockquote>
AuthUserFile /content/usrhome/050/miksup//www/miksup.100webspace.net/class/htaccess_dir_needs_password/.htaclu<br>
AuthName Members<br>
AuthType Basic<br>
Require valid-user<br>
</blockquote>
Which basicly say that you have to enter a valid userid
to get into the area, and it points to 
<ul> 
<li>.htaclu 
</ul>
As the place where the passwords are stored.
<p>
It replaces the .htaccess file that I generated
at this <a href="http://www.tools.dynamicdrive.com/password/">site</a>.
<p>
And the data that this site generated for me to put in the file
looks like this.
<blockquote>
AuthName "Restricted Area"<br> 
AuthType Basic <br>
AuthUserFile /class/htaccess_dir_needs_password/.htpasswd<br> 
AuthGroupFile /dev/null<br>
require valid-user
</blockquote>
Which was closed enough that it protected
the subdirectory, but didn't let me in
because it mangled the path to the
<blockquote>
.htpasswd
</blockquote>
file by not prefixing it with
<blockquote>
/content/usrhome/050/miksup//www/miksup.100webspace.net/......
</blockquote>
<h2>.htpasswd file</h2>
The people at 100webspace.net
use the file
<ul>
<li>.htaclu 
</ul>
to replace the password file of 
<ul>
<li>.htpasswd  
</ul>
Their password file .htaclu contains this
<blockquote>
# password file<br>
homer:QEOPqDNxKqBpy<br>
popeye:UEAqxz0EiYV9z
</blockquote>
As opposed to the file .htpasswd I generated at this
<a href="http://www.tools.dynamicdrive.com/password/">site</a>
which contained this
<blockquote>
homer:7ZrUqqx5h7lac<br>
popeye:V7b97/1Zerte6
</blockquote>
Spelled out in English the site
that generates .htaccess passwords
and control data is
<blockquote>
<a href="http://www.tools.dynamicdrive.com/password">www.tools.dynamicdrive.com/password</a>
</blockquote>
For useless information I tried saving the userids and passwords
generated by the above site into the
<ul>
<li>.htaclu 
</ul>
password file and it wouldn't work.
<p>
I don't know why!
When I edited the file it looks
like the folks at 100webspace.net
will not let me modify the file.
Maybe that is why!
<p>
And hey look at those permissions!
They are
<blockquote>
644 (rw),(r),(r)
</blockquote>
Instead of the
<blockquote>
755 (rwx),(rx),(rx)
</blockquote>
for 
<blockquote>
index.html
</blockquote>
Well those permissions shouldn't stop me from writting to the file!
Lets try this again!
<p>
Well I tried again, and I do have the correct permissions to
write to the file. But.....
<p>
They are somehow intercepting my write and not letting me do it.
After I write I get this message which I failed to notice before.
<blockquote>
  Error while saving the file! Please contact the technical support! 
</blockquote>
<h2>Protected with the old fashioned .htaccess</h2>
But to see if the .htaccess method does work here
I set up this subdirectory and protected with
.htaccess instead of their .htacl 
<blockquote>
<a href="../htaccess_dir_needs_password2">../htaccess_dir_needs_password2</a>
</blockquote> 
<p>
<hr>
<p>
For how to protect single FILES as opposed to DIRECTORIES
see these two URL's
<ul>
<li><a href="../protected_file.php">protected_file.php</a>
<li><a href="../protected_file.html">protected_file.html</a>
</ul>
</td>
<td width="50%">
&nbsp;
</td>
</tr>
</table>
</html>

htaccess_dir_needs_password2/index.html

TOC

<html>
<h1>Protected with .htaccess </h1>
I am protecting this directory with
the old fashion
<ul>
<li>.htpasswd 
<li>.htaccess 
</ul>
instead of their new fangled
<ul>
<li>.htaclu 
<li>.htacl
</ul>
And HOT DAMN!!!
The .htaccess method WORKS!!!!!
<p>
So I can create usernames and passwords at
<blockquote>
<a href="http://www.tools.dynamicdrive.com/password">www.tools.dynamicdrive.com/password</a>
</blockquote>
<h3>Protected with new fangled .htacl</h3>
Now this subdirectory
<blockquote>
<a href="../htaccess_dir_needs_password">../htaccess_dir_needs_password</a>
</blockquote>
is protected with their new fangled
.htacl method as opposed to the
tried and true .htaccess
method I know how to use
<p>
<hr>
<p>
For how to protect single FILES as opposed to DIRECTORIES
see these two URL's
<ul>
<li><a href="../protected_file.php">protected_file.php</a>
<li><a href="../protected_file.html">protected_file.html</a>
</ul>
</html>

../ip_address_gif.php

TOC

<script language="php">
#echo "REMOTE_ADDR=${REMOTE_ADDR}<br>";
#echo "n=$n";
#
# add code to 
#        1) pick a different font counter
#           put the new fonts in the same subdirecttory
#        2) pick a 1 pixel gif image
#           which of course is a different font
#        3) allow it to be called with out any arguments
#           to make it harder for the censors on indy media
#           to find it.
#           ie instead of calling it as
#                     <img src="counter.php?n=mr_liberal">
#           just make it
#                     <img src="c.jpg.php">
#           and with that make it put out an invisible gif 
#           to some default counter. maybe based on the web page
#           number
#
#
#
# this program has been moved to the root directory and named 
#             counter.php
# it was orginally named
#             counter4.php
# in this subdirectory
#             images_for_counters
# with a full path of
#             images_for_counters/counter4.php
#
# the argument 
#             d=n
# is no longer used. 
# that was for the digit to display
# since we display ALL the digits that is
# a moot issue
#            
# the argument 
#             c=name
# is used and name is the counter name to fetch
# from the SQL database and display
#
# the argument 
#             l=log_subdirectory
#
# has been added to the PHP version
# it is the subdirectory of the log file
#
#
# added this code so we can include it from
#       jpg.php
# $len is the min number of digits to display

#
# get a prefix to use for the font images
# if its null we dont use a prefix
#
if ($font == '') {
  $font=$_REQUEST['font'];
}
#
# if they enter a garbage font make it null
# later on change the code to verify the font file and
# if it dont exist change the font to null
#
if (! ($font == 'hb' ||       $font == 'hbig' ||      $font == 'hm' || 
       $font == 'hs' ||       $font == 'black1x1' ||  $font == 'clear1x1' ||  
       $font == 'white1x1' || $font == 'one' ||       $font == 'mrliberal' ||    
       $font == '' )) 
       {
           $font='';
       }


</script>
<script language="php">
#
# added this code so we can include it from
#       jpg.php
# and set n= to something in the jpg.php code

if ($n == '' ) {
   $n=$_REQUEST['n'];
}
























$number="0000000000";
$number=${REMOTE_ADDR};


$num_array=preg_split('/\./', $number , 4);
#echo "0 = '$num_array[0]'<p>";
#echo "1 = '$num_array[1]'<p>";
#echo "2 = '$num_array[2]'<p>";
#echo "3 = '$num_array[3]'<p>";

#$number=preg_replace('/\./', '', $number , 4); 


 

#
# add leading zeros to the number
#
while( $len > strlen($number)) {
 $number="0".$number;
 #echo "$number<br>";
}

#
# now we take $number and build an image from it
#
 # set these to the image width and height
 # after we caculate it from the digits in the image
 $xxheight=1;
 $xxwidth=0;
 #
 # read in the 10 digit images
 # may have to change this from PNG to GIF  to JPG
 #
 $ifiles[0]='images_for_counters/'.$font.'0.gif';
 $ifiles[1]='images_for_counters/'.$font.'1.gif';
 $ifiles[2]='images_for_counters/'.$font.'2.gif';
 $ifiles[3]='images_for_counters/'.$font.'3.gif';
 $ifiles[4]='images_for_counters/'.$font.'4.gif';
 $ifiles[5]='images_for_counters/'.$font.'5.gif';
 $ifiles[6]='images_for_counters/'.$font.'6.gif';
 $ifiles[7]='images_for_counters/'.$font.'7.gif';
 $ifiles[8]='images_for_counters/'.$font.'8.gif';
 $ifiles[9]='images_for_counters/'.$font.'9.gif';
 $ifiles[10]='images_for_counters/'.$font.'dot.gif';
 #
 # loop thru and open a gif file for each number from 0 to 9
 #
# for ($i=0;$i<10;$i++) {
 for ($i=0;$i<11;$i++) {
   #list($zwidth, $zheight, $ztype, $zattr)=getimagesize($ifiles[$i]);
   $size=getimagesize($ifiles[$i]);
   $gif_width[$i]=$size[0];
   $gif_height[$i]=$size[1];
   if ($gif_height[$i] >  $xxheight ) {
     $xxheight=$gif_height[$i];
   }
   $gif[$i]=@imagecreatefromgif ($ifiles[$i]);
   if (!$gif[$i]) {
     echo "error reading file $ifiles[$i] for image $i<br>";
   }  
 }
#
# get the total width of the image
# by adding up the width of each digit in the number
#
 for ($i=0;$i<strlen($number);$i++) {
  $thisdigit=substr($number,$i,1);
  if ($thisdigit == '.' ) {
     $thisdigit=10;
  }
  $xxwidth+=$gif_width[$thisdigit];
 }
 #
 # create the image
 #
 $image=ImageCreate($xxwidth, $xxheight);
 #
 # set the R,G,B background color of the imagee
 #
 $background_color=ImageColorAllocate($image,255,255,255);
 #
 # define RGB black as a color used on the image
 #
 $black=ImageColorAllocate($image,0,0,0);
 #
 # copy the color $black into the image between 0,0 and 50,50
 #
 #ImageFilledRectangle($image,0,0,$xxwidth,$xxheight,$black);
 #
 # convert the $number to an image
 # copy each digit of the number to our image from left to right
 #
 $next_x=0;
 for ($i=0;$i<strlen($number);$i++) {
  $thisdigit=substr($number,$i,1);

  if ($thisdigit == '.') {
    $thisdigit=10;
  }


  $zfile=$ifiles[$thisdigit];
  $zhandle=$gif[$thisdigit];
  #
  # copy the gif image to our image
  #
  $rc=imagecopy ( $image, $zhandle, 
                  $next_x, ($xxheight - $gif_height[$thisdigit]) , 
                  0, 0,
                  $gif_width[$thisdigit],$xxheight);
  $rc=$rc?"true":"failed";
  $next_x=$next_x+ $gif_width[$thisdigit];
 }
 #
 # return the image
 #
 header("Content-Type: image/png");
 ImagePNG($image);





function do_sql_select($counter_name) {
 $rc=0; 
 return $rc;
}
</script> 

../jpg.php

TOC

<script language="php">
#$n="";     # counter number to use
$n="frog";  # counter number to use
$l="";      # log file subdirectory
$len=4;     # length in digits of the number
include 'counter.php';
#
# this doesnt work. the documentation says it will
#
include "http://miksup.100webspace.net/counter.php?n=c";
</script>

../list_ceweekly_all.php

TOC

<html>
<head>
<title> List ALL CEWEEKLY email addresses </title>
<LINK rel="stylesheet" href="/0____css.css" type="text/css">
<META name="resource-type" content="Strategic Edge">
<META name="description" content="Strategic Edge">
<META name="distribution" content="global"> 
<META name="keywords" content="CEWEEKLY, CJHUNTER, CJHuner, email, e-mail, address, addresses">
</head>
<h1 align="center">List ALL CEWEEKLY email addresses</h1>
<?php
 include "0_php_functions.php";
 #$types=array('new_lead', 'called','gave up');
 #
 # this function is used to copy the deleted
 # email record into a backup sql file so
 # we have a copy of who deleted it when
 # and from what ip address
 #
 include "0_php_function_dup_email.php";
 #
 # get the ip address so we can tell where people came from
 #
 $my_ip_address=${REMOTE_ADDR};












?>





<?php #include "sbd_head.php"; ?>
<?php
#
# figure out what to list
#      new leads
#      leads we called
#      leads we never contacted and gave up on
#      all leads
#










#
# figure out how to sort them

#echo "sort $how_to_sort <p>";
if ($how_to_sort == '') {
   $how_to_sort=$_POST["how_to_sort"];
}
#echo "sort $how_to_sort<p>";
if ($how_to_sort == '' ) {
   $how_to_sort='email,date_created,last_emailed';
}

$search_for=$_POST["search_for"];
$search_created=$_POST["search_created"];
$search_emailed=$_POST["search_emailed"];
$search_limit=$_POST["search_limit"];
if (!preg_match("/^[0-9]*$/",$search_limit)) {
   $search_limit=10000;

$search_offset=$_POST["search_offset"];
if ($search_offset == '') {
   $search_offset=0;
}

?>





<form action="list_ceweekly_all.php" method="post">
<br>
<p>Sort by: 
<span style="font-size:75%;">

 <input type="radio" name="how_to_sort" value="email,date_created,last_emailed"
 <?php if ($how_to_sort == 'email,date_created,last_emailed' ) { echo " checked "; } ?> 
> E-mail, created, e-mailed




&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="radio" name="how_to_sort" value="email,last_emailed,date_created"
 <?php if ($how_to_sort == 'email,last_emailed,date_created' ) { echo " checked "; } ?> 
> E-mail, emailed, created



&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="radio" name="how_to_sort" value="date_created,last_emailed,email"
 <?php if ($how_to_sort == 'date_created,last_emailed,email' ) { echo " checked "; } ?> 
> Created, emailed, email


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="radio" name="how_to_sort" value="date_created,email,last_emailed"
 <?php if ($how_to_sort == 'date_created,email,last_emailed' ) { echo " checked "; } ?> 
> Created,  email, emailed 



&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="radio" name="how_to_sort" value="last_emailed,date_created,email"
 <?php if ($how_to_sort == 'last_emailed,date_created,email' ) { echo " checked "; } ?> 
> E-mailed, created, email




&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="radio" name="how_to_sort" value="last_emailed,email,date_created"
 <?php if ($how_to_sort == 'last_emailed,email,date_created' ) { echo " checked "; } ?> 
> E-mailed, email, created 


















</span>
<br>

Search for: E-mail
<input type="text" name="search_for" value="<?php echo $search_for;?>">


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Created
<input type="text" name="search_created" value="<?php echo $search_created;?>">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; E-mailed 
<input type="text" name="search_emailed" value="<?php echo $search_emailed;?>">
<br>
Skip over 




<input type="text" 
name="search_offset" value="<?php 
                                  if ($search_limit == '') {
                                     $next_offset=0;
                                  }
                                  else {
                                     $next_offset=$search_offset+$search_limit;
                                  }
                                  echo $next_offset;?>">




records and then list next 
<input type="text" name="search_limit" value="<?php echo $search_limit;?>">
records
<br>   
<input type="submit" name=submit value="SUBMIT">
</form>
<table width="100%" border="0">
<tr>
<td>&nbsp;</td>
<td>
<?php
   function dump_line($name, $value) {
      if ($value != '') {
         echo "<tr><td align=\"right\">$name</td><td>$value</td></tr>";
      }
      return; 
   }
   require('sql_passwords.php');
   # 
   # connect to SQL 
   #  
   $link = mysql_connect($z_hardcoded_sqlurl,  
                         $z_hardcoded_database,  
                         $z_hardcoded_password ) 
                         or die('Could not connect: ' . mysql_error()); 
   # 
   # select the database I want to use 
   # 
   mysql_select_db($z_hardcoded_database) or die('Could not select database'); 







   #  
   # build sql statement to grab all the data entered so far
   #
   $query = "select 
                    email,
                    date_created,
                    last_emailed
                 from body_shops ";
   $wheres=0;
   if ($search_for != '' ) {
      if ($wheres == 0) {
         $query.=" where "; 
      }
      $wheres++;

      $query.=" email like '%$search_for%' ";
      #                date_created like '%$search_for%'
      #       ";
      #echo "query = $query<br>";
   }

   if ($search_created != '' ) {
      if ($wheres == 0) {
         $query.=" where "; 
      }
      $wheres++;
      if ($wheres > 1) {
         $query.=" and "; 
      }
      
      $query.=" date_created like '%$search_created%' ";
      #echo "query = $query<br>";
   }


   if ($search_emailed != '' ) {
      if ($wheres == 0) {
         $query.=" where "; 
      }
      $wheres++;
      if ($wheres > 1) {
         $query.=" and "; 
      }
      
      $query.=" last_emailed like '%$search_emailed%' ";
      #echo "query = $query<br>";
   }




   if ($how_to_sort  != '' ) {
      $query.= "  order by $how_to_sort ";
   }


   if ($search_limit != '') {
      $query.= "  limit $search_offset , $search_limit ";
   }


   echo "query = $query<br>";

   #
   # display the select
   # 
   $result = mysql_query($query) or die('Query failed: ' . mysql_error());
   echo '<table border="1">';
      echo "<tr style=\"font-size:120%;\">";
      echo "<td>Created</td>";
      echo "<td>E-mailed</td>";
      echo "<td>E-Mail</td>";
      echo "</tr>";
   while($line = mysql_fetch_array($result, MYSQL_ASSOC)) { 
      # 
      # how to read like PERL does in PHP 
      # the name of each selected value is used as a subscript or hash value 
      # 
      $email=$line['email'];

      $date_created=$line['date_created'];
      $last_emailed=$line['last_emailed'];
      if ($last_emailed == '0000-00-00' ) {
         $last_emailed='&nbsp;'; 
      }
      echo "<tr>";
      echo "<td><nobr>$date_created</nobr></td>";
      echo "<td><nobr>$last_emailed</nobr></td>";
      echo "<td><nobr>$email</nobr></td>";
      echo "</tr>";
   } 
   echo '</table>';
   if ($result) { 
   } 
   else { 
      echo "Error!!!!!! select failed!!!!!!!!!!!!!!!!!"; 
   }
   # 
   # close the SQL connection 
   # 
   mysql_close($link); 
?>

</td>
<td>&nbsp;</td>
</tr>
</table>




<hr>

../curl_ftp_stuff/list_z_files.php

TOC

<?php
#
# initialize curl
#
$curl=curl_init();
#
# do a ftp to $site and list the files
#
curl_setopt($curl,CURLOPT_URL,"ftp://$site");
#
# i think this means to list all the files
#
curl_setopt($curl,CURLOPT_FTPLISTONLY,0);
#
# this is the syntax of the ftp command
#
#    ftp://user:password@host:port/path
#
# ftp to my site and get a listing
#
curl_setopt($curl,CURLOPT_USERPWD,$userid.":".$password);
#
# i think this says go get the data
#
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
#
# i think this says run all the stuff we just defined
# and place the data received in $result
#
$result=curl_exec($curl);
#
# close curl
#
curl_close($curl);
#
# remove all the data i consider sensitive
#
$result=remove_sensitive_data($result, $my_site, "my-site");
$result=remove_sensitive_data($result, $userid, "my-site");
#
# print the data we got with the ftp to ftp.gnu.org
#
echo "<pre>";
print $result;
echo "</pre>";
#
# the first time i ran this my listing looked like this
#
#     cgi-bin
#     _private
#     index.html
?>

../log_comment.php

TOC

<?php
$mucho=10000;
require('sql_passwords.php');
#
# get the variables they entered on the form
#
$comment=$_POST['comment'];
$url=$_POST['url'];
$current_time=$_POST['current_time'];

#
# if the time is blank or null use current time
#
if (preg_match ( '/^ *$/', $current_time)) {
   $current_time=date("Y/m/d H:i:s",(time()-(7*60*60)));
}




$xpassword=$_POST['password'];
#
# replace spaces on the comment line and URL with underscores
$comment=preg_replace ('/ /', '_', $comment, $mucho);
$url=preg_replace ('/ /', '_', $url, $mucho);
#
# if the month was entered as a single digit change it to 0n
#
$current_time=preg_replace ('/\/([0-9])\//', '/0${1}/', $current_time, $mucho);
#
# if the day was entered as a single digit change it to 0n
#
$current_time=preg_replace ('/\/([0-9]) /', '/0${1} ', $current_time, $mucho);
#
# if the hour was entered as a single digit change it to 0n
#
$current_time=preg_replace ('/ ([0-9]):/', ' 0${1}:', $current_time, $mucho);
#
# if the minute was entered as a single digit change it to 0n
#
$current_time=preg_replace ('/:([0-9]):/', ':0${1}:', $current_time, $mucho);
#
# if the second was entered as a single digit change it to 0n
#
$current_time=preg_replace ('/:([0-9]) /', ':0${1} ', $current_time, $mucho);
$current_time=preg_replace ('/:([0-9])$/', ':0${1} ', $current_time, $mucho);
#
#remove all the spaces in the date/time
#
$current_time=preg_replace ('/ /', '_', $current_time, $mucho);
#echo "inputs:comment=$comment<br>url=$url<br>time=$current_time<br>";
#
# get the current time
#
$now=date("Y/m/d H:i:s",(time()-(7*60*60)));
#
# get their IP address
#
$the_ip_address=${REMOTE_ADDR};
#
# if the comment they entered is not blank
# build a comment line to display and log it
# to disk
#
$comment_as_logged="";
if ($comment != "" ) {
   $comment_as_logged=$now." ".$the_ip_address." COMMENT ".$current_time." ".$comment." ".$url;




   if ( $z_hardcoded_password != $xpassword ) {
      $comment_as_logged="<SPAN style=\"font-size: 300%; background-color: rgb(255,0,0);\"><b><i>Invalid Password</i></b></span>";
   }
   else {
      #
      #open the logfile
      #
      $F=fopen("log_file_poop.txt","a");
      #
      # dump the data to the log file
      #
      fwrite ( $F, "$comment_as_logged\n" );
      #
      #close the logfile
      #
      $rc=fclose($F);
   }
}
#
# build a new current time to display on the form
#
if ( $z_hardcoded_password == $xpassword ) {
   $current_time=$now;
   $comment="";
   $url="";
}
#
# print the form
#
print "<form action=\"log_comment.php\" method=\"post\">";
print "<br>";
print "<table>";
print "<tr>";
print "<td>Comment:</td>";
print "<td><input type=\"text\" name=\"comment\" value=\"$comment\" size=\"60\"></td>";
print "</tr>";

print "<tr>";
print "<td>URL:</td>";
print "<td><input type=\"text\" name=\"url\" value=\"$url\" size=\"60\"></td>";
print "</tr>";
print "<tr>";
print "<td>Comment Time:</td>";



print "<td><input type=\"text\" name=\"current_time\" value=\"$current_time\" size=\"19\" maxlength=\"19\"></td>";
print "</tr>";

print "<td>Password:</td>";
print "<td><input type=\"password\" name=\"password\" value=\"$xpassword\"></td>";
print "</tr>";


print "<tr>";
print "<td>&nbsp;</td>";
print "<td><input type=\"submit\" name=submit value=\"Write Comment to Log File\"></td>";
print "</tr>";
#
# if we wrote something to the log file display it
#
if ($comment_as_logged != "" ) {
   print "<tr>";
   print "<td>&nbsp;</td>";
   print "<td>";
   print "this comment was written to disk:<br>";
   print "<blockquote><nobr>";
   print "$comment_as_logged";
   print "</blockquote></nobr>";
   print "</td>";
   print "</tr>";
}
print "<tr>";
print "<td>&nbsp;</td>";
print "<td>&nbsp;<p></td>";
print "</tr>";
print "<tr>";
print "<td>&nbsp;</td>";
print "<td>&nbsp;<p></td>";
print "</tr>";
print "<tr>";
print "<td>&nbsp;</td>";
print "<td>&nbsp;<p></td>";
print "</tr>";
print "<tr>";
print "<td>&nbsp;</td>";
print "<td>&nbsp;<p></td>";
print "</tr>";



print "<tr>";
print "<td>&nbsp;</td>";
print "<td><input type=\"reset\" name=reset value=\"CLEAR MENU\"></td>";
print "</tr>";

print "</table>";


#print "<hr>";
#print "<input type=\"reset\" name=reset value=\"CLEAR MENU\">";
#print "<input type=\"hidden\" name=\"formname\" value=\"resume.form\">";
#print "<input type=\"hidden\" name=\"title\" value=\"E-mail Resume\">";
#print "<input type=\"hidden\" name=\"bcc\" value=\"\">";
#print "<input type=\"hidden\" name=\"debugflag\" value=\"\">";
#print "</form>";
?>

../log_them.php

TOC

<h2>Grab their IP address and other info and Log them to disk!</h2>
<table border=1>
<script language="php">
echo "<tr><td><b>Remote Server ip</b></td><td>${SERVER_ADDR}</td></tr>";
echo "<tr><td><b>Your IP</b></td><td> ${REMOTE_ADDR}</td></tr>";
echo "<tr><td><b>Your Port</b></td><td> ${REMOTE_PORT}</td></tr>";
echo "</table>";
echo "<table border=1>";
echo "<tr><td><b>HTTP_X_FORWARDED_FOR</b></td></tr><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ${HTTP_X_FORWARDED_FOR} &nbsp; </td></tr>";
echo "<tr><td><b>HTTP_REFERER</b></td></tr><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${HTTP_REFERER} &nbsp; </td></tr>";
echo "<tr><td><b>HTTP_USER_AGENT</b></td></tr><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${HTTP_USER_AGENT} &nbsp; </td></tr>";
echo "<tr><td><b>HTTP_VIA</b></td></tr><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${HTTP_VIA} &nbsp; </td></tr>";
echo "<tr><td><b>REQUEST_URI</b></td></tr><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${REQUEST_URI} &nbsp; </td></tr>";
echo "</table>";
#
# build the string which is written to the log file
#
$logout="";
$logout.=" SERVER_ADDR=${SERVER_ADDR} ";
$logout.=" REMOTE_ADDR=${REMOTE_ADDR} ";
$logout.=" REMOTE_PORT=${REMOTE_PORT} ";
$logout.=" HTTP_X_FORWARDED_FOR=${HTTP_X_FORWARDED_FOR} ";
$logout.=" HTTP_REFERER=${HTTP_REFERER} ";
$logout.=" HTTP_USER_AGENT=${HTTP_USER_AGENT} ";
$logout.=" HTTP_VIA=${HTTP_VIA} ";
$logout.=" REQUEST_URI=${REQUEST_URI} ";
</script>
<table border=1>
<tr>
<td>
<script language="php">
echo "logout=$logout<br>";
</script>
</td>
</tr>
</table>
<table border=1>
<tr>
<td>
<script language="php">
#
# write the stuff to the log file
#
$file="log_file.txt";
#$F=fopen("log_file.txt","a");
$F=fopen($file,"a");
print "opening file ($file)[$F]<br>";
fwrite ( $F, "log $logout\n" );
$rc=fclose($F);
print "closing file ($file) rc=$rc<br>";
</script>
</td>
</tr>
</table>

../dns_stuff/look_up_ip_addresses.php

TOC

<h2>Look up a few IP addresses</h2>
<?php
echo "DNS Stuff<p>";
echo "<table border=1>";
foo('156.42.68.2');
foo('70.162.70.13');
foo('207.69.137.20');
foo('149.169.170.93');
foo('4.240.253.93');
foo('207.69.138.7');
foo('149.169.170.117');
foo('71.38.116.253');
foo('156.42.68.3');
foo('129.219.181.234');
foo('149.169.170.135');
foo('129.219.181.234');
foo('149.169.170.91');
foo('4.240.253.27');
foo('130.13.248.58');
foo('68.227.233.24');
foo('66.245.214.50');
foo('132.162.251.146');
#coo('one of the next 4');
foo('129.219.181.234');
foo('71.108.185.244');
foo('129.219.207.225');
foo('156.42.68.3');
foo('68.109.142.181');
foo('24.98.81.35');
foo('63.224.136.211');
foo('207.200.116.198');
#coo('a null header follows');
foo('72.201.232.148');
foo('64.12.116.131');
foo('210.212.176.6');
foo('205.188.117.68');
foo('159.53.110.142');
foo('208.108.129.141');
foo('140.198.73.127');
foo('70.58.250.170');
foo('196.33.248.227');
foo('70.57.102.232');
#coo('mrl');
foo('69.173.1.243');
foo('140.198.72.208');
foo('65.57.245.11');
foo('24.15.62.243');
foo('129.219.244.8');
#coo('ice');
foo('156.42.68.3');
foo('70.249.242.66');
foo('24.91.45.130');
#coo('web mail - from what i sent azrkba');
foo('70.176.2.28');
foo('129.219.244.8');
foo('66.1.196.87');
foo('68.231.189.3');
foo('68.106.43.250');
foo('68.106.226.166');
foo('66.226.239.182');
foo('140.198.73.98');
foo('199.64.0.252');
foo('64.202.160.161');
foo('199.41.217.151');

foo('216.218.240.191');
foo('216.17.145.98');
foo('216.240.146.66');
foo('216.17.145.113');
foo('70.176.140.97'); # kevins IP address
foo('128.173.123.153');
foo('128.218.224.54');
foo('129.219.181.234');
foo('129.219.207.225');
foo('129.219.244.8');
foo('130.13.248.58');
foo('130.166.243.54');
foo('132.162.251.146');
foo('140.198.72.146');
foo('140.198.72.200');
foo('140.198.72.208');
foo('140.198.72.230');
foo('140.198.72.234');
foo('140.198.73.121');
foo('140.198.73.127');
foo('140.198.73.135');
foo('140.198.73.140');
foo('140.198.73.147');
foo('140.198.73.154');
foo('140.198.73.170');
foo('140.198.73.178');
foo('140.198.73.182');
foo('140.198.73.183');
foo('140.198.73.212');
foo('140.198.73.225');
foo('140.198.73.232');
foo('140.198.73.234');
foo('140.198.73.45');
foo('140.198.73.67');
foo('140.198.73.98');
foo('140.198.74.107');
foo('140.198.74.215');
foo('149.169.170.117');
foo('149.169.170.135');
foo('149.169.170.91');
foo('149.169.170.93');
foo('149.169.241.127');
foo('152.22.0.254');
foo('156.42.68.2');
foo('156.42.68.3');
foo('159.53.110.142');
foo('159.53.46.141');
foo('170.215.39.216');
foo('196.33.248.227');
foo('199.41.217.151');
foo('199.64.0.252');
foo('205.188.117.68');
foo('207.114.130.130');
foo('207.200.116.198');
foo('207.69.137.20');
foo('207.69.138.7');
foo('208.108.129.141');
foo('208.47.100.80');
foo('210.212.176.6');
foo('216.17.145.113');
foo('216.17.145.98');
foo('216.19.59.136');
foo('216.218.240.191');
foo('216.240.146.66');
foo('24.15.62.243');
foo('24.23.39.252');
foo('24.251.86.114');
foo('24.255.18.131');
foo('24.255.45.99');
foo('24.91.45.130');
foo('24.98.81.35');
foo('4.240.234.70');
foo('4.240.249.157');
foo('4.240.253.27');
foo('4.240.253.93');
foo('63.224.136.211');
foo('64.12.116.131');
foo('64.136.26.227');
foo('64.202.160.161');
foo('64.241.37.140');
foo('64.72.112.136');
foo('65.13.66.43');
foo('65.57.245.11');
foo('66.1.196.87');
foo('66.167.45.76');
foo('66.226.239.182');
foo('66.245.214.50');
foo('66.81.157.12');
foo('66.82.9.58');
foo('67.0.118.33');
foo('67.136.139.111');
foo('67.150.237.152');
foo('67.42.46.133');
foo('68.106.226.166');
foo('68.106.43.250');
foo('68.109.142.181');
foo('68.110.90.1');
foo('68.110.97.56');
foo('68.2.29.199');
foo('68.2.32.102');
foo('68.226.127.38');
foo('68.227.233.24');
foo('68.231.189.3');
foo('68.255.5.56');
foo('68.63.183.100');
foo('68.98.122.53');
foo('68.99.231.130');
foo('69.11.144.75');
foo('69.173.1.243');
foo('69.230.224.238');
foo('70.112.69.129');
foo('70.162.70.13');
foo('70.176.140.97');
foo('70.176.140.97'); # kevins IP address
foo('70.176.2.28');
foo('70.199.92.115');
foo('70.249.242.66');
foo('70.57.100.184');
foo('70.57.102.232');
foo('70.58.250.170');
foo('70.59.241.226');
foo('71.108.185.244');
foo('71.35.26.60');
foo('71.35.8.134');
foo('71.38.116.253');
foo('72.201.232.148');
foo('74.6.68.114');





















#
# correctly sorted
#
foo('4.240.234.70');
foo('4.240.249.157');
foo('4.240.253.27');
foo('4.240.253.93');
foo('24.15.62.243');
foo('24.23.39.252');
foo('24.91.45.130');
foo('24.98.81.35');
foo('24.251.86.114');
foo('24.255.18.131');
foo('24.255.45.99');
foo('63.224.136.211');
foo('64.12.116.131');
foo('64.72.112.136');
foo('64.136.26.227');
foo('64.202.160.161');
foo('64.241.37.140');
foo('65.13.66.43');
foo('65.57.245.11');
foo('66.1.196.87');
foo('66.81.157.12');
foo('66.82.9.58');
foo('66.167.45.76');
foo('66.226.239.182');
foo('66.245.214.50');
foo('67.0.118.33');
foo('67.42.46.133');
foo('67.136.139.111');
foo('67.150.237.152');
foo('68.2.29.199');
foo('68.2.32.102');
foo('68.63.183.100');
foo('68.98.122.53');
foo('68.99.231.130');
foo('68.106.43.250');
foo('68.106.226.166');
foo('68.109.142.181');
foo('68.110.90.1');
foo('68.110.97.56');
foo('68.226.127.38');
foo('68.227.233.24');
foo('68.231.189.3');
foo('68.255.5.56');
foo('69.11.144.75');
foo('69.173.1.243');
foo('69.230.224.238');
foo('70.57.100.184');
foo('70.57.102.232');
foo('70.58.250.170');
foo('70.59.241.226');
foo('70.112.69.129');
foo('70.162.70.13');
foo('70.176.2.28');
foo('70.176.140.97');
foo('70.176.140.97'); # kevins IP address
foo('70.199.92.115');
foo('70.249.242.66');
foo('71.35.8.134');
foo('71.35.26.60');
foo('71.38.116.253');
foo('71.108.185.244');
foo('72.201.232.148');
foo('74.6.68.114');
foo('128.173.123.153');
foo('128.218.224.54');
foo('129.219.181.234');
foo('129.219.207.225');
foo('129.219.244.8');
foo('130.13.248.58');
foo('130.166.243.54');
foo('132.162.251.146');
foo('140.198.72.146');
foo('140.198.72.200');
foo('140.198.72.208');
foo('140.198.72.230');
foo('140.198.72.234');
foo('140.198.73.45');
foo('140.198.73.67');
foo('140.198.73.98');
foo('140.198.73.121');
foo('140.198.73.127');
foo('140.198.73.135');
foo('140.198.73.140');
foo('140.198.73.147');
foo('140.198.73.154');
foo('140.198.73.170');
foo('140.198.73.178');
foo('140.198.73.182');
foo('140.198.73.183');
foo('140.198.73.212');
foo('140.198.73.225');
foo('140.198.73.232');
foo('140.198.73.234');
foo('140.198.74.107');
foo('140.198.74.215');
foo('149.169.170.91');
foo('149.169.170.93');
foo('149.169.170.117');
foo('149.169.170.135');
foo('149.169.241.127');
foo('152.22.0.254');
foo('156.42.68.2');
foo('156.42.68.3');
foo('159.53.46.141');
foo('159.53.110.142');
foo('170.215.39.216');
foo('196.33.248.227');
foo('199.41.217.151');
foo('199.64.0.252');
foo('205.188.117.68');
foo('207.69.137.20');
foo('207.69.138.7');
foo('207.114.130.130');
foo('207.200.116.198');
foo('208.47.100.80');
foo('208.108.129.141');
foo('210.212.176.6');
foo('216.17.145.98');
foo('216.17.145.113');
foo('216.19.59.136');
foo('216.218.240.191');
foo('216.240.146.66');





  
echo "</table>";
?> 
<script language="php">
function foo ($ip) {
 if ($ip == '' ) {
   return;
 }
 $name = gethostbyaddr($ip);
 echo "<tr><td>$ip</td><td>$name &nbsp;</td></tr>";

 if (checkdnsrr ( $ip, 'MX')) {
    echo "<tr><td>&nbsp;</td><td>MX</td></tr>";
 }






 return;
}



function coo ($ip) {
 if ($ip == '' ) {
   return;
 }
 echo "<tr><td colspan=2>$ip</td></tr>";
 return;
}
</script>

../dns_stuff/look_up_url_addresses.php

TOC


Warning: file(../dns_stuff/look_up_url_addresses.php ) [function.file]: failed to open stream: No such file or directory in /home/www/miksup.100webspace.net/class/display_functions.php on line 20

Warning: Invalid argument supplied for foreach() in /home/www/miksup.100webspace.net/class/display_functions.php on line 21

../cgi-bin/mod.php

TOC

<?php
#
# get the function to convert raw html to printable html
#
include "../class/html_to_displayable_html.php";
function display_data_as_textarea ($datatodump) {
   #
   # this function just displays the data in an HTML 
   # text area box which they can scroll
   #
   $cols="110";
   $rows="14";
   echo "<blockquote>"; 
   echo "<textarea name=\"nothing\" cols=\"$cols\" rows=\"$rows\">";
   echo "$datatodump"; 
   echo "</textarea>";
   echo "</blockquote>";
   return;
}
#
# get the data from the form
#
$text=$_POST['text'];
$text=preg_replace("/^ */","",$text); 
$text=preg_replace("/ *$/","",$text); 
?>
Dump files <a href="dumpfiles.php">dump files</a>
<p>
<form action="mod.php" method="post">
<input type="submit" name="submit" value="SUBMIT">
<br>
URL to Save to DISK <input type="text" name="text" value="<?php echo $text; ?>">
<br>
<input type="submit" name="submit" value="SUBMIT">
<p>
<input type="reset" name=reset value="CLEAR MENU">
</form>
<?php
#
# tell them URL we are processing
#
echo "<p>";
#
# if the URL is not null or spaces process it
#
if (preg_match("/^ *$/",$text)) {
   echo "no URL entered! Nothing processed";
   exit;
}
else {
   if (preg_match("/^http[s]*:\/\//i",$text)) {
      if (preg_match("/^http[s]*:\/\/\$/i",$text)) {
         echo "$text is not a URL! Nothing processed";
         exit;
      }
   }
   else {
      $text="http://$text";
   }
   echo "Processing&nbsp;&nbsp;&nbsp;&nbsp;<b>'$text'</b>";
   echo "<blockquote>";
   echo "<iframe src=\"$text\" width=\"100%\" height=\"300\">";
   echo "</iframe>";
   echo "</blockquote>";
   $data=file_get_contents($text);
   if ($data != "" ) {
      $datadot=preg_replace("/[<>]/",".",$data);
      #
      # remove binary characters 0 - 31 decimal  \x00 - \x1f hex
      #                    and 127 - 255 decimal \x7f - \xff hex
      # with the POSIX bracket expressions [:cntrl:] - not supported here!
      #
      #$datadot=preg_replace("/[:cntrl:]/",".",$datadot);
      $datadot=preg_replace("/[\\x00-\\x1f]/",".",$datadot);
      $datadot=preg_replace("/[\\x7f-\\xff]/",".",$datadot);
      echo "Displayed with HTML and binary characters dotted";
      display_data_as_textarea($datadot);
      #
      # remove the html from the string
      #
      echo "Displayed with HTML removed";
      $datanohtml=strip_tags($data);
      display_data_as_textarea($datanohtml);
      echo "Displayed with raw HTML";
      $datahtml=html_to_displayable_html($data);
      display_data_as_textarea($datahtml);
      #
      # get all the files that end in .html
      # and are 8 digits long
      # sort them in reverse order so the highest file 
      # is first
      #
      $files=`ls webpages/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].html | sort -r `;
      #
      # set output file number to zero
      #
      $fileout=0;
      if ($files == '' ) {
         #
         # no files exist! use zero for first file number
         #
         #echo "no files to dump<p>";
      }
      else {
            #
            # remove the path to the string
            #
            $files=preg_replace("/^.*\//","",$files);
            # 
            # if the string contains more then one file
            # remove the trailing files 
            # it could be a MS/DOS machine, MAC or UNIX
            # 
            $files=preg_replace("/[\n\r].*/m","",$files);
            #
            # remove the trailing .html
            #
            $files=preg_replace("/\.html.*/i","",$files); 
            $fileout=$files+1;
      }
      #
      # convert the number into an 8 digit number
      #
      while(strlen($fileout) < 8 ) {
         $fileout="0$fileout";
      }
      $textfileout='webpages/'.$fileout.".txt";
      $fileout=$fileout.".html";
      $filetowrite='webpages/'.$fileout;
      echo "Saving as $filetowrite and $textfileout<br>";
      #
      # the maggots disabled the file_put_contents() function
      #
      #file_put_contents($filetowrite,$data);
      #
      # open an output file
      #
      #
      # write the raw data to disk
      #
      # open the file
      #
      $outfile=fopen($filetowrite,"w");
      $bytesexpected=strlen($data);
      $byteswritten=fwrite($outfile,$data);
      #
      # did the write work!!!!
      if ($byteswritten != $bytesexpected) {
         echo "error writting file $filetowrite!!!<br>";
         echo "we expected to write $bytesexpected bytes<br>";
         echo "but $byteswritten bytes were actually written<br>"; 
      }
      #
      # close the file
      #
      fclose($outfile);
      #
      # write the data without any HTML to disk
      #
      # open the file
      #
      $outfile=fopen($textfileout,"w");
      $bytesexpected=strlen($datanohtml);
      $byteswritten=fwrite($outfile,$datanohtml);
      #
      # did the write work!!!!
      if ($byteswritten != $bytesexpected) {
         echo "error writting file $filetowrite!!!<br>";
         echo "we expected to write $bytesexpected bytes<br>";
         echo "but $byteswritten bytes were actually written<br>"; 
      }
      #
      # close the file
      #
      fclose($outfile);
   }
   else {
      echo "<p>ERROR!!!! $text did not return any data!";
   } 
}
?>

../cgi-bin/mod.pl

TOC

#!/usr/bin/perl
#
# print header stuff
#
$mydebugflag=1;
$mydebugflag=0;
print "Content-type: text/html", "\n\n";
print "<html>\n";
print "<body background=\"nevada.gif\">\n";
print "<img src=\"racing_men.gif\" border=\"0\">";
print "<img src=\"racing_men.gif\" border=\"0\">";
print "<img src=\"racing_men.gif\" border=\"0\">";
print "<img src=\"racing_men.gif\" border=\"0\">";
print "<br>";
print "<img src=\"racing_men.gif\" border=\"0\">";
print "<img src=\"racing_men.gif\" border=\"0\">";
print "<img src=\"racing_men.gif\" border=\"0\">";
print "<img src=\"racing_men.gif\" border=\"0\">";
print "<br>";
print "<img src=\"racing_men.gif\" border=\"0\">";
print "<img src=\"racing_men.gif\" border=\"0\">";
print "<img src=\"racing_men.gif\" border=\"0\">";
print "<img src=\"racing_men.gif\" border=\"0\">";
print "<br>";
#foreach $key (keys(%ENV)) {
# if ( $key eq "REMOTE_ADDR" ) {
#  print "KEY=$key<p>";
#  print "\$ENV{KEY}=$ENV{$key}<p>";
#  $my_ip_address=$ENV{'REMOTE_ADDR'};
# }
# print "$my_ip_address \$ENV{$key}=\"$ENV{$key}\"<br>\n";
#}
$my_ip_address=$ENV{'REMOTE_ADDR'};
#print "$my_ip_address<p>";
@weekarry=("SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN");
#
#define stuff to grab data entered on form
#
require CGI;
use CGI;
$cgi = new CGI;



#
# on june 28, 2006 I discovered that this program stopped working
# i suspect TRIPOD changed something in its include files.
# i changed the data from POST to GET and that appears to have fixed
# the problem. 
# buttttt it is better to process the data as POST cuz you can process
# more data so i should change it back to post when i can
#
#
# i may want to process the data myself that way i dont have 
# to rely on their stinking functions. I guess i do it this way
#


#
# on sept 30 i moved this from www.tripod.com to here and
# it seems to work. 
# i have to change the GET back to a post to make it work
# but once i do that we should be cruzing again!

if ($mydebugflag){
 if ($ENV{'REQUEST_METHOD'} eq "GET") {
  print "data is via GET<p>\n";
  $in = $ENV{'QUERY_STRING'};
  } 
 else {
  print "data is via POST<p>\n";
  #$in = <STDIN>;
  while(<STDIN>) {
  #$in .= $_;
  print $_;
  }
  }
  print "data=<table border=1><tr><td>$in<\/td><\/tr><\/table>\n";
}





#
# get the data they entered in the text bos
#
if ($mydebugflag){print "included headers and shit\n<p>";}
$errors=0;
$formtext=$cgi->param('text');
$formfile=$cgi->param('file');
$ub=$cgi->param('ub');
$rb=$cgi->param('rb');
$lb=$cgi->param('lb');
$ib=$cgi->param('ib');
$db=$cgi->param('db');
$wb=$cgi->param('wb');
$cw=$cgi->param('cw');
$ss=$cgi->param('ss');
$ii=$cgi->param('ii');
$mymy=$cgi->param('mymy');
if ($mydebugflag){print "buttoms selected<table border=1><tr><td>$ub$rb$lb$ib$db$wb$cw$ss$ii$mymy<\/td><\/tr><\/table>";}
if ($mydebugflag){print "text entered<table border=1><tr><td> $formtext $formfile <\/td><\/tr><\/table>";}





#
# they must click on ONE or more of the boxes to 
# indicate what type of news article this is.
# if they dont click on a box dont let them add
# the news article
#
if ($mydebugflag){print "checking for checked box\n<p>";}
if ($mydebugflag){print "errors=$errors\n<p>";}
if ( $ub eq '' && $rb eq '' && $lb eq '' && $ib eq '' && $db eq '' && 
     $wb eq '' && $cw eq '' && $ss eq '' && $ii eq '' && $mymy eq '' ) {
    $errors++;
}
if ($mydebugflag){print "errors=$errors\n<p>";}
#
#they must also enter some NON-BLANK TEXT
#if they dont dont let them continue
if ($formtext =~ /^[ \n\r]*$/ ) {
  $errors++;
}
if ($mydebugflag){print "errors=$errors\n<p>";}
#if ($errors > 0 ) {
if ($errors == 1 ) {
  if ($formtext =~ /^[ \n\r]*$/ ) {
    print "ERROR!!!! You MUST enter a News Article you idiot<p>";
  }
  if ( $ub eq '' && $rb eq '' && $lb eq '' && $ib eq '' && $db eq '' && 
       $wb eq '' && $cw eq '' && $ss eq '' && $ii eq '' && $mymy eq '' ) {
      print "ERROR!!!! You must check one of the boxes idiot<p>";
  }
  print "ERROR!!!! IDIOT!!!!<p>";
  exit;
}

$zdate=time();
if ($errors == 0 ) {
  #open(ALL,">>mod.txt");
  $bw=open(ALL,">>mod.txt");
  print "open bw=$bw<br>";
  #
  # (we still have to get the header data)
  # print the header data
  #
  #print ALL "AA <a name=\"$zdate\">\n";
  print ALL "HH header";
  if ($ub eq 'on') {print ALL " UB";}
  if ($rb eq 'on') {print ALL " RB";}
  if ($lb eq 'on') {print ALL " LB";}
  if ($ib eq 'on') {print ALL " IB";}
  if ($db eq 'on') {print ALL " DB";}
  if ($wb eq 'on') {print ALL " WB";}
  if ($cw eq 'on') {print ALL " CW";}
  if ($ss eq 'on') {print ALL " SS";}
  if ($ii eq 'on') {print ALL " II";}
  if ($mymy eq 'on') {print ALL " MY";}
  print ALL "\n";
  #
  # get and print each line
  #
  @x=split("\n",$formtext);
  for ($i=0;$i<=$#x;$i++) {
   $thisline=$x[$i];
   $bw=print ALL "DD $thisline\n";
   #
   # if $bw is != 1 the the write probably failed!!!!!
   #if ($bw != 1 ) {
   print "print bw=$bw<br>";
   if ($bw == 0 ) {
     print "\$bw=$bw!!! does this mean the write to ALL failed???<br>";
   }
  }
  close(ALL);
}
else {
  print "<h1>NOTHING SAVED TO DISK<\/h1>\n";
}
print "1) Ener Your News Article<br>";
print "2) Click Where you wish to save your news article";
#
#
# on june 28, 2006 I discovered that this program stopped working
# i suspect TRIPOD changed something in its include files.
# i changed the data from POST to GET and that appears to have fixed
# the problem. 
# but you can grab more data when you do it as post so i should
# change it back
#
#
# on sept 30, 2006 i changed it back to GET
#
print "<form action=\"mod.pl\" method=\"post\">";
#print "<form action=\"mod.pl\" >";

print "<input type=\"submit\" name=submit value=\"SUBMIT\">";


print "<table border=1>";
print "<tr>";
&start($ib,'ib','ib','1');
&start($ub,'ub','useless','2');
&start($rb,'rb','god','3');
&start($lb,'lb','putz','4');
&start($db,'db','libdis','5');
&start($wb,'wb','war','6');
&start($cw,'cw','cop','7');
&start($ss,'ss','secret service','8');
&start($mymy,'mymy','messy yards','9');
&start($ii,'ii','no stinking ID','10');
print "</tr>";
print "</table>";


#print "<select name=\"file\">";
#print "<option value=\"NEW\" $xnew >New News Articles";
#print "<option value=\"ALL\" $xall >ALL";
#print "<option value=\"WAR\" $xwar >Anti-War";
#print "<option value=\"LIB\" $xlib >Libertarian";
#print "<option value=\"ATH\" $xath >Atheist & Religion";
#print "<option value=\"GOV\" $xgov >Government Idiots & Rulers";
#print "<option value=\"SCI\" $xsci >Science";
#print "<option value=\"USE\" $xuse >Useless Information";
#print "<option value=\"SEX\" $xsex >Sylvia";
#print "<option value=\"NEW\" $xnew >New News Articles";
#print "<option value=\"EATH\" $mxath >Atheist E-Mail";
#print "<option value=\"ELIB\" $mxlib >Libertarian E-Mail";
#print "<option value=\"EGUN\" $mxgun >Gun E-Mail";
#print "<option value=\"ELS\" $mxls >List Servers E-Mail";
#print "<option value=\"ECOP\" $mxcop >COPWATCHERS E-Mail";
#print "<option value=\"EMEDIA\" $mxmed >MEDIA Contact E-Mail";
#print "</select>";




print "<br>";
print "<textarea name=\"text\" cols=\"50\" rows=\"20\">";
print "</textarea>";
print "<hr>";
print "<input type=\"reset\" name=reset value=\"CLEAR MENU\">";
print "<input type=\"hidden\" name=\"formname\" value=\"resume.form\">";
print "<input type=\"hidden\" name=\"title\" value=\"E-mail Resume\">";
print "<input type=\"hidden\" name=\"bcc\" value=\"\">";
print "<input type=\"hidden\" name=\"debugflag\" value=\"\">";
print "</form>";
print "NEWSPAPERS";
print "<ul>";
print "<li>Daily";
print "   <ul>";
print "<li><a href=\"http://www.azcentral.com\">http://www.azcentral.com</a>";
print "<li><a href=\"http://www.arizonarepublic.com\">http://www.arizonarepublic.com</a>";
print "<li><a href=\"http://www.arizonatribune.com\">http://www.arizonatribune.com</a>";
print "<li><a href=\"http://www.azstarnet.com\">http://www.azstarnet.com</a>";
print "<li><a href=\"http://www.tucsoncitizen.com\">http://www.tucsoncitizen.com</a>";
print "   </ul>";
print "<li>Weekly";
print "   <ul>";
print "<li><a href=\"http://www.phoenixnewtimes.com\">http://www.phoenixnewtimes.com</a>";
print "<li><a href=\"http://www.phoenixnewtimes.com\">http://www.phoenixnewtimes.com</a>";
print "<li><a href=\"http://www.tucsonweekly.com\">Tucson Weekly</a>";
print "   </ul>";
print "<li>POLITICAL Party Newspapers";
print "   <ul>";
print "<li><a href=\"http://www.pww.org\">http://www.pww.org</a> Communist Party";
print "   </ul>";

print "<li>Arab Newspapers";
print "   <ul>";
print "<li><a href=\"http://english.aljazeera.net\">http://english.aljazeera.net</a> Iraq war news";
print "   </ul>";






print "<li>COLLEGE Newspapers";
print "   <ul>";
print "<li><a href=\"http://www.statepress.com\">http://www.statepress.com</a> ASU";
print "<li><a href=\"http://www.mc.maricopa.edu/legend\">http://www.mc.maricopa.edu/legend MCC</a>";
print "<li><a href=\"http://wildcat.arizona.edu\">http://wildcat.arizona.edu</a> U of A";
print "   </ul>";
print "<li>SPANISH WEEKLYS";
print "   <ul>";
print '<li><a href="http://www.lavozinternet.com">http://www.lavozinternet.com</a> La Voz';
print '<li><a href="http://www.azcentral.com/lavoz">http://www.azcentral.com/lavoz</a> La Voz';
print '<li><a href="http://www.prensahispanaaz.com">http://www.prensahispanaaz.com</a> La Prensa';
print "   </ul>";
print "<li>FAKE News (Humor)";
print "   <ul>";
print '<li><a href="http://www.theonion.com">The Onion</a>';
print "   </ul>";
print "</ul>";
print "<p>Details and information";
print "<blockquote>";
print '<a name="1">1) Criminal acts and stupid stuff done by the Government<br>';
print '<a name="2">2) Useless Information<br>';
print '<a name="3">3) Stupid stuff done by people for God and in the name of religion<br>';
print '<a name="4">4) Stupid stuff done by those idiots Paul Putz and Linda Chapman<br>';
print '<a name="5">5) Libertarian Discussions and stuff from the Libertarian listservers<br>';
print '<a name="6">6) Stuff about the current war or current country the US government is invading in the name of freedom<br>';
print '<a name="7">7) Stuff to post on the C*pW*tch web site<br>';
print '<a name="8">8) Criminal acts committed by the Secret Service in the name of protecting the American Emperor<br>';
print '<a name="9">9) Crimes committed and homes seized by the messy yard cops from people who didn\'t mow their lawns or paint their coolers<br>';
print '<a name="10">10) No Stinking Id!!! Articles about how American is becoming a police state where you need ID to go to the bathroom<br>';
print "</blockquote>";
print ' <img src="../jpg_me.php">';
for ($i=0;$i<50;$i++){print '<p><br>';}
exit;





&display_form();
print "</html>\n";
exit;

sub display_form {
 print "<p><a name=\"#top\">\n";
 print "$title\n";
 &print_z_date;
 #print "<a href=\"#help\">Help on how this Web page works</a><p>";
 print "<p>";
 print "<form action=\"silver_resume_bccmail_felt.pl\">\n";
 #in form allow them to enter userid and password
 print "Userid: <input type=\"text\" size=\"60\" name=\"userid\" value=\"$userid\"><br>\n";
 print "Password: <input type=\"password\" size=\"60\" name=\"password\" value=\"$password\"><br>\n";
 print "Password2: <input type=\"password\" size=\"60\" name=\"checksum\" value=\"$checksum\"><br>\n";
 &dump_files;
 #print "From: <input type=\"text\" size=\"60\" name=\"frommail\" value=\"$frommail\"><br>\n";
 #print "Reply-To: <input type=\"text\" size=\"60\" name=\"replyto\" value=\"$replyto\">\n";
 print "<br>\n";
 print "Subject: <input type=\"text\" size=\"60\" name=\"subject\" value=\"$subject\">\n";
 print "<p>\n";
 print "<input type=\"submit\" name=submit value=\"SUBMIT\"> \n";
 print "<p>\n";
 #print "<textarea name=\"text\" cols=\"79\" rows=\"300\">\n";
 #print "$text";
 #print "</textarea>";
 print "<hr>\n";
 print "<p>\n";
 print "<input type=\"reset\" name=reset value=\"CLEAR MENU\">\n";
 print "<input type=\"hidden\" name=\"formname\" value=\"$formname\">\n";
 print "<input type=\"hidden\" name=\"title\" value=\"$title\">\n";
 print "<input type=\"hidden\" name=\"debugflag\" value=\"$debugflag\">\n";
 print "</form>\n";
 print "<p><a href=\"coronado.html\">help</a>\n";
 #print "<a name=\"help\">How to enter E-Mail address's and Peoples names<p>";
 #print "<p><a href=\"#top\">Jump to top of Page</a><p>";
 #print "<ol>";
 #print "<li>The From: e-mail address is required.";
 #print "<li>The e-mail will appear to be sent from the From: e-mail address.";
 #print "<li>Normally when a person replys to an e-mail the reply will be sent";
 #print " to the From: e-mail address. Thats unless a Reply-To: address is entered.";
 #print "<li>The Reply-To: e-mail address is not required.";
 #print "<li>If a Reply-To: e-mail address is given when a ";
 #print " person replys to the e-mail the reply will be sent to ";
 #print " the Reply-To: address instead of the From: address. ";
 #print " However not all e-mail software works this way. ";
 #print "<li>For both the From: and Reply-To: e-mail address you ";
 #print " may enter an email address that looks like this: ";
 #print " <blockquote> ";
 #print " lousy_aim\@aol.com ";
 #print " </blockquote> ";
 #print " <p> ";
 #print "<li>For both the From: and Reply-To: e-mail address you ";
 #print " may follow the email address with a human name thats ";
 #print " enclosed in (\"  \") like this: ";
 #print " <blockquote> ";
 #print " lousy_aim\@aol.com (\"Larry Naman\")";
 #print " </blockquote> ";
 #print " <p> ";
 #print "<li>The Subject: is required! ";
 #print "I'm not going to let you piss off";
 #print " people by sending an e-mail with out a subject. ";
 #print "</ol>";
 #print "<p>At the top of the page will be the title:<p> ";
 #print " <blockquote> ";
 #print "File to send Press Releases to<p>";
 #print " </blockquote> ";
 #print "followed by one or file names each which has a radio button.";
 #print "<a href=\"#stinking_file_list\"> Click here to jump to the list</a><p>";
 #print "The web site times out if it sends out more then 200 e-mails at a time.<p>";
 #print "To get around that problem all the e-mail addresses are split";
 #print " into files of of 200 or less e-mail addresses.<p>";
 #print "To send an e-mail to all of the addresses<p>";
 #print "<ol>";
 #print "<li>Click on the radio button of the first file ";
 #print "<li>Click on SUBMIT button to send the e-mail to the address in the first file ";
 #print "<li>Click on the radio button of the next file and repeat the ";
 #print " 1st 2 steps until you have sent e-mails to all files in the list ";
 #print "</ol>";
 #print "<p><a href=\"#top\">Jump to top of Page</a><p>";
 print "</html>";
 return;
}
 sub dump_files {
 print "<a name=\"stinking_file_list\">\n";
 #$mask="m/^".$file_prefix."\\.[0-9]+\\.email\$/";
 $mask=$file_prefix."\\.[0-9]+.*\\.email";
 print "<ul>\n";
 opendir(DIR,".");
 $nf=0;
 $checked=' checked ';
 while ($the_file_name=readdir(DIR)) {
   #if ($the_file_name =~ /^aitp\.[0-9]+\.email$/ ) {
   if ($the_file_name =~ $mask ) {
      print "<li>$the_file_name <input type=\"radio\" name=\"thefile\" value=\"$the_file_name\" $checked>\n";
      $nf++;
      $checked='';
   }
 }
 if ($nf == 0 ) {
    print "<p>Somethings screwed up!!!!!!!!!!<br>\n";
    print "ERROR!! No files exist that match '$file_prefix'<br>\n";
    print "ERROR!! Tell mike mask is '$mask'<p>\n";
 }
 closedir(DIR);
 print "</ul>\n";
 return;
}





sub print_z_date {
 @snot=localtime();
 $zstinkingdate=$snot[3];
 $zstinkingmonth=$snot[4]+1;
 $mud='';
 $zstinkingyear=$snot[5]-100;
 $zstinkingseconds=time;
 $zstinkingseconds/=3600;
 $zstinkingseconds=int($zstinkingseconds);
 if ( $zstinkingyear < 10 ) {
 $mud='0';
 }
 print "$zstinkingmonth/$zstinkingdate/$mud$zstinkingyear";
 print " $zstinkingseconds";
 #print " $snot[0],0 ";
 #print "$snot[1],1 ";
 #print "$snot[2],2 ";
 #print "$snot[3],3 ";
 #print "$snot[4],4 ";
 #print "$snot[5],5 ";
 #print "$snot[6],6 ";
 #print "$snot[7],7 ";
 return;
}




sub start {
 print "<td";
 if ($_[0] eq 'on' ) {
    print " style=\"background-color: rgb(255,255,0)\"";
 }
 print ">";
 print "$_[2]<sup><a href=#$_[3]>$_[3]</a></sup>";
 print "<br><input type=checkbox name=";
 print "$_[1]";
 print "></td>\n";
 return;
}

modify_php_ini.php

TOC

<html>
And these are the values that are in the php.ini file.
I used the function
<blockquote>
$ini_value=ini_get('value');
</blockquote>
to grab them on the fly.
<blockquote>
<table border=1 style="background-color:#00ffff">
<?php
$foo=array('smtp_port','SMTP','sendmail_from','sendmail_path');
foreach ($foo as $x) {
   $ini_value=ini_get($x);
   echo "<tr><td>$x</td><td>$ini_value</td><td>ini_get('$x')</td></tr>";
}
?>
</table>
</blockquote>
To modify the default values in the php.ini file
for this session  and this session only  use this function
<blockquote>
$ini_value=ini_set('sendmail_from','root@unix.com');
</blockquote>
Note, some of the value it won't let you modify.
Here are the results and it looks like the change of
the default from userid or 'sendmail_from' worked.
<blockquote>
<table border=1 style="background-color:#00ffff">
<?php
$ini_value=ini_set('sendmail_from','root@unix.com');
$foo=array('smtp_port','SMTP','sendmail_from','sendmail_path');
foreach ($foo as $x) {
   $ini_value=ini_get($x);
   echo "<tr><td>$x</td><td>$ini_value</td><td>ini_get('$x')</td></tr>";
}
?>
</table>
</blockquote>

../perl_lwp.pl

TOC

#!/usr/bin/perl
#
# define the functions 
#     mikes_fix_html()
#     html_to_dhtml()
# in the file
#     perl_use_code.pm
#
# note 1: you include the name WITHOUT the .pm
# note 2: the module must return a value ie: 1 in this case
#
# this web page has a good reference on writting this stuff
#   
#http://perl.apache.org/docs/general/perl_reference/perl_reference.html#use____require____do_____INC_and__INC_Explained
#
use perl_use_code;
#
# this URL has some nice info on the PERL LWP functions
#
#          http://www.perl.com/pub/a/2002/08/20/perlandlwp.html
#
require CGI;
use CGI;
$cgi = new CGI;
#
# so i can include modules in the current path
#
push @INC, '.';
#
# this program gets a URL 
# and fetches the data associated with that URL
# which is usually HTML data
# then it tokenizes the html so most of the 
# HTML tags are displayed at the begining the line
#
#
# get the url the person entered on the HTML form
#
my $url = '';
$url=$cgi->param('url');
#
# if the URL is null set some default value
#
if ($url =~ /^ *$/ ) {
  $url = 'http://miksup.100webspace.net';
}
#
# print the header stuff for a web page
#
print "Content-type: text/html", "\n\n";
print "<html>\n";
print "<body  link=\"blue\">";
print "<div style=\"background-color: #ffffff; color: rgb(0, 0, 0);\" id=\"tokyo\">";
#
# display the form to get the URL they want listed
#
print "<FORM action=\"perl_lwp.pl\" method=\"post\">";
print "<table><tr><td>URL:</td><td><INPUT name=\"url\" type=\"text\" size=\"160\"value=\"$url\"></td></tr>";
print "<tr><td>&nbsp;</td><td><INPUT type=\"submit\" value=\"ENTER\"></td></tr></table>";
print "</form>";
print "<p>";
#
# define the LWP stuff
#
use LWP::Simple;
#
# use LWP to read the URL from another remote web site
#
my $content = get $url;
#
# use die if the URL could not be defined
#
die "Couldn't get $url" unless defined $content;
#
# convert the RAW HTML to html we can display
#
$content_html=html_to_dhtml($content);
#
# to make it cleaner put a number of selected tags
#tags on at the begining of a line. so 
# a <p> tag is displayed as
#           <br>&lt;p&gt;
#
# it would have been simpler to call the function
#     $content_html=mikes_fix_html($content_html);
# but as an example on how to use the require function
# i did this. 
# also because we are requiring it the $content_html
# cant be defined with 'my $content_html'
#
require 'perl_lwp_edits.pl';
#
# display the RAW HTML
#
print "The HTML from web page<blockquote><a href=\"".$url,"\">$url</a></blockquote>";
print "<table width=\"100%\" style=\"color: rgb(0, 0, 0);\">";
print "<tr>";
print "<td width=\"10%\">";
print "&nbsp;";
print "</td>";
print "<td width=\"90%\">";
print "$content_html";
print "</td>";
print "</tr>";
print "</table>";
print "</div>";
#
# how display the actual HTML
# which depending on how they coded it
# may or may not look like the actual HTML
#
print "Now this web page is displayed as defined by its HTML<blockquote><a href=\"".$url,"\">$url</a></blockquote>";
print "$content";

../perl_lwp_edits.pl

TOC

#
# call mikes function which take certain html tags
# and puts a <BR> in front of them
# so they display at the begining of the line
# in real life i would have included this routine
# in line but just used it here as an example of 
# how to use the require function
#
# second note because this code is via a require()
# we cant pass it variable defined via my xxx;
# because it wont see them.
#
$content_html=mikes_fix_html($content_html);
#
# cool. return a 1 so the caller continues working
#
1;

../perl_sendmail.pl

TOC

#!/usr/bin/perl
print "Content-type: text/html", "\n\n";
print "<html>\n";
print "<body background=\"nevada.gif\">\n";
require CGI;
use CGI;
$cgi = new CGI;
#
# get the data they entered in the text bos
#
$formtext=$cgi->param('text');
$formfile=$cgi->param('file');
print "sending an e-mail with /usr/sbin/sendmail -t<p>";
$rc=open(SENDMAIL, "|/usr/sbin/sendmail -t") or die "Cannot open /usr/sbin/sendmail -t $!";
print "open rc=$rc<br>";
$rc=print SENDMAIL "TO: getlibdis\@yahoo.com\n";
print "print rc=$rc<br>";
$rc=print SENDMAIL "FROM: deadgoat\@hippydog.com\n";
print "print rc=$rc<br>";
$rc=print SENDMAIL "Subject: sending email with sendmail and PERL program perl_sendmail.pl\n";
print "print rc=$rc<br>";
$rc=print SENDMAIL "Content-type: text/plain\n\n";
print "print rc=$rc<br>";
$rc=print SENDMAIL "I used the perl program\nperl_sendmail.pl\nto send this email\n";
print "print rc=$rc<br>";
$rc=close(SENDMAIL);
print "close rc=$rc<br>";

../perl_test.pl

TOC

#!/usr/bin/perl
#$debug_flag=0;
#require TripodCGI;
#use CGI;
#$cgi = new CGI;
#
# get the digit to display
#
#$f=$cgi->param('f');
#$d=$cgi->param('d');
#if ($debug_flag) {
  print "Content-type: text/html", "\n\n";
  print "<html>\n";
  print "HI world!!!!!!";
  exit

../perl_test2.pl

TOC

#!/usr/bin/perl
require CGI;
use CGI;
$cgi = new CGI;
push @INC, '.';
#
# get the url the person entered on the HTML form
#
my $url = '';
$url=$cgi->param('url');
#
# if the URL is null set some default value
#
if ($url =~ /^ *$/ ) {
  $url = 'http://miksup.100webspace.net';
}
#
# print the header stuff for a web page
#
print "Content-type: text/html", "\n\n";
print "<html>\n";
print "<body  link=\"blue\">";
print "<div style=\"background-color: #ffffff; color: rgb(0, 0, 0);\" id=\"tokyo\">";
$content_html=foo();
print "RAW HTML<blockquote>$content_html</blockquote>";
fix_html($_); 
print "<p>EDITED HTML<blockquote>$content_html</blockquote>";
exit;

sub fix_html {
   my @tags=('html','/html','frame','/frameset','/frameset','noframes','/noframes','link','embed','p','/p','br','/br','li','ol','/ol','ul','/ul','hr','head','/head','title','center','/center','body','/body','script','/script','noscript','table','/table','th','tr','/tr','td','/td','div','/div','span','/span','form','/form','input','option','select','meta','a','h1','h2','h3','h4','img');
   foreach (@tags) {
      $content_html=~s/&lt;([\s]*)$_([ ]*)&gt;/<br>&lt;$1$_$2&gt;/gi;
   } 
   $content_html=~s/&lt;!--(\s)*/<br>&lt;!--$1/gi;
   return;
}




sub foo {
 my $content_html='<html><p><h1>xxx</h1><!-- stinking comment --><h2>fff</h2><script></script><              /html          >';
 $content_html=~s/&/&amp;/g;
 $content_html=~s/>/&gt;/g;
 $content_html=~s/</&lt;/g;
 return $content_html;
}

../perl_use_code.pm

TOC

#
# this web page has a good reference on writting this stuff
#
#    #http://perl.apache.org/docs/general/perl_reference/perl_reference.html#use____require____do_____INC_and__INC_Explained
#



sub html_to_dhtml {
   # 
   # convert raw html to displayable HTML
   # ie
   #     <h1>Title</h1>
   # becomes
   #     &lt;h1&gtTitle&lt;/h1&gt;
   #
   # get the argument passed to us 
   #
   my $content_html=$_[0];
   #
   # convert the RAW HTML to html we can display
   #
   # ie ">" is changed to "&gt;"
   # ie "<" is changed to "&lt;"
   # ie "&" is changed to "&amp;"
   #
   $content_html=~s/&/&amp;/g;
   $content_html=~s/</&lt;/g;
   $content_html=~s/>/&gt;/g;
   #
   # all done return the value
   #
   return $content_html;
}






#
# a function to put each of these html tags at the begining of a line
# ie: but a <br> tag in front of them
#
sub mikes_fix_html {
   my @mikes_tags=('html',
                   '/html',
                   'frame',
                   '/frameset',
                   '/frameset',
                   'noframes',
                   '/noframes',
                   'link',
                   'embed',
                   'p',
                   '/p',
                   'br',
                   '/br',
                   'li',
                   'ol',
                   '/ol',
                   'ul',
                   '/ul',
                   'hr',
                   'head',
                   '/head',
                   'title',
                   'center',
                   '/center',
                   'blockquote',
                   '/blockquote',
                   'body',
                   '/body',
                   'script',
                   '/script',
                   'noscript',
                   'table',
                   '/table',
                   'th',
                   'tr',
                   '/tr',
                   'td',
                   '/td',
                   'div',
                   '/div',
                   'span',
                   '/span',
                   'form',
                   '/form',
                   'input',
                   'option',
                   '/option',
                   'select',
                   '/select',
                   'meta',
                   'a',
                   'h1',
                   'h2',
                   'h3',
                   'h4',
                   'img'
                   );
   #
   # pick up the data that was passed to us
   #
   my $content_html=$_[0];
   #
   # loop thru each tag
   #
   foreach (@mikes_tags) {
      #
      # for each tag found put a <br> in front of the tag
      # note the tag has the format
      # 
      #    < whitespace tag whitespace
      #
      # and it is changed to
      #
      #     <br>< whitespace tag whitespace
      #
      $content_html=~s/&lt;([\s]*)$_([\s>]*)/<br>&lt;$1$_$2/gi;
   } 
   #
   # comments are handled differently
   #
   $content_html=~s/&lt;!--/<br>&lt;!--/gi;
   $content_html=~s/--&gt;/<br>--&gt;/gi;
   return $content_html;
}
1;

../phone.pl

TOC

#!/usr/bin/perl
print "Content-type: text/html", "\n\n";
print "<html>\n";
print "<body background=\"nevada.gif\">\n";
print "<h2 align=\"center\">Phone Spell</h1>\n";
#
#define stuff to grab data entered on form
#
require CGI;
use CGI;
$cgi = new CGI;
#
# get the email address they entered on the form
#
$fone=$cgi->param('fone');
$case=$cgi->param('case');
$numbers=$cgi->param('numbers');
if ($case eq "" || $case == 0) {
 $ucase="";
}
else {
 $ucase="CHECKED";
}
if ($numbers == 1) {
 $unumbers="checked";
}
else {
 $unumbers="";
}
#print "fone=$fone<br>\n";
$fone=~s/"//g;
#print "fone=$fone<br>\n";
print "<center>\n";
print "<form action=\"phone.pl\">";
print "<input type=\"text\" name=\"fone\" size=\"10\" value=\"$fone\"><br>";
print "<input type=\"submit\" name=submit value=\"Spell It\">";
print "<p>";
print "UPPER CASE <INPUT type=\"checkbox\" name=\"case\" value=\"1\" $ucase>";
print "NO Numbers <INPUT type=\"checkbox\" name=\"numbers\" value=\"1\" $unumbers>";

print "</form>";
print "</center>\n";
#if ( $#ARGV == -1 )
# {
#  print STDOUT "usage\n";
#  print STDOUT "$0 number1 [number2 number3 ...]\n";
#  print STDOUT "the program prints out all the spellings of the phone number entered\n";
#  print "usage\n";
#  print STDOUT "$0 4868\n";
#  print "$0 number1 [number2 number3 ...]\n";
#  print "the program prints out all the spellings of the phone number entered\n";
#  exit 1;
# }
#
# process each number passed to the command line
#
#for $_ (@ARGV)
if ($fone ne "" )
 {
  # print "processing stupid fone<br>\n";
  #$number=$_;
  $_=$fone;
  $number=$fone;
  # 
  # print the number we are spelling
  #
  #print "Number<br>  $number<br>\n";
  #
  #if the number contains any letters 
  #convert them to thecorrect digit
  #note Q - becomes 7
  #and  Z - becomes 9
  #and after converting delete anything
  #that is not a number
  #
  # convert output to uppercase
  #
  if ($case == 1 ) {
    print "<div style=\"text-transform: uppercase;\">";
  }

  if ( ! /^[0-9]+$/ )
   {
    print "<table border=\"1\" align=\"center\">\n";
    print "<tr><td>$number</td>\n";
    print "<td>  processed as  </td>\n";
    s/[abc]/2/gi;
    s/[def]/3/gi;
    s/[ghi]/4/gi;
    s/[jkl]/5/gi;
    s/[mno]/6/gi;
    s/[pqrs]/7/gi;
    s/[tuv]/8/gi;
    s/[wxyz]/9/gi;
    #
    #at this point all valid characters have
    #been converted to numbers
    #delete any characters that are left that
    #are not numbers
    s/[^0-9]//gi;
    #
    #tell them what we converted the number to
    #
    print "<td>$_</td></tr>\n";
    print "</table>\n";
   }
  #
  #so we can be lazy convert the number from a number like
  #                 5467
  #to a list of numbers delimited by commas
  #and then delete the last comma
  s/./$&,/g;        # 5467 - 5,4,6,7,
  s/,$//;           # 5,4,6,7, - 5,4,6,7
  #
  # convert the numbers into a list or an array
  # if we hardcoded it would look like this
  #     @nums=(5,4,6,7);
  #
  @nums=split(",");
  # 
  #call the phone speller program which is
  #named recur because it recursively calls it self
  #
  #   arg1 - this is the number like 7 which is to be converted
  #          to letters 7 -> p, r , s 
  #   arg2 - this is the digit number were processing
  #          0 is the 1st digit
  #          1 is the 2nd digit
  #          2 is the 3rd digit and so on
  #   arg3 - this is the number of digits in the phone number
  #          were processing minus one.
  #          C and perl programmers like to think in terms as
  #          relative to zero instead of relative to one
  #print "<br>calling &recur<br>";
  print "<tt>";
  &recur($nums[0],0,$#nums);
  #print "done &recur<br>";
  print "</tt>";
 }
else
 {
  #print "Enter a phone number you bozo!<p>";
 }
exit 0;
sub recur 
 { 
  #print "entering recur<br>";
  #
  # use my to make these variables dynamic.
  # if they are static the program will choke
  my $j=0;
  my $y;
  my $l;
  my $start=0;
  #
  # if the current digit is either zero or one
  #    only generate one set of letters for it
  #    because zero and one dont have any letters
  #    the only way they can be represented is as
  #    either 1 or 0
  #
  if ($_[0] <= 1 )
   {
    $start=2;
   }
  #
  #generate all 3 possible digits for this number
  #
  #for ($j=0;$j<3;$j++)
  #print "recur loop1<br>";
  for ($j=$start;$j<3;$j++)
   {
    #
    #call function getdigit to get the next digit
    #and stick it on the array
    #
    $array[$_[1]]=&getdigit($_[0],$j);
    #print ($_[1]," ",@array,"\n");
    if ($_[1] < $_[2])
     {
      #
      #recursive get the next numbers digit
      #
      $y=$_[1]+1;
      #print "calling recur recursivelly<br>";
      &recur($nums[$y],$y,$#nums);
     }
    else
     {
      #
      # after losts of work we have gotten the last digit of
      # this number print it.
      #
      #print "recur loop2<br>";
      for($l=0;$l<=$#array;$l++)
       {
        print "$array[$l]";
       }
      print "<br>\n";
      #
      # end the recursive calls only after the last digit is processed
      # these 3 lines are not required, but i have not bothered to
      # see if it reduces processing time.
      #
      if ($j == 2 )
       {
        #print "returning from recur<br>";
        return;
       }
     }
   }
 }

sub getdigit 
 {
  #this table defines what 
  #letters are associated with each number
  #some numbers dont have any letters like 0 and 1
  #
  my @table=((0,0,0),(1,1,1),
         ("a","b","c"),
         ("d","e","f"),
         ("g","h","i"),
         ("j","k","l"),
         ("m","n","o"),
         ("p","r","s"),
         ("t","u","v"),
         ("w","x","y")
        );
  my $num=$_[0];        # grab the telephone number
  my $sub=$_[1];        # get the offset letter number
                        # like for the number 2 if
                        # the offset is 0 - a is returned
                        #               1 - b is returned
                        #               2 - c is returned
  my $zsub;
  #
  #subscript must be 0 to 2 and not  1.4
  #
  if ($sub < 0 || $sub > 2 || $sub!~/^\d$/ || ! ($sub=~/^[0-9]$/ ))
   {
    #print STDERR "logic error getdigit needs subscript 0 to 2 we have \"$sub\"\n";
    print "logic error getdigit needs subscript 0 to 2 we have \"$sub\"\n";
    exit 1;
   }
  #
  # number must be 0 - 9
  # nada mas
  #
  if ($num < 0 || $num > 9 || ! ($num=~/^[0-9]$/ ))
   {
    #print STDERR "logic error getdigit needs telephone number 0 to 9 we have \"$num\"\n";
    print "logic error getdigit needs telephone number 0 to 9 we have \"$num\"\n";
    exit 1;
   }
   $zsub=($num*3)+$sub;
   #print ($num," ",$sub," ",($num*3)+$sub," ",$zsub," ",$table[$zsub],"\n");
   return $table[$zsub];
 }

phpinfo.php

TOC

<html>
phpinfo();
<p>
Lists info about the version of PHP I am using
<p>
And it looks like at the time I am writting this I have 
<p>
PHP Version 4.4.0
<p>
<?php
phpinfo();
?>
</html>

../picture_table_size.php

TOC

<html>
<?php 
   for ($i=1;$i<2000;$i++) {
?>
<table width="<?php 
   print $i;
?>px" border="1" cellspacing="0" cellpadding="0"><tr><td>
<?php 
   print "<img src=\"images_for_counters/black1x11.gif\" alt=\"this line is $i pixels wide\">";
?>
<?php 
   if ($i >= 30 ) {
      print $i;
   }
?></td></tr></table>
<?php 
   }
   #$zheight=50;
   #
   # ztweek is for the space on the right of the number
   #

   #
   # for a clear blackground set clear to something

   #$clear='';
   #$clear='xxx';

   #$ztweek=8;
   #for ($i=0;$i<10;$i++) {
   #   print "<img src=\"a_square_2p.php?text=$i&zheight=$zheight&ztweek=$ztweek&clear=$clear\"><br>";
   #}
?> 
</html>



../picture_table_size.php

TOC

<html>
<?php 
   for ($i=1;$i<2000;$i++) {
?>
<table width="<?php 
   print $i;
?>px" border="1" cellspacing="0" cellpadding="0"><tr><td>
<?php 
   print "<img src=\"images_for_counters/black1x11.gif\" alt=\"this line is $i pixels wide\">";
?>
<?php 
   if ($i >= 30 ) {
      print $i;
   }
?></td></tr></table>
<?php 
   }
   #$zheight=50;
   #
   # ztweek is for the space on the right of the number
   #

   #
   # for a clear blackground set clear to something

   #$clear='';
   #$clear='xxx';

   #$ztweek=8;
   #for ($i=0;$i<10;$i++) {
   #   print "<img src=\"a_square_2p.php?text=$i&zheight=$zheight&ztweek=$ztweek&clear=$clear\"><br>";
   #}
?> 
</html>



../picture_table_size_down.php

TOC

<html>
<table border="0" cellspacing="0" cellpadding="0">
<tr valign="top">
<td>




<?php 
   for ($i=1;$i<800;$i++) {
?>
<?php 
   #print $i;
   if ($i%10) {
      print "<img src=\"images_for_counters/black1x11.gif\" alt=\"im down $i pixels\"><br>";
   }
   else {
      for ($j=1;$j<10;$j++) {
         print "<img src=\"images_for_counters/black1x11.gif\" alt=\"im down $i pixels\">";
      }
      print "<br>";
   }
?>
<?php 
   }
?> 
</td>
</tr>
</table>
</html>



../picture_table_size_down.php

TOC

<html>
<table border="0" cellspacing="0" cellpadding="0">
<tr valign="top">
<td>




<?php 
   for ($i=1;$i<800;$i++) {
?>
<?php 
   #print $i;
   if ($i%10) {
      print "<img src=\"images_for_counters/black1x11.gif\" alt=\"im down $i pixels\"><br>";
   }
   else {
      for ($j=1;$j<10;$j++) {
         print "<img src=\"images_for_counters/black1x11.gif\" alt=\"im down $i pixels\">";
      }
      print "<br>";
   }
?>
<?php 
   }
?> 
</td>
</tr>
</table>
</html>



../pdf_adobe_pdf/program_name.php

TOC

<h1>PHP magic constants</h1>
<?php
    echo "PHP program name=".__FILE__."<br>";
    echo "PHP programname=".__FILE__."<br>";
    echo "PHP file name=".__FILE__."<br>";
    echo "PHP filename=".__FILE__."<p>";
?>
<h2>PHP program name</h2>
well to get the PHP file name the user clicked on use this code
<blockquote>
$filename=preg_replace('/.*\//',"",__FILE__);<br>
echo "file=$filename";
</blockquote>
And bingo the file name is displayed
<blockquote>
<?php
   $filename=preg_replace('/.*\//',"",__FILE__);
   echo "$filename<br>";
?>
</blockquote>
<h2>Path to PHP program name</h2>
To get the path to the PHP file name the user clicked on use this code
<blockquote>
   $filenamepath=preg_replace("/\/[^\/]*\$/","",__FILE__);<br>
   echo $filenamepath;
</blockquote>
And bingo the path to the filename is displayed
<blockquote>
<?php
   #
   # remove the PHP program name from the path name
   #
   $filenamepath=preg_replace("/\/[^\/]*\$/","",__FILE__);
   #
   # display the path to the php program or file name
   #
   echo "$filenamepath";
?>
</blockquote>
To get an array of the sub-directorys down to your 
program name use this PHP code
<blockquote>
</blockquote>
and this is the array you will get
<blockquote>
<?php
   #
   # create an array
   #
   $file_path=array();
   #
   # split the pathname and current php program name into its parts
   # delimited by the /
   #
   $file_path=explode("/",__FILE__);
   #
   # how many subdirectories to the program name
   # including the program name 
   #
   $paths_deep=count($file_path);
   #
   # display each subdirectory in the path name
   #
   echo "<ul>";
   foreach ($file_path as $f) {
      if ($f != '' ) {
      echo "<li>";
      echo $f;
      echo "<br>";
      }
   }
   echo "</ul>";
?>
</blockquote>
<h2>PHP function or subroutine name</h2>
To get the name of the PHP function your in use this code
<blockquote>
      $functionname=__FUNCTION__; <br>
      echo "this functions name is ".$functionname."()";<br>
      echo "this functions name is ";<br>
      echo __FUNCTION__."()";
</blockquote>
And when we run it the output looks like this
<blockquote>
<?php
   function foo() {
      #
      # get this functions name
      #
      $functionname=__FUNCTION__;
      #
      # one way to display this functions name
      #
      echo "this functions name is ".$functionname."()<br>";
      #
      # another way to display this functions name
      #
      echo "this functions name is ";
      echo __FUNCTION__."()";
      return;
   }
   #
   # display the functions name twice
   #
   foo();
?>
</blockquote>
<h2>PHP line number</h2>
To get the current line number of the PHP code use this
<blockquote>
<?php
    echo "PHP line number=".__LINE__."<br>";
    echo "PHP linenumber=".__LINE__;
?>
</blockquote>
<h2>PHP class and PHP method</h2>
And for object oriented stuff use these
<blockquote>
    echo "PHP name of class of object=".__CLASS__."";<br>
    echo "PHP name of object function=".__METHOD__;
</blockquote>
Here is the object stuff at work
<blockquote>
<?php
    echo "PHP name of class of object=".__CLASS__."<br>";
    echo "PHP name of object function=".__METHOD__;
?>
</blockquote>

protected_file.html

TOC

<html>
These FILES
<ul>
<li><a href="protected_file.html">protected_file.html</a>
<li><a href="protected_file.php">protected_file.php</a>
</ul>
are protected with .htaccess
<p>
This site
<blockquote>
<a href="http://www.tools.dynamicdrive.com/password">www.tools.dynamicdrive.com/password</a>
</blockquote>
generated this logic to protect them for me
<tt>
<blockquote>
AuthName "Restricted Area"<br> 
AuthType Basic <br>
<a href=".htpasswd">AuthUserFile /content/usrhome/050/miksup/www/miksup.100webspace.net/class/.htpasswd</a><br> 
AuthGroupFile /dev/null<br> 
&lt;Files protected_file.html&gt;<br>
require valid-user<br>
&lt;/Files&gt;<br>
&lt;Files protected_file.php&gt;<br>
require valid-user<br>
&lt;/Files&gt;
</blockquote>
</tt>
<p>
<hr>
<p>
For info on how to protect DIRECTORYS as opposed to files
see both of these
<ul>
<li><a href="htaccess_dir_needs_password/index.html">htaccess_dir_needs_password/</a> .htacl
<li><a href="htaccess_dir_needs_password2/index.html">htaccess_dir_needs_password2/</a> .htaccess
</ul>

protected_file.php

TOC

<html>
These FILES
<ul>
<li><a href="protected_file.html">protected_file.html</a>
<li><a href="protected_file.php">protected_file.php</a>
</ul>
are protected with .htaccess
<p>
This site
<blockquote>
<a href="http://www.tools.dynamicdrive.com/password">www.tools.dynamicdrive.com/password</a>
</blockquote>
generated this logic to protect them for me
<tt>
<blockquote>
AuthName "Restricted Area"<br> 
AuthType Basic <br>
<a href=".htpasswd">AuthUserFile /content/usrhome/050/miksup/www/miksup.100webspace.net/class/.htpasswd</a><br> 
AuthGroupFile /dev/null<br> 
&lt;Files protected_file.html&gt;<br>
require valid-user<br>
&lt;/Files&gt;<br>
&lt;Files protected_file.php&gt;<br>
require valid-user<br>
&lt;/Files&gt;
</blockquote>
</tt>
<p>
<hr>
<p>
For info on how to protect DIRECTORYS as opposed to files
see both of these
<ul>
<li><a href="htaccess_dir_needs_password/index.html">htaccess_dir_needs_password/</a> .htacl
<li><a href="htaccess_dir_needs_password2/index.html">htaccess_dir_needs_password2/</a> .htaccess
</ul>
<p>
<hr>
Do some PHP stuff
<p>
<?php
for($i=0;$i<100;$i++) {
   echo "$i ";
}
echo "<br>";
echo "that's it folks!!!!";
?>

refresh.html

TOC

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
   "http://www.w3.org/TR/html4/frameset.dtd">
<HTML>
<HEAD>
<!-- redisplay or refresh the display every n seconds -->
<meta  content="10;" http-equiv="refresh">
<TITLE>A simple frameset document</TITLE>
</HEAD>
<FRAMESET rows="25%, 25%, 25%, 25%">
   <FRAMESET cols="25%, 25%, 25%, 25%">

      <FRAME src="http://random_events.tripod.com/cgi-bin/random.pl" scrolling="no">
      <FRAME src="http://random_events.tripod.com/cgi-bin/random.pl" scrolling="no">
      <FRAME src="http://random_events.tripod.com/cgi-bin/random.pl" scrolling="no">
      <FRAME src="http://random_events.tripod.com/cgi-bin/random.pl" scrolling="no">
   </FRAMESET>
   <FRAMESET cols="25%, 25%, 25%, 25%">
      <FRAME src="http://random_events.tripod.com/cgi-bin/random.pl" scrolling="no">
      <FRAME src="http://random_events.tripod.com/cgi-bin/random.pl" scrolling="no">
      <FRAME src="http://random_events.tripod.com/cgi-bin/random.pl" scrolling="no">
      <FRAME src="http://random_events.tripod.com/cgi-bin/random.pl" scrolling="no">
   </FRAMESET>
   <FRAMESET cols="25%, 25%, 25%, 25%">
      <FRAME src="http://random_events.tripod.com/cgi-bin/random.pl" scrolling="no">
      <FRAME src="http://random_events.tripod.com/cgi-bin/random.pl" scrolling="no">
      <FRAME src="http://random_events.tripod.com/cgi-bin/random.pl" scrolling="no">
      <FRAME src="http://random_events.tripod.com/cgi-bin/random.pl" scrolling="no">
   </FRAMESET>
   <FRAMESET cols="25%, 25%, 25%, 25%">
      <FRAME src="http://random_events.tripod.com/cgi-bin/random.pl" scrolling="no">
      <FRAME src="http://random_events.tripod.com/cgi-bin/random.pl" scrolling="no">
      <FRAME src="http://random_events.tripod.com/cgi-bin/random.pl" scrolling="no">
      <FRAME src="http://random_events.tripod.com/cgi-bin/random.pl" scrolling="no">
   </FRAMESET>
<NOFRAMES>
      <P>This frameset document contains URL 16 times.
      <blockquote>
      <li><a src="http://random_events.tripod.com/cgi-bin/random.pl">http://random_events.tripod.com/cgi-bin/random.pl</a>
      </blockquote>
      Since the URL generates a random web page there should
      be up to 16 random web pages displayed
      <p>
      This is an example of how a you could have
      a web page to display different security
      cameras for a guard to monitor.
      <p>
      Since the web page is refreshed or redislayed
      every n seconds, the gaurd gets a new view of
      the cameras every n seconds.
      <p>
      to get really spiffy on the server side you could
      have the web page be blank and only display a 
      video image if an EVENT is detected.
      <p>
      that way the guard doesnt actually have to
      think each time the display is refreshed
      <P>
      ie: if the guard sees a BLANK screen he knows nothing is happening
      <p>
      but if the guard sees an IMAGE on the screen he knows
      somebody is trying to break into the facility
  </NOFRAMES>
</FRAMESET>
</HTML>

../curl_ftp_stuff/remove_sensitive_data.php

TOC

<?php
   #
   # this function just removes stuff i consider sensitive
   #
   function remove_sensitive_data($data, $remove, $replace) {
      $data=preg_replace("/$remove/",$replace,$data);
     return $data;
   }
?>

send_an_email.php

TOC

<?php


function dump_file_length_header($data) {
   #
   # this function is used to build the 
   #  Content-Length: nnn
   # header where nnn is the size of the file
   # note all of our files are encoded into
   # mime or base64 so the size will be larger
   # then the orginal file size
   #
   # the file has been read into memory
   # get the size of it
   #
   $bytes=strlen($data);
   #
   # build the content-length header
   #
   $length_header="Content-Length: $bytes\r\n";
   #
   # return to the caller
   #
   return $length_header;
}
function tell_em_about_attached_file($fname,$attachment,$name) {
   #
   # if the file name is not blank
   # this function generates a message
   # telling them
   #    1) file name
   #    2) is it an attachment or not YES/NO
   #    3) the name used
   #
   $message="";
   #
   # if the name is not blank do our stuff
   #
   if ($_FILES[$fname]['name'] != '') {
     #
     # assume it isn't an attachment
     #
     $isitanattachment="NO";
     if ($attachment == 'a') {
        #
        # well gosh it IS an attachment
        #
        $isitanattachment="YES";
     }
     #
     # build the message
     #
     $pc_name=$_FILES[$fname]['name'];
     $message="$pc_name, a=$isitanattachment n='$name'\n";
   }  
   #
   # return the message to the caller
   #
   return $message;
}
function build_tr_for_file($file) {
   if ($_FILES[$file]['name'] != "" ) {
      echo "<tr><td>Filename</td><td>{$_FILES[$file]['name']}</td></tr>";
      echo "<tr><td>File type</td><td>{$_FILES[$file]['type']}</td></tr>";
      echo "<tr><td>File size</td><td>{$_FILES[$file]['size']}</td></tr>";
      echo "<tr><td>File error</td><td>{$_FILES[$file]['error']}</td></tr>";
      echo "<tr><td>File on server</td><td>{$_FILES[$file]['tmp_name']}</td></tr>";
      echo "<tr><td colspan=\"2\">&nbsp;</td></tr>";
     }
   return;
}


function get_blank_lines($count) {
   #
   # i dont know how many blank lines i need
   # before and after the file so this function
   # will let me enter between 0 and 9 which
   # one of the values will work
   #
   for($i=0;$i<10;$i++) {
      $selected="";
      if ($i == $count) {
         $selected=" selected ";
      }
      echo "<option value=\"$i\" $selected>$i</option>";
   }
   return;
}

function tell_about_file_uploaded_to_us ($file) {
   # 
   # for debugging tell them some info about
   # the file they have uploaded
   #
   # blank the message
   #
   $status_messages="";
   #
   # if the file has been uploaded get the details
   #
   if ($_FILES[$file]['name'] != "" ) {
       #
       # tell them the files name
       #      
       $status_messages.=$_FILES[$file]['name'];
       $status_messages.=" contains ";
       #
       # tell them the files size in bytes
       #  
       $status_messages.=$_FILES[$file]['size'];
       #
       # tell them where the file was uploaded to
       # which is usually a randomly made name in
       #      /tmp
       #  
       $status_messages.=" bytes is attached to this email as ";
       $status_messages.=$_FILES[$file]['tmp_name'];
       $status_messages.=" with ";
       #
       # tell them how many errors the file had as it was uploaded
       # at least that is what i think this is.
       # I dont know for sure.
       #  
       $status_messages.=$_FILES[$file]['error'];
       $status_messages.=" errors\n";
   }
   #
   # return the message to the caller
   #
   return $status_messages;
}

function setup_call_to_attach_file ($zname, $attachment, $attachmentname, $cr_before, $cr_after, $dump_flength, $dont_use_imap) {
   #
   # make the output null
   #
   $header="";
   #
   # create an array to make a copy of the file info
   #
   $filex=array();
   #
   # if the file was entered then add it to the header info
   #
   if ($_FILES[$zname]['name'] != "" ) {
      #
      # copy the file array
      #
      $filex=$_FILES[$zname];
      #
      # get the files name
      #
      $filexname=$_FILES[$zname]['name'];
      #
      # put the files data to the header
      #
      $header=attach_a_file_to_headers($filex, 
                                        $attachment, 
                                        $attachmentname,
                                        $filexname,
                                        $cr_before,
                                        $cr_after,
                                        $dump_flength,
                                        $dont_use_imap);
        }
   #
   # all done return the data to the caller
   #
   return $header;
}



function attach_a_file_to_headers($file, $attachment, $name, $filename, $cr_before, $cr_after, $dump_flength, $dont_use_imap) {
   #
   # this function will build the header records
   # that are used to attach a file to an email
   # and send the file as an attachment
   #   $file       - the file array with file informaion
   #   $attachment - is this file going to be an attachment
   #               - as opposed to a file that will be say
   #               - an image in html displayed
   #   $name       - the name of this file, not the filename
   #               - this is the name used in an <a or <img tag
   #               - like   <img src="foo">
   #               - as opposed to the files name like
   #               - resume.doc which is part of the $file array
   #
   # zero out the data we want to return
   #
   $data="";
   #
   # debug the puppy
   #
   if (0) {
      echo "attachment=$attachment<br>";
      echo "attachment name=$name<br>";
      echo "file array=$file<br>"; 
      foreach ($file as $f) {
         echo "&nbsp;&nbsp;&nbsp;$f<br>";
      }
   }
   #
   # are we supposed to attache it as an  attachment
   # as opposed to an inline file which could be used
   # as an image when we display the email as HTML
   #
   if ( $attachment != '' ) {
      $data.="Content-Disposition: attachment;\r\n";
   }
   #
   # should we add the file name?
   #
   if ($filename != '') {
      $data.="filename=\"$filename\"\r\n";
   }
   #
   # add the content-type
   #  
   $data.="Content-type: ".$file['type'];
   #
   # if we have a "name" put it after the content type
   if ($name != '' ) {
      $data.=" name=\"$name\"";
   }
   #
   # either way put a \n at the end of the content-type
   #
   $data.="\r\n";
   #
   # tell it that the text that follows is mime or base64
   # which are two ways to say the same thing
   #






   #
   # read the file into memory
   #
   $file_data=file_get_contents($file['tmp_name']);
   #
   # convert the file data into mime text or base64 text
   # 
   #
   # for useless information this is how the file is encoded
   # see this URL for more info
   #   
   #         http://www.freesoft.org/CIE/RFC/1521/7.htm
   #
   #   Value Encoding  Value Encoding  Value Encoding  Value Encoding
   #        0 A            17 R            34 i            51 z
   #        1 B            18 S            35 j            52 0
   #        2 C            19 T            36 k            53 1
   #        3 D            20 U            37 l            54 2
   #        4 E            21 V            38 m            55 3
   #        5 F            22 W            39 n            56 4
   #        6 G            23 X            40 o            57 5
   #        7 H            24 Y            41 p            58 6
   #        8 I            25 Z            42 q            59 7
   #        9 J            26 a            43 r            60 8
   #       10 K            27 b            44 s            61 9
   #       11 L            28 c            45 t            62 +
   #       12 M            29 d            46 u            63 /
   #       13 N            30 e            47 v
   #       14 O            31 f            48 w         (pad) =
   #       15 P            32 g            49 x
   #       16 Q            33 h            50 y
   #
   # do the encoding
   #


   #$dont_use_imap
   if (! function_exists('imap_binary') || $dont_use_imap == 'y') {
      #
      # imap_binary() function does not exist
      # or we are testing and want to use my function
      # use my code to convert to mime or base64
      #
      if (! function_exists('imap_binary')) {
         echo "imap_binary() function does not exist<br>";
      }
      if ($dont_use_imap == 'y') {
         #echo "who cares about imap_binary() we ain't using it<br>";
      }
      #echo "using mikes IMAP function<br>";
      #
      # convert the string to a monster string
      # which is encoded in base64 or mime format
      #
      $base64data0=base64_encode($file_data);
      #
      # split it into lines that are 60 bytes long
      #
      $base64data=chunk_split($base64data0,60);
   }
   else {
      #
      # imap_binary function exists!
      # use it
      #
      #echo "imap_binary() function EXISTS<br>";
      $base64data=imap_binary($file_data);
   }







   #
   # dump the header that tells the length of the data
   # before the base64 header
   #
   if ( $dump_flength == 'before' ) {
      $data.=dump_file_length_header($base64data);
   }
   $data.="Content-transfer-encoding: base64\r\n";
   #
   # dump the header that tells the length of the data
   # after the base64 header
   #
   if ( $dump_flength == 'after' ) {
      $data.=dump_file_length_header($base64data);
   }
   #
   # should we add extra blank lines before the file?
   #
   if ($cr_before > 0 ) {
      $extra_blank_lines=0;
      while($extra_blank_lines < $cr_before) {
         $data.="\r\n";
         $extra_blank_lines++;
      }
   }
   #echo "like this<br>Content-Type: text/plain; charset=US-ASCII; name=mud<br>";
   #
   # add the mime or base64 data to the header
   #
   $data.=$base64data;
   #
   # should we add extra blank lines after the file?
   #
   if ($cr_after > 0 ) {
      $extra_blank_lines=0;
      while($extra_blank_lines < $cr_after) {
         $data.="\r\n";
         $extra_blank_lines++;
      }
   } 
   #
   # debug and dump the data
   #
   if (0) {
      echo "header=<pre>$data\"</pre>end header<p>";
   }
   #
   # return the data
   #
   return $data;
}
?>
<html>
<?php
#
# print our ip address
#
if (0) {
   echo "IP Address=";
   echo ${REMOTE_ADDR};
   echo "<p>";
}
#
# if we are at the lycos site print
# a few blank lines at the top to
# get around their annoying headers
#
#if (${REMOTE_ADDR} == '156.42.68.5' || ${REMOTE_ADDR} == '212.78.204.20') {
if (${REMOTE_ADDR} == '212.78.204.20') {
   for ($i=0;$i<3;$i++) {
      echo "&nbsp;<p>";
   }
}


?>
I moved the notes on MIME and multipart attachment to 
<a href="#mime_notes">here</a> at the bottom of the page.
<br>
This is the 
<a href="http://miksup.100webspace.net/class/display_send_an_email.php">source code</a> for this program.
<br>
You can go back to where you came from by
clicking
<a href=" 
<?php
#echo "{$_SERVER['HTTP_REFERER']}<br>";
#echo "{$HTTP_SERVER_VARS['HTTP_REFERER']}<br>";
echo $_ENV['HTTP_REFERER'];
?>
">here</a>
<p>
<?php
#
# include this function to clean up the
# data returned from PHP forms
# those annoying forms return
#    ", ', and \
# as
#    \",  \', and \\
#
#
# since i am giving this to grey DONT
# include the function. hard code it
#
#include "clean_php_form_data.php";
function clean_php_form_data($data) {
   #
   # for some reason when you enter the characters
   #     ", ', and \
   # into a PHP form they are returned as
   #     \", \', and \\
   #
   # well this function cleans up the data
   # and removes the annoying backslashes
   #
   # oddly data is NOT returned this way in PERL
   #
   $data=preg_replace('/\\\\\'/',"'",$data);
   $data=preg_replace('/\\\\\"/','"',$data);
   $data=preg_replace('/\\\\\\\\/',"\\",$data);
   return $data;
}
#
function sum_total_errors($data, $total_errors) {
   if ($data != '' ) {
      $total_errors++;
   }
   return $total_errors;
}
function clean_up_to_lines($data) {
    #
    # remove leading and trailing spaces
    #
    $data=preg_replace("/^ */","",$data);
    $data=preg_replace("/ *\$/","",$data);
    #
    # remove extra spaces
    #
    $data=preg_replace("/  */"," ",$data);
    #
    # remove leading and trail spaces from
    #       < frog@dog.com   >
    $data=preg_replace("/ *< */","<",$data);
    $data=preg_replace("/ *> */",">",$data); 
    #
    # remove leading and trail spaces from commas that
    # seperate email addresses
    #      frog@god.com     ,   me@superman.gov
    #
    $data=preg_replace("/ *, */",",",$data);
    return $data;
}
function get_address_errors($data) {
    $errors="";
    if ($data != '' ) {
       $names=explode(",",$data);
       foreach ($names as $n) {
          #
          # remove leading and trailing spaces
          #
          $n=preg_replace("/^ */","",$n);
          $n=preg_replace("/ *\$/","",$n);
          #
          # if you have
          #        tom jones <you@email.com>
          # we have to validate the stuff enclosed in <>
          # as the email address and ignore the other stuff
          # this code should do that
          #
          $nn=$n;
          if (preg_match("/<.*>/",$nn)) {
             $nn=preg_replace("/^.*</","",$nn);
             $nn=preg_replace("/>.*\$/","",$nn);  
          }
          #
          # now validate the email address
          # if the email address contains spaces
          # it is invalid
          #
          if (preg_match("/ /",$nn)) {
             if ($errors == '' ) {
                $errors=$n;
             }
             else {
                $errors.=" $n";
             }
          }
          else {
             #
             # if the email address is not in the form
             #     something@somewhere.xxx
             # it is invalid
             #
             if (! preg_match("/[^@]+@[^@]+\.[^@]+/",$nn)) {
                if ($errors == '' ) {
                   $errors=$n;
                }
                else {
                   $errors.=" $n";
                }
             }
             else {
                #
                # and it cant end or begin with
                # these letters
                # nor can it have @....@ in it
                # nor can it have .. or 2 dots next to each other
                #
                $nonos="\.@";
                if (preg_match("/^[$nonos]/",$nn)  || 
                    preg_match("/[$nonos]\$/",$nn) || 
                    preg_match("/\.\./",$nn) || 
                    preg_match("/@.*@/",$nn)) {
                   #
                   # we have either
                   #    illegal begining or ending characters
                   #    multiple @ signs
                   #
                   if ($errors == '' ) {
                      $errors=$n;
                   }
                   else {
                      $errors.=" $n";
                   }
                }
             }
          }
       }
    }
    #
    # if email addresses have stuff like
    #        tom & bob <thoseguyes@email.com>
    # convert it so it is displayable
    #
    $errors=htmlentities($errors);
    #
    # make it red and tell them it is an error
    if ($errors != '' ) {
    $errors="<span style=\"background=#ff0000\">ERROR $errors</span>";
    }
    return $errors;
}

   #
   # set the default values for this program
   #
   $total_errors=0;
   $size=80;
   $rows=10;
   #
   # the size of attachment names
   # used like
   #           <img src="attachment name">
   #
   $anamesize=10;
   #
   # grab the data the user typed into the HTML form
   #

   #
   # use this to figure out the first time we are called
   # so we can initialize stuff
   #
   $hidden_post_variable=$_POST['hidden_post_variable'];



   $from=$_POST['from'];
   $to=$_POST['to'];
   $cc=$_POST['cc'];
   $bcc=$_POST['bcc'];
   $rto=$_POST['rto'];
   $text=$_POST['text'];
   $cr_before=$_POST['cr_before'];
   $cr_after=$_POST['cr_after'];
   $subject=$_POST['subject'];
   $how_to_attach=$_POST['how_to_attach'];
   $send_as_html=$_POST['send_as_html'];
   $dump_header_in_debug_window=$_POST['dump_header_in_debug_window'];
   $dont_use_imap=$_POST['dont_use_imap'];
   $put_debug_info_in_email=$_POST['put_debug_info_in_email'];




   $dump_flength=$_POST['dump_flength'];
   #echo "\$dump_flength='$dump_flength'<br>";



   #
   # if first time set the date to current time
   #
   if ($hidden_post_variable == '' ) {
      #
      # get unix time ie: base January 1 1970 00:00:00 GMT
      #
      $ztime=time();
      #
      # convert to Phoenix time
      #
      $ztime-=(60*60*9);
      #
      # 1st time use date and time in Phoenix Arizona
      # the -9000 i think it says we are 9 hours
      # before London time.
      #
      $zdate=date("D, d M Y H:i:s -0900", $ztime);
      $zdate.=" (MST)";
      #
      # also set the flag to dump the 
      # debug info into the body of the email
      #
      $put_debug_info_in_email='y';
   }
   else {
      #
      # 2nd time use date they entered on form
      #
      $zdate=$_POST['zdate'];
   }

   $attachment1=$_POST['attachment1'];
   $attachmentname1=$_POST['attachmentname1'];
   $attachment2=$_POST['attachment2'];
   $attachmentname2=$_POST['attachmentname2'];
   $attachment3=$_POST['attachment3'];
   $attachmentname3=$_POST['attachmentname3'];
   $attachmentname2=$_POST['attachmentname2'];
   $attachment4=$_POST['attachment4'];
   $attachmentname4=$_POST['attachmentname4'];
   $attachment5=$_POST['attachment5'];
   $attachmentname5=$_POST['attachmentname5'];
   $attachment6=$_POST['attachment6'];
   $attachmentname6=$_POST['attachmentname6'];

   #
   # clean up the data returned from the form
   # ', ", and \ 
   # are returned as 
   # \', \" and \\
   #
   $text=clean_php_form_data($text);
   $from=clean_php_form_data($from);
   $to=clean_php_form_data($to);
   $cc=clean_php_form_data($cc);
   $bcc=clean_php_form_data($bcc);
   $rto=clean_php_form_data($rto);
   $subject=clean_php_form_data($subject);
   #
   # verify all the FROM: email addresses are valid
   #
   $from=clean_up_to_lines($from);
   $from_errors=get_address_errors($from);
   $total_errors=sum_total_errors($from_errors, $total_errors);
   #
   # verify all the TO: email addresses are valie
   #
   $to=clean_up_to_lines($to);
   $to_errors=get_address_errors($to);
   $total_errors=sum_total_errors($to_errors, $total_errors);
   #
   # a to field is required,
   # if other data was entered
   #
   if ( $from != '' || $cc != '' || $bcc != '' || $text != '' || $subject != '' ) {
      if ($to == '' ) {
         $total_errors++;
         $to_errors.=" a TO address is required";
      }
   }
   else {
      $total_errors=-1;
   }
   #
   # verify all the CC: email addresses are valid
   #
   $cc=clean_up_to_lines($cc);
   $cc_errors=get_address_errors($cc);
   $total_errors=sum_total_errors($cc_errors, $total_errors);
   #
   # verify all the BCC: email addresses are valid
   #
   $bcc=clean_up_to_lines($bcc);
   $bcc_errors=get_address_errors($bcc);
   $total_errors=sum_total_errors($bcc_errors, $total_errors);
   #
   # verify all the Reply To: email addresses are valid
   #
   $rto=clean_up_to_lines($rto);
   $rto_errors=get_address_errors($rto);
   $total_errors=sum_total_errors($rto_errors, $total_errors);
   #
   # if errors dont send the stinking email
   #
   if ($total_errors > 0 ) {
      echo "ERROR(s) E-MAIL NOT SENT!  total errors=$total_errors<br>";
   }

?>
<table style="background-color:#dddddd">
<tr valign="top">
<td>
<!-- form action="send_an_email.php" method="post" -->
<!-- make it a miltipart/form so we can upload files -->
<form action="send_an_email.php"  
      method="post" 
      enctype="multipart/form-data"> 
<input type="submit" name=submit value="Send">



     <input type="checkbox" name="dump_header_in_debug_window"  value="y"
     <?php if ($dump_header_in_debug_window == 'y'  ){echo "checked"; } ?>>
     <a href="#dump_headers">dump headers</a>



     <a href="#dump_length">dump length</a>
     <input type="radio" name="dump_flength"  value="after"
     <?php if ($dump_flength == 'after' || $dump_flength == '' ) {echo "checked"; } ?> > After
     <input type="radio" name="dump_flength"  value="before"
     <?php if ($dump_flength == 'before' ) {echo "checked"; } ?> > Before
     <input type="radio" name="dump_flength"  value="never"
     <?php if ($dump_flength == 'never') {echo "checked"; } ?> > Don't


     &nbsp;&nbsp;&nbsp; <a href="#use_base64_not_imap">use base64 not imap</a>
     <input type="checkbox" name="dont_use_imap"  value="y"
     <?php if ($dont_use_imap == 'y'  ){echo "checked"; } ?>>




<table>
<tr>
   <td align="right">From:</td>
   <td align="left"><input type="text" name="from"  
       <?php echo " size=\"$size\" value=\"$from\""; ?> >
       <?php echo "$from_errors"; ?>
   </td>
</tr>
<tr>
   <td align="right">To:</td>
   <td align="left"><input type="text" name="to"  
       <?php echo " size=\"$size\" value=\"$to\""; ?> >
       <?php echo "$to_errors"; ?>
   </td>
</tr>
<tr>
   <td align="right">CC:</td>
   <td align="left"><input type="text" name="cc"  
       <?php echo " size=\"$size\" value=\"$cc\""; ?> >
       <?php echo "$cc_errors"; ?>
   </td>
</tr>
<tr>
   <td align="right">BCC:</td>
   <td align="left"><input type="text" name="bcc"  
       <?php echo " size=\"$size\" value=\"$bcc\""; ?> >
       <?php echo "$bcc_errors"; ?>
   </td>
</tr>

<tr>
   <td align="right">Reply To:</td>
   <td align="left"><input type="text" name="rto"  
       <?php echo " size=\"$size\" value=\"$rto\""; ?> >
       <?php echo "$rto_errors"; ?>
   </td>
</tr>



<tr>
   <td align="right">
      <a href="#the_date_info">Date</a> :)
   </td>
   <td align="left"><input type="text" name="zdate"  
       <?php echo " size=\"$size\" value=\"$zdate\""; ?> >
   </td>
</tr>


<tr>
   <td align="right">Subject:</td>
   <td align="left"><input type="text" name="subject"  
       <?php echo " size=\"$size\" value=\"$subject\""; ?> >
   </td>
</tr>
<tr>
   <td align="right">&nbsp;</td>
   <td align="left">
        Send as TEXT
        <input type="radio" name="send_as_html"  value="text"
       <?php if ($send_as_html == 'text' || $send_as_html == '' ) {echo "checked"; } ?> >,
       <a href="#html_text">HTML</a>
        <input type="radio" name="send_as_html"  value="html"
       <?php if ($send_as_html == 'html' ) { echo "checked";}       ?> >



       &nbsp;&nbsp;&nbsp;<a href="#put_debug_info_in_e-mail">Put debug info in E-mail</a>
     <input type="checkbox" name="put_debug_info_in_email"  value="y"
     <?php if ($put_debug_info_in_email == 'y'  ){echo "checked"; } ?>>





   </td>
</tr>
<tr>
   <td align="right">&nbsp;</td>
   <td align="left">
        <input type="radio" name="how_to_attach"  value="before"
       <?php if ($how_to_attach == 'before'  ){echo "checked"; } ?>>
       <s>Attach <span style="background-color:pink;">BEFORE</span> screws up HTML</s>
       <a href="#notes_on_before_after"><sup>1</sup></a>
       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <a href="#before_file">\n before file</a>
                    <select name="cr_before">
                       <?php get_blank_lines($cr_before); ?>
                    </select>
<br>
       <input type="radio" name="how_to_attach"  value="after"
       <?php if ($how_to_attach == 'after' || $send_as_html == '') {echo "checked"; } ?> >
       Attach file <span style="background-color:pink;">
       after</span> HTML in header data section
       <a href="#notes_on_before_after"><sup>1</sup></a>
        &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; 
        <a href="#after_file">\n after file</a> &nbsp;&nbsp;
                    <select name="cr_after">
                       <?php get_blank_lines($cr_after); ?>
                    </select>
<br>
       <!-- take your choice! disabled or readonly will do     -->
       <!-- i lied disabled works much better                  -->
       <input disabled type="radio" name="how_to_attach"  value="body">
       <!-- input readonly type="radio" name="how_to_attach"  value="body" -->
       <s>Attach file to <span style="background-color:pink;">end of body</span>
       as opposed to the headers</s>
       <a href="#notes_on_before_after"><sup>1</sup></a>
   </td>
</tr>
<tr>
   <td align="right">&nbsp;</td>
   <td align="left">
        <table border=0>
        <tr>
        <td>
        <table border="1">
           <tr>
               <td>File Name</td>
               <td>
                   <a href="#as_attachment">as Attachment</a>
                   <br>vs INLINE
               </td>
               <td>
                  <a href="#inline_name">name</a>
                  <br>for INLINE
               </td>
           </tr>
           <tr>
              <td>
                 <input type="file" name="file_to_upload">
              </td>
              <td>
                 <input type="checkbox" name="attachment1"  value="a"
                 <?php if ($attachment1 == 'a'  ){echo "checked"; } ?>>
              </td>
              <td>
                 <input type="text" name="attachmentname1"  
                 <?php echo " size=\"$anamesize\" value=\"$attachmentname1\""; ?> >
              </td>
           </tr>


           <tr>
              <td>
                 <input type="file" name="file_to_upload2">
              </td>
              <td>
                 <input type="checkbox" name="attachment2"  value="a"
                 <?php if ($attachment2 == 'a'  ){echo "checked"; } ?>>
              </td>
              <td>
                 <input type="text" name="attachmentname2"  
                 <?php echo " size=\"$anamesize\" value=\"$attachmentname2\""; ?> >
              </td>
           </tr>

           <tr>
              <td>
                 <input type="file" name="file_to_upload3">
              </td>
              <td>
                 <input type="checkbox" name="attachment3"  value="a"
                 <?php if ($attachment3 == 'a'  ){echo "checked"; } ?>>
              </td>
              <td>
                 <input type="text" name="attachmentname3"  
                 <?php echo " size=\"$anamesize\" value=\"$attachmentname3\""; ?> >
              </td>
           </tr>

           <tr>
              <td>
                 <input type="file" name="file_to_upload4">
              </td>
              <td>
                 <input type="checkbox" name="attachment4"  value="a"
                 <?php if ($attachment4 == 'a'  ){echo "checked"; } ?>>
              </td>
              <td>
                 <input type="text" name="attachmentname4"  
                 <?php echo " size=\"$anamesize\" value=\"$attachmentname4\""; ?> >
              </td>
           </tr>



           <tr>
              <td>
                 <input type="file" name="file_to_upload5">
              </td>
              <td>
                 <input type="checkbox" name="attachment5"  value="a"
                 <?php if ($attachment5 == 'a'  ){echo "checked"; } ?>>
              </td>
              <td>
                 <input type="text" name="attachmentname5"  
                 <?php echo " size=\"$anamesize\" value=\"$attachmentname5\""; ?> >
              </td>
           </tr>
           <tr>
              <td>
                 <input type="file" name="file_to_upload6">
              </td>
              <td>
                 <input type="checkbox" name="attachment6"  value="a"
                 <?php if ($attachment6 == 'a'  ){echo "checked"; } ?>>
              </td>
              <td>
                 <input type="text" name="attachmentname6"  
                 <?php echo " size=\"$anamesize\" value=\"$attachmentname6\""; ?> >
              </td>
           </tr>

         </table>
         </td>
         <td valign="top">

              <!--
              <table border=1>
                 <tr>
                  <td>extra \n<br>before file</td>
                  <td>extra \n<br>after file</td>
                 </tr>
                 <tr>
                 <td>
                    <select name="cr_before">
                       <?php get_blank_lines($cr_before); ?>
                    </select>
                 </td>
                 <td>
                    <select name="cr_after">
                       <?php get_blank_lines($cr_after); ?>
                    </select>
                 </td>
                 </tr>
              </table>
              -->



         </td>
         </tr>
         </table>
   </td>
</tr>
<tr>
   <td colspan="2">
       <textarea name="text" 
       <?php echo "cols=\"$size\" rows=\"$rows\" "; ?>><?php echo "$text"; ?></textarea>  
   </td>
</tr>
</table>
<p>
<input type="hidden" name="hidden_post_variable" value="hidden post data">
<input type="reset" name=reset value="RESET">
</form>
</td>
<td style="background-color:#ffff00">
<h2>Debug Window</h2>
<?php
  #
  # dont send any email
  # we have errors
  #
  if ($total_errors != 0 ) {
      
  }
  else {
     #echo "sending email!!!!! Default from:<br>";
     #
     # play with some of the php.ini values
     # and see if we can get the mail to be sent 
     #
     #$ini_value=ini_set('sendmail_from',$from);
     #$ini_value=ini_set('SMTP','on');
     #$ini_value=ini_set('SMTP','ON');

     # i did this as a wild *ass guess
     # and it doesn't work at all
     # so never let it execute
     #
     if (0) {
        #
        # if we are supposed to attach the
        # file to the body do it here.
        # i suspect this wont work
        # because the existing email software
        # will think it is text that is part
        # of the body but I could be wrong
        #
        if ( $how_to_attach == 'body') {
           if ($_FILES['file_to_upload']['name'] != "" ) {
              echo "attaching file to BODY instead of headers<br>";
              #
              # set the length of the attached file
              #
              $text.="\r\n";
              $text.="Content-Length: ";
              $text.=$_FILES['file_to_upload']['size'];
              $text.="\r\n";
              #
              # tell it the type of the attached file
              #
              $text.="Content-type: ";
              $text.=$_FILES['file_to_upload']['type'];
              $text.="\r\n";
              #
              # add the data for the attached file
              # for some reason i think we may have
              # to convert the data to mime format
              # but i could be wrong
              #
              $text.=file_get_contents($_FILES['file_to_upload']['tmp_name']);
           }
        }
     }
     #
     # send mail with DEFAULT from:
     # which at greys site is
     #   anonymous@ hosting2.fastq.com
     #
     # this is the default on my server
     # which doesnt even send the mail
     #   me@localhost.com
     #
     # we know this works so stop sending the stinking email
     #
     if (0) {
        #
        # this works so stop sending the email
        # each time i test new stuff
        # 
        $rc=mail($to,$subject,$text);
     }
     #
     # modify the DEFAULT from to this $from
     # and send the email again
     #
     # again this works so stop sending the
     # email each time i test new stuff
     #
     if (0) {
        $ini_value=ini_set('sendmail_from',$from);
        echo "sending email!!!!! modified default from: $from<br>";
        $rc=mail($to,$subject,$text);
     }
     #
     # now build a header record to use as the from:
     # and send the email with it
     #
     #
     # save $text and later restore it
     #
     $oldtext=$text;
     $status_messages="";
     #
     # for debugging tell them if we generated a
     #     content-length 
     # header and if we did where we generated it
     #
     if ($dump_flength == 'before') {
       $status_messages.="Content-Length:xxx is BEFORE base64 header \n";
     }
     if ($dump_flength == 'after') {
       $status_messages.="Content-Length:xxx is AFTER base64 header \n";
     }
     if ($dump_flength == 'never') {
       $status_messages.="Content-Length:xxx NOT used\n";
     }
     #
     # for debugging tell them how many blank lines
     # we printed before and after the file
     #
     $status_messages.="$cr_before blank lines placed BEFORE file\n";
     $status_messages.="$cr_after blank lines placed AFTER file\n";
     #
     # tell them about the files they have uploaded
     # what the file name is, how it is attached and the use name
     #
     $status_messages.=tell_em_about_attached_file('file_to_upload',
                                                   $attachment1,
                                                   $attachmentname1);
     $status_messages.=tell_em_about_attached_file('file_to_upload2',
                                                   $attachment2,
                                                   $attachmentname2);
     $status_messages.=tell_em_about_attached_file('file_to_upload3',
                                                   $attachment3,
                                                   $attachmentname3);
     $status_messages.=tell_em_about_attached_file('file_to_upload4',
                                                   $attachment4,
                                                   $attachmentname4);
     $status_messages.=tell_em_about_attached_file('file_to_upload5',
                                                   $attachment5,
                                                   $attachmentname5);
     $status_messages.=tell_em_about_attached_file('file_to_upload6',
                                                   $attachment6,
                                                   $attachmentname6);
     #
     # for debugging tell them if the file was
     # attached before or after the HTML header
     #
     if ($how_to_attach == 'before') {
       $status_messages.="File attached before HTML\n";
     }
     if ($how_to_attach == 'after') {
       $status_messages.="File attached after HTML\n";
     }
     #
     # some PHP sites dont have the function
     #   imap_binary()
     # so this code is to tell us about that
     # and let us test the function either way
     #


     if ($dont_use_imap == 'y') {
       $status_messages.="Dont use imap_binary flag set to Y\n";
     }
     else {
       $status_messages.="Dont use imap_binary flag NOT set\n";
     }
     if (function_exists('imap_binary')) {
       $status_messages.="imap_binary() EXISTS\n";
     }
     else {
       $status_messages.="imap_binary() DOESNT exist\n";
     }





     #
     # never do this! the body stuff was 
     # a wild *ss guess that didnt work
     # 
     if (0) {
        if ($how_to_attach == 'body') {
          $status_messages.="File attached to body as opposed to headers\n";
        } 
     }
     #
     # for debugging for each file uploaded tell them
     #        filename, file size, unix filename, errors
     # this message is listed in the body of the email
     #
     $stinking_files_uploaded=0;
     $status_messagesx=tell_about_file_uploaded_to_us ('file_to_upload');
     if ($status_messagesx != '' ) {
        $stinking_files_uploaded++;
        $status_messages.=$status_messagesx;
     }
     $status_messagesx=tell_about_file_uploaded_to_us ('file_to_upload2');
     if ($status_messagesx != '' ) {
        $stinking_files_uploaded++;
        $status_messages.=$status_messagesx;
     }
     $status_messagesx=tell_about_file_uploaded_to_us ('file_to_upload3');
     if ($status_messagesx != '' ) {
        $stinking_files_uploaded++;
        $status_messages.=$status_messagesx;
     }
     $status_messagesx=tell_about_file_uploaded_to_us ('file_to_upload4');
     if ($status_messagesx != '' ) {
        $stinking_files_uploaded++;
        $status_messages.=$status_messagesx;
     }
     $status_messagesx=tell_about_file_uploaded_to_us ('file_to_upload5');
     if ($status_messagesx != '' ) {
        $stinking_files_uploaded++;
        $status_messages.=$status_messagesx;
     }
     $status_messagesx=tell_about_file_uploaded_to_us ('file_to_upload6');
     if ($status_messagesx != '' ) {
        $stinking_files_uploaded++;
        $status_messages.=$status_messagesx;
     }
     #
     # if no files were uploaded tell them
     #
     if ($stinking_files_uploaded == 0 ) {
        $status_messages.="No files attached to this email\n";
     }
     if ($send_as_html == 'html' ) {
       $status_messages.="Sending as HTML\n";
       $status_messages=preg_replace("/\n/","<br>\n",$status_messages);
     }
     else {
       $status_messages.="NOT sending as HTML\n";
     }


     #
     # if this variable is set to a y then
     # put the debug information into the
     # body of the email.
     # this way I can turn off the debugging
     # and use it to send homeland security 
     # messages to cartoonists like benson :)
     #
     if ($put_debug_info_in_email == 'y') {
        $text=$status_messages.$text;
     }
     $header="";
     #
     # build the from: header
     #
     if ($from != "" ) {
        $header.="From: $from\r\n";
        #echo "Sending with headers<blockquote><pre>";
        #echo "$header";
        #echo "</pre></blockquote>";  
     }
     #
     # build the CC: header
     #
     if ($cc != "" ) {
        $header.="CC: $cc\r\n";
        #echo "Sending with headers<blockquote><pre>";
        #echo "$header";
        #echo "</pre></blockquote>";
     }
     #
     # build the BCC: header
     #
     if ($bcc != "" ) {
        $header.="BCC: $bcc\r\n";
        #echo "Sending with headers<blockquote><pre>";
        #echo "$header";
        #echo "</pre></blockquote>";  
     }
     #
     # build the Reply To: header
     #
     if ($rto != "" ) {
        #
        # "reply to:" doesnt work
        # try using
        # "reply-to:"
        #
        if (0) {
           $header.="Reply To: $rto\r\n";
        }
        else {
           $header.="Reply-To: $rto\r\n";
        }
        #echo "Sending with headers<blockquote><pre>";
        #echo "$header";
        #echo "</pre></blockquote>";  
     }
     #
     # build the Date: header
     #
     if ($zdate != "" ) {
        $header.="Date: $zdate\r\n";
        #echo "Sending with headers<blockquote><pre>";
        #echo "$header";
        #echo "</pre></blockquote>";  
     }





     #we may have to flip the order we add the HTML and attached files
     # which is why i put the
     # if ($how_to_attach == "after" ) {
     # }
     # and
     # if ($how_to_attach == "before" ) {
     # }
     # logic
     #
     # i probably have to give the file i attach a name
     # look at my manuals for that. I remember they gave
     # a jpg file they used in an email in one example
     # a name
     #
     #
     # here we will first add the HTML header
     # then we will attach the file and its header
     # 
     # i am guessing the existing php mail software
     # will pull the first html header and use it
     # for the text in the body of the message
     # but i could be wrong on that
     #
     if ($how_to_attach == "after" ) {
        #
        # if we are sending it as HTML 
        # build the html header before the FILES
        #
        if ($send_as_html == 'html' ) {
           $header.="Content-type: text/html\r\n";
        }
        #
        # add the file they uploaded as an attachment to the e-mail
        #
        #echo "<p>make sure the header has been attached AFTER this<p>";
        #
        # add each file entered to the header information
        #
        $header.=setup_call_to_attach_file ('file_to_upload', $attachment1, $attachmentname1, $cr_before, $cr_after, $dump_flength, $dont_use_imap); 
        $header.=setup_call_to_attach_file ('file_to_upload2', $attachment2, $attachmentname2, $cr_before, $cr_after, $dump_flength, $dont_use_imap); 
        $header.=setup_call_to_attach_file ('file_to_upload3', $attachment3, $attachmentname3, $cr_before, $cr_after, $dump_flength, $dont_use_imap); 
        $header.=setup_call_to_attach_file ('file_to_upload4', $attachment4, $attachmentname4, $cr_before, $cr_after, $dump_flength, $dont_use_imap); 
        $header.=setup_call_to_attach_file ('file_to_upload5', $attachment5, $attachmentname5, $cr_before, $cr_after, $dump_flength, $dont_use_imap);
        $header.=setup_call_to_attach_file ('file_to_upload6', $attachment6, $attachmentname6, $cr_before, $cr_after, $dump_flength, $dont_use_imap); 



 
        

     }
     if ($how_to_attach == "before" ) {
        #
        # add the file they uploaded as an attachment to the e-mail
        #
        #echo "<p>make sure the header has been attached BEFORE this<p>";



        #
        # add each file entered to the header information
        #
        $header.=setup_call_to_attach_file ('file_to_upload', $attachment1, $attachmentname1, $cr_before, $cr_after, $dump_flength, $dont_use_imap); 
        $header.=setup_call_to_attach_file ('file_to_upload2', $attachment2, $attachmentname2, $cr_before, $cr_after, $dump_flength, $dont_use_imap); 
        $header.=setup_call_to_attach_file ('file_to_upload3', $attachment3, $attachmentname3, $cr_before, $cr_after, $dump_flength, $dont_use_imap); 
        $header.=setup_call_to_attach_file ('file_to_upload4', $attachment4, $attachmentname4, $cr_before, $cr_after, $dump_flength, $dont_use_imap); 
        $header.=setup_call_to_attach_file ('file_to_upload5', $attachment5, $attachmentname5, $cr_before, $cr_after, $dump_flength, $dont_use_imap);
        $header.=setup_call_to_attach_file ('file_to_upload6', $attachment6, $attachmentname6, $cr_before, $cr_after, $dump_flength, $dont_use_imap); 





        #if ($_FILES['file_to_upload']['name'] != "" ) {
        #   #
        #   # attach the first selected file to the header
        #   #
        #   $file1=array();
        #   $file1=$_FILES['file_to_upload'];
        #   $file1name=$_FILES['file_to_upload']['name'];
        #   $header.=attach_a_file_to_headers($file1, 
        #                                     $attachment1, 
        #                                     $attachmentname1,
        #                                     $file1name,
        #                                     $cr_before,
        #                                     $cr_after);
        #}
        #
        # if we are sending it as HTML 
        # build the html header after the FILES
        #
        if ($send_as_html == 'html' ) {
           $header.="Content-type: text/html\r\n";
        }
     }
     #
     # dump the headers ?
     #
     if ($dump_header_in_debug_window == 'y') {
        echo "<b>dumping headers</b>";
        echo "<pre>";
        echo $header;
        echo "</pre>";
     }
     #
     # only send the email ONCE and send it here
     # before I was sending it after I built
     # each and every header
     #
     echo "SENDING the E-MAIL now!<br>";
     $rc=mail($to,$subject,$text,$header);
     #
     # we have sent the email but
     # print some information in the debug window
     # about how we sent the email
     #
     echo "<table border=1>";
     $x=htmlentities($to);
     echo "<tr><td align=\"right\">To:</td><td>$x &nbsp;</td></tr>";
     $x=htmlentities($cc);
     echo "<tr><td align=\"right\">CC:</td><td>$x &nbsp;</td></tr>";
     $x=htmlentities($bcc);
     echo "<tr><td align=\"right\">BCC:</td><td>$x &nbsp;</td></tr>";
     $x=htmlentities($rto);
     echo "<tr><td align=\"right\">Reply To:</td><td>$x &nbsp;</td></tr>";
     $x=htmlentities($from);
     echo "<tr><td align=\"right\">From:</td><td>$x &nbsp;</td></tr>";



     #
     # list the data about each of the files
     # that were uploaded in table format
     # for debugging
     #
     build_tr_for_file('file_to_upload');
     build_tr_for_file('file_to_upload2');
     build_tr_for_file('file_to_upload3');
     build_tr_for_file('file_to_upload4');
     build_tr_for_file('file_to_upload5');
     build_tr_for_file('file_to_upload6');

     #if ($_FILES['file_to_upload']['name'] != "" ) {
     #   echo "<tr><td>Filename</td><td>{$_FILES['file_to_upload']['name']}</td></tr>";
     #   echo "<tr><td>File type</td><td>{$_FILES['file_to_upload']['type']}</td></tr>";
     #   echo "<tr><td>File size</td><td>{$_FILES['file_to_upload']['size']}</td></tr>";
     #   echo "<tr><td>File error</td><td>{$_FILES['file_to_upload']['error']}</td></tr>";
     #   echo "<tr><td>File on server</td><td>{$_FILES['file_to_upload']['tmp_name']}</td></tr>";
     #}


     $x=htmlentities($subject);
     echo "<tr><td align=\"right\">Subject:</td><td>$x &nbsp;</td></tr>";
     $x=$text;
     #
     # if they are sending it as text
     # convert the krud in the message
     # to html stuff so we can view
     # it in netscape
     # ie 
     #     > becomes &gt;
     #     < becomes &lt;
     #     .....
     #
     if ( $send_as_html == 'text' ) {
        $x=htmlentities($text);
        #
        # make the spaces display correctly with &nbsp;
        #
        $x=preg_replace("/ /","&nbsp;",$x);
        #
        # make line breaks display correctly with <br>
        #
        $x=preg_replace("/\n/","<br>",$x);
     }
     echo "<tr><td colspan=2>$x&nbsp;</td></tr>";
     echo "<tr><td align=\"right\">RC</td><td>$rc&nbsp;</td></tr>";

     if ($rc != 1 ) {
        echo "<tr><td colspan=\"2\">Hmmm... Something has changed. The rc used to be set to one</td></tr>";
     }
     echo "</table>";
  }   
?>
</td>
</tr>
</table>
<a name="php.ini.stuff">
<h2>PHP.INI stuff</h2>
These are the values I want:
<blockquote>
<table border=1 style="background-color:#00ffff">
<tr><td>SMTP </td><td> "localhost"</td><td> PHP_INI_ALL</td></tr>  
<tr><td>smtp_port</td><td> "25"</td><td> PHP_INI_ALL</td></tr>
<tr><td>sendmail_from</td><td> NULL</td><td> PHP_INI_ALL</td></tr>   
<tr><td>sendmail_path</td><td> "/usr/sbin/sendmail -t -i"</td><td> PHP_INI_SYSTEM</td></tr>   
</table>
</blockquote>
And these are the actual values that PHP returns
<blockquote>
<table border=1 style="background-color:#00ffff">
<?php
$foo=array('smtp_port','SMTP','sendmail_from','sendmail_path');
foreach ($foo as $x) {
   $ini_value=ini_get($x);
   echo "<tr><td>$x</td><td>$ini_value</td><td>ini_get('$x')</td></tr>";
}
?>
</table>
</blockquote>
Lets try to reset one of them using this code
<blockquote>
$ini_value=ini_set('sendmail_from','root@unix.com');
</blockquote>
and see what happens!
Here are the results and it looks like the change worked!
<blockquote>
<table border=1 style="background-color:#00ffff">
<?php
$ini_value=ini_set('sendmail_from','root@unix.com');
$foo=array('smtp_port','SMTP','sendmail_from','sendmail_path');
foreach ($foo as $x) {
   $ini_value=ini_get($x);
   echo "<tr><td>$x</td><td>$ini_value</td><td>ini_get('$x')</td></tr>";
}
?>
</table>
</blockquote>

<table width="100%" border="0">
<tr>
<td width="50%">
<a name="dump_headers">
<h3>Dump Headers</h3>
When you check the "dump headers" box
I write a whole bunch of debug information
to the right of the form in a box with
a yellow background.
<p>
You will see all the header and data
information I am passing to the
program that sends the e-mail.
<a name="dump_length">
<h3>dump length</h3>
When you click on the dump length button
for each file uploaded I will generate
a header record that has the length of the
uploaded file in bytes. That is the length
of the file after it has been converted to
mime. That header record looks like this
<blockquote>
Content-Length: 9672 
</blockquote>
And I am not sure how the software uses this.
At this point in time I am trying to avoid
writting the code using "multi-part forms"
because that gets a little messy and
I am hoping by allowing the length I
won't need to use "multi-part forms"
<p>
When I first heard the term 
"multi-part forms"
I thought the data was cut into
chunks and sent as multi-parts.
Well that may or may not be true
but it has absolutely nothing to
do with "multi-part forms".
<p>
A "multi-part form" is when you send several files
in one data stream and use unique string ID to
delimit the files.
<p>
And example is send three files using the string id
<blockquote>
frozen_frogs_drink_beer_and_smoke_cigarettes
</blockquote>
Would look like this:
<blockquote>
--frozen_frogs_drink_beer_and_smoke_cigarettes<br>
Data for file #1<br>
--frozen_frogs_drink_beer_and_smoke_cigarettes<br>
Data for file #2<br>
--frozen_frogs_drink_beer_and_smoke_cigarettes<br>
Data for file #3<br>
--frozen_frogs_drink_beer_and_smoke_cigarettes
</blockquote>
Only it seems that it is a little bit more
complex then that!




<a name="use_base64_not_imap">
<h3>use base64 not imap</h3>
The orginal code I wrote uses a function
<blockquote>
imap_binary()
</blockquote>
to convert the data from text to base64 or mime format.
Some versions of PHP don't have that functions
so the orginal program blows up when loaded on those
systems.
<p>
To get around that problem I check to see if the
function imap_binary() exists and if it doesn't
I use this code 
<blockquote>
$base64data0=base64_encode($file_data);<br>
$base64data=chunk_split($base64data0,60);
</blockquote>
to convert the data to mime or base64 format, 
then I split the data into 60 byte blocks.
<p>
So that I can test this code on a system that
has imap_binary() I put this check box so
I can force it to use the above code instead
of imap_binary().
<a name="the_date_info">
<h3>Date:</h3>
You can use this field to set the date the email was sent.
If you leave it blank I use the default time,
whatever that is.
You can put anything you want in it like:
<blockquote>
Yesterday<br>
Tomorrow<br>
December 25, 2029<br>
July 4, 1776
</blockquote>
The first time the program is run I will 
put the current Phoenix time in the field
with something like this
<blockquote>
Mon, 24 Dec 2007 11:37:20 -0900 (MST)
</blockquote>
In this case
<blockquote>
Mon - is the day of the week or Monday<br>
24 - is the day of the month or Dec 24<br>
Dec - is the month or December<br>
2007 - is the year<br>
11:37:20 - is the current time<br>
-0900 (MST) - says that Phoenix time is 9 hours before London time<br>
(MST) - says that Phoenix time is Mountain Standard Time
</blockquote>




<a name="put_debug_info_in_e-mail">
<h3>Put debug info in E-mail</h3>
OK it is Christmas time and all the cartoonists
are making fun of the homeland security thugs
and how they are going to shake down Santa Claus.
<p>
So for fun I sent a couple of cartoonists 
e-mails telling them how they are in trouble
with the TSA thugs for thinking they have
First Amendment rights.
<p>
This switch tells the software not to put
any of the debug information into the body
of the mail, so the e-mail will look like
a message from the government thugs in
the homeland security department. 
<p>
And just so the homeland security thugs
won't jail me for life, I used the non-existant
Department of Homeland IN-Security as the e-mail 
address
<a name="notes_on_before_after">
<h3>Notes on Before and After<sup>1</sup></h3>
<h4>No files attached</h4>
When you DON'T attach a file and send HTML
it seems to always work irregardless of
if you click on the before or after buttons.
<h4>One or more files attached</h4>
When one or more files are attached and you send HTML
it always works with the after button checked.
<p>
When one or more files are attached and you send HTML
the HTML is always screwed up when the before button checked.
<h4>Attach file to end of body</h4>
When the button that says
<blockquote>
Attach file to end of body 
</blockquote>
was clicked on and you attached files
and sent HTML it always seemed to  
screw stuff up.
<p>
That is why i disabled the button.
<h4>Attaching files still doesn't work</h4>
I still have to figure out how to attach files
so they are NOT in the body of the text,
but are attached as a file which you can click on
and down load.
<p>
I think that must be done using a multi-part form
header. But I still have to play with it.
<p>
The way the current code works is I just send the
file off using something like this
<blockquote>
<tt>
filename="resume.doc"<br>
Content-type: application/msword<br>
Content-transfer-encoding: base64<br>
Content-Length: 90298<br>
0 or more blank lines<br>
0M8R4KGxGu mime or base64 data AAAAAAAAAAAPgADAP7<br>
0 or more blank lines
</tt>
</blockquote>
<a name="before_file">
<h3>\n Before File</h3>
This is the number of blank lines
to print before dumping the file.
It is just for debugging.
I think I can get by with out
any blanks lines.
But there is a remote chance that
one blank line may be needed.
<a name="after_file">
<h3>\n After File</h3>
This is the number of blank lines
to print after dumping the file.
It is just for debugging.
I think I can get by with out
any blanks lines.
But there is a remote chance that
one blank line may be needed.
<a name="as_attachment">
<h3>As Attachment</h3>
I beleive there are two types of attachments you can have
when you send a file with an e-mail.
<p>
The first one is an attachment that the user
can download to his computer.
<p>
That is what you get when you click on one of
these buttons.
When you do this i generate the header record
<blockquote>
<nobr>Content-Disposition: attachment;</nobr>
</blockquote>
The 2nd type of attachment is for use when you
have the email displayed as HTML.
<p>
You could have an image attached to display in
the HTML, or another HTML web page for them
to jump to when they click on an A tag.
And this type of attachment is used for that.
<a name="inline_name">
<h3>Inline Name</h3>
In this case the NAME field is used to identify
the name of the image or other html to jump to.
<p>
In this case I add the name to the following header record
<blockquote>
<nobr>Content-type: image/pjpeg name="frogs"</nobr>
</blockquote>
In the above case I suspect that the name "frogs"
would be used in either an
<blockquote>
&lt;img src="frogs"&gt;
</blockquote>
tag or if the attached thing was html it would
be used in an A tag like this
<blockquote>
&lt;a href="frogs"&gt;&nbsp;&nbsp;&nbsp;&lt;/a&gt; 
</blockquote>
<h3>Uploaded file name</h3>
For each file you upload I generate a header record
that looks like this with the name of the uploaded
file. The name is the filename of the file
on the computer which it was uploaded from
<blockquote>
filename="222.jpg"
</blockquote>
I am not sure if this file name can be used
in the html tags.
Nor am I sure of what this file name can
be used for anywhere.
<h3>Uploaded file name on the remote server</h3>
When the file gets to the server it is usually
saved in 
<blockquote>
/tmp/xxx
</blockquote>
where xxx is a randomly generated file name
<a name="html_text">
<h3>TEXT HTML Radio buttons</h3>
If you click on the HTML radio button in
the two button radio set which is
TEXT and HTML
I will generate this header records
which says to send the e-mail as HTML
<blockquote>
Content-type: text/html
</blockquote>
I am not sure how the mail function uses it.
</td>
<td width="50%">
&nbsp;
</td>
</tr>
</table>
<h2>MIME notes</h2>
<a name="mime_notes">
<?php
#
# include my notes on mime and mulitpart attachments
#
include "notes_mime_attachment.php";
?>

../show_counter_images.php

TOC

<?
  function list_gif_and_jpg_files($the_directory) {
  #
  # path name to the file with the images
  #
  if ( $the_directory == '') {
     $the_directory='images_for_counters';
  }
  #
  # get an array to hold all the names of gif and jpg files
  #
  $dl = array();
  #
  # read the directory and get all the gif and jpg images
  #
  if ($hd = opendir($the_directory))
  {
    #
    # read each file name in the directory
    #
    while ($sz = readdir($hd)) {
       #
       # if the file is a jpg or gif file keep it
       # else skip the file
       # 
       if (preg_match("/[0-9]\.(gif|jpg)$/i",$sz)) { 
          $dl[] = $sz;
       }
    }
    #
    # close the directory. we are done reading it
    #
    closedir($hd);
    #
    # sort the file names
    #
    asort($dl);
    #
    # print out the images and image names
    # in a table
    #


    echo "<table border=1 style=\"background-image: url(images_for_counters/plaid.jpg)\">";
    foreach ($dl as $value) {
       $the_image=$the_directory."/".$value;
       #
       # a lot of the images are invisible images :)
       # well they are 1 pixel wide by 1 pixel tall
       # which is ALMOST invisible
       # if the lenght or width of the image is less then 10 pixels
       # display it as 10 pixels so we can see the image with out
       # going blind
       #
       list($width, $height, $type, $attr) = getimagesize($the_image);
       if ($width < 10) {
           $width=10;
       }
       if ($height < 10) {
           $height=10;
       }
       print "<tr valign=\"bottom\"><td><img src=\"$the_image\" width=$width height=$height></td><td>$value</td></tr>";
    }
    echo "</table>";
  }
 }
?>

../show_counter_images2.php

TOC

<?
 require('show_counter_images.php');
 list_gif_and_jpg_files('images_for_counters')
?>

../curl_ftp_stuff/simple_ftp_to_gnu.php

TOC

<?php
#
# in this script we dont login like we do in
#    ftp_to_gnu.php
# but we do get a list of the files in the 
# root directory
#
#
# initialize curl
#
$curl=curl_init();
#
# do a ftp to
#    ftp.gnu.org
#
curl_setopt($curl,CURLOPT_URL,"ftp://ftp.gnu.org");
#
# i think this says go get the data
#
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
#
# i think this says run all the stuff we just defined
# and place the data received in $result
#
$result=curl_exec($curl);
#
# close curl
#
curl_close($curl);
#
# print the data we got with the ftp to ftp.gnu.org
#
echo "<pre>";
print $result;
echo "</pre>";
#
# the first time i ran this the results looked like this
#
#     lrwxrwxrwx    1 0        0               8 Aug 20  2004 CRYPTO.README -> .message
#     -rw-r--r--    1 0        0           17864 Oct 23  2003 MISSING-FILES
#     -rw-r--r--    2 0        0            4178 Aug 13  2003 MISSING-FILES.README
#     -rw-r--r--    1 0        0            1765 Feb 20  2007 README
#     -rw-r--r--    1 0        0          405121 Oct 23  2003 before-2003-08-01.md5sums.asc
#     -rw-r--r--    1 0        0          145971 Jan 24 11:32 find.txt.gz
#     drwxrwxr-x  261 0        1003         8192 Jan 23 19:26 gnu
#     drwxrwxr-x    3 0        1003         4096 Sep 23  2004 gnu+linux-distros
#     -rw-r--r--    1 0        0              90 Feb 16  1993 lpf.README
#     -rw-r--r--    1 0        0          300599 Jan 24 11:32 ls-lrRt.txt.gz
#     drwxr-xr-x    3 0        0            4096 Apr 20  2005 mirrors
#     lrwxrwxrwx    1 0        0              11 Apr 15  2004 non-gnu -> gnu/non-gnu
#     drwxr-xr-x   43 0        0            4096 Jan 04 15:02 old-gnu
#     lrwxrwxrwx    1 0        0               1 Aug 05  2003 pub -> .
#     drwxr-xr-x    2 0        0            4096 Nov 08 17:46 savannah
#     drwxr-xr-x    2 0        0            4096 Aug 02  2003 third-party
#     -rw-r--r--    1 0        0             954 Aug 13  2003 welcome.msg
?>

sockets_kind_of.php

TOC

<?php
#
# get the function to convert raw html to printable html
#
include "html_to_displayable_html.php";
#
if ($set_cookie == '') {
   setcookie("disk1","hot SPICY socket",time()+333333);
   setcookie("diskfood","socket",time()+333333);
   setcookie("disk2","steelsocket",time()+333333);
}
$set_cookie="si";
#
# this session id stuff is for people who refuse to use cookies
# it keeps track of them on the server side instead of with
# cookies on their PC.
# the session lasts until they close their browser window
#
$mysessionid=session_start();
if ( $_SESSION['socketskindofx'] == '' ) {
   $_SESSION['socketskindofx']=1;
}
else {
   $_SESSION['socketskindofx']++;
}
?>
<h1>Playing with Sockets and Kinda Sockets</h1>
Here we will play with sockets and stuff that is kind of sort of like sockets!!!
Orginally I was going to do real sockets and fake sockets 
on the same web page but real sockets cover a lot of ground
so I split this into two parts, real and fake sockets.
<h1>Real Sockets</h1>
For some real sockets check <a href="sockets_real.php">this</a> out!
<h1>Kind of Sockets</h1>
Cool PHP lets you treat URLs as disk files and read them!
I am positive that the low level routines that handle
this logic when they see the "http://" they know they
have to use a socket to read the file on a remote computer
instead of do a disk read on the computer where this code
lives.
<p>
You can treat the URL www.sudoku.com as a disk file and read it!
Hmmm.... doesn't that sound like we are writing a socket?
Here are two ways
<blockquote>
$data=file_get_contents("http://www.sudoku.com");
<p>
&nbsp;&nbsp;&nbsp;&nbsp;or
<p>
$file=fopen("http://azcentral.com","r");<br>
$data=fread($file,20000000);<br>
fclose($file);
</blockquote>
<?php
#
# read the web page with file_get_contents();
#
$data=file_get_contents("http://www.sudoku.com");
#
# convert the HTML to html a human can read
#
$data=html_to_displayable_html($data);
#
#display the web page we read as HTML in a table
#
echo "<p>";
echo "the HTML from http://www.sudoku.com";
echo "<p>";
echo "<table border=\"10\">";
echo "<tr><td>";
echo $data;
echo "</td></tr>";
echo "</table>";
#
# now we will the the same thing a 2nd time
# but we will do it the hard way using the
# lower level functions that 
# file_get_contents() uses
#
$file=fopen("http://azcentral.com","r");
$data=fread($file,20000000);
fclose($file);
#
# convert the HTML to html a human can read
#
$data=html_to_displayable_html($data);
#
#display the web page we read as HTML in a table
#
echo "<p>";
echo "the HTML from http://azcentral.com";
echo "<p>";
echo "<table border=\"10\">";
echo "<tr><td>";
echo $data;
echo "</td></tr>";
echo "</table>";
?>

sockets_real_select.php

TOC

<?php

include "html_to_displayable_html.php";
include "dump_socket_header_data.php";
include "getsocketdataafterheaders.php";
include "save_krud.php";
include "get_socket_header_data.php";
include "get_header_content_type.php";

function get_html_with_line_breaks ($data) {
   #
   # convert the data to displayable html
   # every line will end in a <br>
   # as opposed to the other html routine
   # which just dumps the html as raw data
   #
   $dataout="";
   #
   # split out by lines
   #
   $dataheader=explode("\n", $data);
   #
   # process each line
   #
   foreach ($dataheader as $line) {
      #
      # convert stuff like '>' to '&gt;'
      #                    '&' to '&amp;'
      #
      $line=htmlentities($line);
      #
      # add the line break at the end
      #
      $line.="<br>";
      $dataout.=$line;
   }
   return $dataout;
}









function display_socket_binary ($data) {
   $flush_the_puppy=0;
   $dataheader=explode("\n", $data);
   foreach($dataheader as $theline) {
      #
      # skip over the header data
      #
      if ($theline == "\r") {
         break;
      }
   }
   #echo "<p>End of Headers! Binary Data follows<p>";
   #
   # delete the header information from the data
   #
   $gotendheaders=0;
   while($gotendofheaders==0) {
      #
      # the last header is a null line with 
      # have we found it yet?
      #
      if (substr($data,0,4) == "\r\n\r\n" ) {
         #
         # delete last part of the headers
         # which is 4 bytes and we are done!
         #
         $data=substr($data,4);
         $gotendofheaders=1;
      }
      else {
         #
         # delete the 1st byte till we get to end of header
         #
         $data=substr($data,1);
      }  
   }
   #
   # convert unprintable binary data to a "."
   #
   #$data=preg_replace("/[\\x00-\\x1f]/",".",$data);
   #$data=preg_replace("/[\\x7f-\\xff]/",".",$data); 
   #
   # now dump the data out in a bunch of 1 line chunks $linelen long
   $linelen=64;
   echo "<table>";
   while($data != '' ) {
      $line=substr($data,0,$linelen);
      $linehex=$line;
      #
      # convert unprintable binary to a '.'
      #
      $line=preg_replace("/[\\x00-\\x1f]/",".",$line);
      $line=preg_replace("/[\\x7f-\\xff]/",".",$line); 
      #
      # convert < > and & to their html values so they dont mess us up
      #
      $line=preg_replace("/&/","&amp;",$line); 
      $line=preg_replace("/</","&lt;",$line); 
      $line=preg_replace("/>/","&gt;",$line);
      $line=preg_replace("/ /","&nbsp;",$line); 
      #
      # how get the hex of the binary data
      #
      $hexout="";
      #for($i=0;$i<$linelen;$i++) {
      for($i=0;$i<strlen($linehex);$i++) {
         $c=substr($linehex,$i,1);
         $cc=ord($c);
         #
         # it blows up with a 54 error if i dont put the next line there
         #
         $hexout.=' ';
         $hexout.=sprintf("%02x",$cc);
      } 
      #$hexout=preg_replace("/ /","",$hexout); 
      echo "<tr><td><tt>$line</tt></td><td><tt><nobr>$hexout</nobr></tt></td></tr>";
      $data=substr($data,$linelen);
      $flush_the_puppy++;
      if ($flush_the_puppy == 100 ) {
         flush();
      }
   }
   echo "</table>";


   #
   # html stuff
   #
   #$data=preg_replace("/[<>]/",".",$data); 
   #echo "$data";
   return;
}



















function delete_to_this_text ($data, $text) {
   #
   # delete till we find this word 
   # in either upper case or lower case
   # we use this to search for a specific html tag
   # ie
   #       <img
   #       <a
   #
   $textlength=strlen($text);
   $got_text=0;
   while($got_text==0) {
      #
      # PHP doesn't user lc() or lower() instead it uses strtolower()
      #
      # have we found the word?
      # the word can be either UPPERCASE or lowercase
      #
      if (strtolower(substr($data,0,$textlength)) == strtolower($text) ) {
         #
         # the begining of the string matches the text
         # whoppie we are DONE!!!!
         #
         $got_text=1;
      }
      else {
         #
         # delete the 1st byte till we find the word
         #
         $data=substr($data,1);
      }  
   }
   return $data;
}








#
# function to
#        list all <a> tags
#        list all <img> tags
#
function dump_the_stinking_socket ($sitename) {
   echo "<table>";
   echo "<tr valign=\"top\">";
   echo "<td>";
   echo "Processing $sitename<br>";
   $site=$sitename;
   $url=$sitename;
   #
   # remove the leading http:// or https://
   #  
   $site=preg_replace("/^http[s]?:\/\//i","",$site);
   #
   # on the site remove everything after the /
   #
   $site=preg_replace("/\/.*\$/","",$site);
   #
   # this URL1 and URL2 stuff allows them to
   # do a whois on both their URL and their IP address
   #
   $url1="<a href=\"whois_this_url.php?stinkingserver=$site\">$site</a>";
   echo "Site=<span style=\"background-color:#ffff00\">$url1</span><br>";
   echo "URL=$url<br>";
   echo "</td>";
   echo "<td>";
   echo "<table border=\"1\" style=\"background-color:#ffff00\">";
   echo "<tr><td colspan=\"3\">Click to view who owns the IP address or URL</td></tr>";
   echo "<tr><td>&nbsp;</td><td>IP Address</td><td>IP Name</td></tr>";
   #
   # get the sites IP address 
   #
   $their_ip_address = gethostbyname ($site); 
   $their_name = gethostbyaddr($their_ip_address);
   $url1="<a href=\"whois_this_url.php?stinkingserver=$their_ip_address\">$their_ip_address</a>";
   $url2="<a href=\"whois_this_url.php?stinkingserver=$their_name\">$their_name</a>";
   echo "<tr><td>URL IP</td><td>$url1</td><td>$url2</td></tr>";
   #
   # get our IP address, ie: THIS servers IP address
   # get our IP name also
   #
   $my_ip_address=getenv('SERVER_ADDR');
   $their_name = gethostbyaddr($my_ip_address);
   $url1="<a href=\"whois_this_url.php?stinkingserver=$my_ip_address\">$my_ip_address</a>";
   $url2="<a href=\"whois_this_url.php?stinkingserver=$their_name\">$their_name</a>";
   echo "<tr><td>Program IP</td><td>$url1</td> <td>$url2</td> </tr>";
   $your_ip_address=getenv('REMOTE_ADDR');
   #
   # get their IP address
   # get their IP name also
   #
   $their_name = gethostbyaddr($your_ip_address);
   $url1="<a href=\"whois_this_url.php?stinkingserver=$your_ip_address\">$your_ip_address</a>";
   $url2="<a href=\"whois_this_url.php?stinkingserver=$their_name\">$their_name</a>";
   #echo "<tr><td>Your IP</td><td> $your_ip_address</td><td>$their_name</td></tr>";
   echo "<tr><td>Your IP</td><td>$url1</td><td>$url2</td></tr>";
   echo "</table>";
   echo "</td>";
   echo "</tr>";
   echo "</table>";

  



   $port=80;
   $fp=@fsockopen($site, $port);
   if ($fp) {
      $data="";
      fwrite($fp, "GET $url HTTP/1.1\r\nHOST: $site\r\n\r\n");
      while(!feof($fp)) {
         $data.=fread($fp, 100);
      }
      fclose($fp);
      #
      # get the header data into an array
      #
      $header_array=get_socket_header_data($data);
      echo "<h2>Header ARRAY</h2>";
      echo "<blockquote>";
      foreach($header_array as $theline) {
         #
         # convert to displayable html
         #
         $theline=htmlentities($theline);
         #
         # display the puppy
         #
         echo "$theline<br>";
      }
      echo "</blockquote>";
     
      #
      # now figure out what type of data it is
      #
      $content_type=get_header_content_type($header_array);
      echo "<h2>Content-Type:</h2>";
      echo "<blockquote>";
      foreach($content_type as $line) {
         echo "$line<br>";
      }
      echo "</blockquote>";
      #
      # if it is an audio file play the puppy!
      #
      if ($content_type[1] == 'audio') {
         echo "<h2>Its an audio file</h2>";
         echo "<blockquote>";
         echo "play the sounds!!!!";
         #
         # dont use the stupid microsnot method
         # but do play the sounds
         # dont display a stupid control window
         # to let them control the sounds
         #
         #echo "<BGSOUND SRC=\"$sitename\" LOOP=\"INFINITE\">";
         echo "<EMBED SRC=\"$sitename\" AUTOSTART=\"TRUE\" 
                                        HIDDEN=\"true\" 
                                        LOOP=\"TRUE\">";
         echo "</blockquote>";
      } 
      #
      # if it is an video file show the stinking movie
      #
      if ($content_type[1] == 'video') {
         echo "<h2>Its a VIDEO file</h2>";
         echo "<blockquote>";
         #
         # put a window to play the video or show the movie
         # they will have some controls so they can start and stop it
         #
         echo "<EMBED SRC=\"$sitename\" AUTOSTART=\"TRUE\" 
                                        HIDDEN=\"false\" 
                                        LOOP=\"TRUE\">";
         echo "</blockquote>";
      } 
      #
      # if it is an image display the images
      #
      if ($content_type[1] == 'image') {
         echo "<h2>Here is a copy of the image</h2>";
         echo "<blockquote>";
         echo "<img SRC=\"$sitename\">";
         echo "</blockquote>";
      } 



      #
      # convert the data read from the socket to HTML
      # and display it
      #
      #echo $data;
      #
      # dump the header data
      #
      echo "<h2>Socket Header Records</h2>";
      echo "<blockquote>";
      dump_socket_header_data($data);
      echo "</blockquote>";
      #
      # dump the <a> and <img> tags if the data is text/html or text/xml
      #
      if ($content_type[0] == 'text/html' ||
          $content_type[0] == 'text/xml' ) {   
         #
         # dump only the <a> tags
         # for future robot use :)
         #
         $therawhtml=get_socket_data_after_headers($data);
         #
         # remove all the html tags execpt <a> tags
         #
         $therawhtml=strip_tags($therawhtml,"<a>"); 
         #save_krud($therawhtml);
         #
         # now try to remove all the data execpt for the raw <a tags
         #
         $therawhtml=delete_to_this_text ($therawhtml, "<a");
         $therawhtml=preg_replace("/^[^<]*<a /im","<a ",$therawhtml);  
         $therawhtml=preg_replace("/<\/a>/im"," ",$therawhtml);     
         #
         # remove the stuff at the end
         #
         $therawhtml=preg_replace("/>[^<>]*\$/im",">",$therawhtml);    
         # 
         $therawhtml=preg_replace("/>[^<>]*</im","><",$therawhtml); 
         $therawhtml=html_to_displayable_html($therawhtml);
         #
         # put a <br> at the end of each <a> tag
         #
         $therawhtml=preg_replace("/&gt;/im","&gt;<br>",$therawhtml);  
         echo "<h2>dump &lt;a&gt; tags</h2>";
         echo "<blockquote>";
         echo $therawhtml;
         echo "</blockquote>";
         # dump only the <img> tags
         # for future robot use :)
         #
         $therawhtml=get_socket_data_after_headers($data);
         #
         # remove all the html tags execpt <img> tags
         #
         $therawhtml=strip_tags($therawhtml,"<img>");   
         #save_krud($therawhtml);
         #
         # now try to remove everything BUT the <img> tags
         #
         $therawhtml=delete_to_this_text ($therawhtml, "<img");
         $therawhtml=preg_replace("/^[^<>]*</im","<",$therawhtml); 
         $therawhtml=preg_replace("/>[^<>]*\$/im",">",$therawhtml);
         #
         # for testing display the actual images we found
         #
         if (1) {
            echo "<h2>dump &lt;img&gt; tags Check out the photos mom!</h2>";
            echo "<blockquote>";
            $therawhtml2=$therawhtml;
            #
            # put a <br> tag before each image
            # 
            $therawhtml2=preg_replace("/>/im","><br>",$therawhtml2);
            #
            # remove the 
            #                align="right"
            #                align="left"
            #                align="top"
            #                align="bottom"
            # stuff
            $therawhtml2=preg_replace("/align=\"left\"/im","",$therawhtml2);
            $therawhtml2=preg_replace("/align=\"right\"/im","",$therawhtml2);
            $therawhtml2=preg_replace("/align=\"top\"/im","",$therawhtml2);
            $therawhtml2=preg_replace("/align=\"bottom\"/im","",$therawhtml2);
            $therawhtml2=preg_replace("/style=\"[^\"]*\"/im","",$therawhtml2);
            echo $therawhtml2;
            echo "</blockquote>";
            echo "<p>";
         }
         $therawhtml=html_to_displayable_html($therawhtml);
         #
         # put a <br> at the end of each <img> tag
         #
         $therawhtml=preg_replace("/&gt;/im","&gt;<br>",$therawhtml); 
         echo "<h2>dump &lt;img&gt; tags</h2>";
         echo "<blockquote>";
         echo $therawhtml;
         echo "</blockquote>";
      }
      #
      # now decide how to dump the data
      # should we dump it as binary data
      # or dump it as text data
      $dump_data_format="";
      #
      # do some specific tests
      #
      switch ($content_type[0]) {
         #
         # i think rtf contains binary
         # does it?
         #
         case 'text/rtf': $dump_data_format="binary";
                          break;

      }
      if ($dump_data_format == "" ) {
         switch ($content_type[1]) {
         #
         # i think rtf contains binary
         # does it?
         #
            case 'text': $dump_data_format="ascii";
                             break;
            default: $dump_data_format="binary";
                             break;

         }
      }  
      #
      # get the raw html or other data after the header
      # if it is an image or wordfile it could will
      # if its html dump it!
      #
      $therawhtml=get_socket_data_after_headers($data);
      #
      # convert the raw data to html that can be displayed
      # a <br> is added to each line
      #
      $therawhtml_line=get_html_with_line_breaks ($therawhtml);
      #$therawhtml=html_to_displayable_html($therawhtml);
      #
      # now dump the text as either binary or ascii
      #
      echo "<h2>Dumping the data in $dump_data_format</h2>";
      echo "<blockquote>";
      if ( $dump_data_format == "ascii" ) {
         #
         # print it out in ascii
         # we have to change all the html code
         # to stuff that displays correctly
         #
         echo $therawhtml_line;
         #echo $therawhtml;
      }
      else {
         #
         # dump  it as binary
         # display printable text and data in hex too
         #
         display_socket_binary($data);
         #display_socket_binary_flush($data);
      }
      echo "</blockquote>";
   }
   else {
      #
      # error opening the socket
      # it probably doesnt exist
      #
      echo "<p>";
      echo "<div style=\"background-color:#ff0000;\">";
      echo "Error opening ";
      echo "<span style=\"background-color:#ffff00;\">";
      echo "$sitename on port $port";
      echo "</span>";
      echo "<blockquote>";
      echo "error=";
      echo "<span style=\"background-color:#ffff00;\">";
      echo "&nbsp;$fp&nbsp;";
      echo "</span>";
      echo "</blockquote>";
      echo "</div>";
   }
   return;
}
?>
<h1>Playing with Sockets and Kinda Sockets</h1>
Here we will play with sockets and stuff that is kind of sort of like sockets!!!
<h1>A REAL Socket</h1>
URL to run some sockets on :)
<form action="sockets_real_select.php" method="post">
<input type="submit" name=submit value="Submit"> 
<input type="text" name="stinkingserver" size="100"
<?php 
$stinkingserver=$_POST['stinkingserver'];
#
# remove leading and trailing spaces from URL
#
$stinkingserver=preg_replace("/ */","",$stinkingserver);  
$stinkingserver=preg_replace("/ *\$/","",$stinkingserver); 
#
# add the http:// if it aint there
#
if (! preg_match("/^http[s]?:\/\//i",$stinkingserver)) {
   if ($stinkingserver != '') {
      $stinkingserver="http://$stinkingserver";
   } 
}
echo "value=\"$stinkingserver\""; 
?>
>
<a href="view_krud.php">Dump krud.txt</a>
<br>
<a href="whois_this_url.php">Do a whois on a URL or IP address</a>
<p>
</form>
<?php
#
# analyize the URL if a name was entered

if ($stinkingserver != '') {
   dump_the_stinking_socket($stinkingserver);
}
?>
<h1>documentation on request methods and HTTP</h1>
See <a href="http://www.w3.org/Protocols/HTTP/1.1/rfc2616bis/draft-lafon-rfc2616bis-03.txt">this</a>
<p>
Also two of those books I bought in Menlo Park when
I was working at CISCO had some good documentation on this.
They are:
<blockquote>
Webmaster in a nutshell<br>
A Desktop Quick Reference<br>
by Stephen Spainhour & Robert Eckstein<br>
O'Reilly
<p>
Internet in a nutshell<br>
A Desktop Quick Reference<br>
by Valerie Quercia<br>
O'Reilly
</blockquote>
<h1>Kind of Sockets</h1>
Cool PHP lets you treat URLs as disk files and read them!
I call them fake sockets. 
<p>
Check them out <a href="sockets_kind_of.php">here</a>
<h1>Some URL's to run thru this web page</h1>
<ul>
<li>gif Image <a href="http://arizona.indymedia.org/uploads/2007/12/tempe_logo.gif">http://arizona.indymedia.org/uploads/2007/12/tempe_logo.gif</a>
<li>jpg Image <a href="http://sandiego.indymedia.org/berserkcop2.jpg">http://sandiego.indymedia.org/berserkcop2.jpg</a>
<li>mpeg Video <a href="http://www.tizag.com/files/html/htmlexample.mpeg">http://www.tizag.com/files/html/htmlexample.mpeg</a>
<li>mp3 Audio <a href="https://my-stuff.tripod.com/sinema.mp3">https://my-stuff.tripod.com/sinema.mp3</a>
<li>wma Audio <a href="http://tape-recorder.tripod.com/WS_30027.WMA">http://tape-recorder.tripod.com/WS_30027.WMA</a>
</ul>

../sql_stuff/sql_add_counter.php

TOC

<script language="php">
  require('../sql_passwords.php');
  echo "<h1>Add and Update Counters</h1>\n";
  $zname=$_POST['zname'];
  $zvalue=$_POST['zvalue'];
  $zname=$_REQUEST['zname'];
  $zvalue=$_REQUEST['zvalue'];
  $errors=0;
  $errort="";
  $zpassword=$_REQUEST['zpassword'];
  #
  # if the counter is blank set it to zero
  #
  if ( preg_match ( '/^ *$/', $zvalue) || preg_match ( '/^ *00* *$/', $zvalue) ) {
     $zvalue=0;
  }
  #
  # if the counter is not blank make sure it is a number
  #
  if ( !preg_match ( '/^[+]{0,1}[0-9][0-9]*$/', $zvalue) ) {
     $errors++;
     $errort="counter is not numeric";
  }
</script>

 <FORM action="sql_add_counter.php" method="post">
 <table border=0>
 <tr>
 <td align="right">
 Name:</td><td><INPUT type="text" name="zname"
<script language="php">
  echo " value=\"$zname\"";
</script>
></td></tr> 
<tr><td  align="right">Value:</td><td><INPUT type="text" name="zvalue"
<script language="php">
  echo " value=\"$zvalue\"";
</script>
></td></tr>
<tr><td align="right">Password:</td><td><INPUT type="PASSWORD" name="zpassword"
<script language="php">
  echo " value=\"$zpassword\"";
</script>
></td></tr>
<tr><td>&nbsp;</td><td><INPUT type="submit" value="submit"></td></tr>
 </FORM>
<script language="php">



 #
 # they can only update the SQL tables if they have a kinda sorta public password
 #
 if ( $zpassword != $z_hardcoded_password ) {
  exit;
 }
 #
 # connect to SQL
 #
 $link = mysql_connect($z_hardcoded_sqlurl, 
                       $z_hardcoded_database, 
                       $z_hardcoded_password )
                       or die('Could not connect: ' . mysql_error());
 #
 # select the database I want to use
 #
 mysql_select_db($z_hardcoded_database) or die('Could not select database');
 #
 # go and either add the item or update the item
 #

 #
 # only update or insert if there are ZERO errors
 #
 if ( $errors == 0 &&  !preg_match ( '/^ *$/', $zname)  ) {
    $rc=update_insert($zname, $zvalue);
 }
 #
 # show them the contents of the SQl data base
 # sorted by the name
 #
 echo "<table>\n";
 #
 # dont let them update the SQL data if they entered garbage on the form
 #
 if ( $errors > 0 ) {
  echo "<tr><td colspan=2>";
  echo "<DIV style=\"background-color: rgb(255,0,0)\">";
  echo "$errors error(s) $errort</DIV></td></tr>";
 }
 if ( $rc ) {
  echo "<tr><td colspan=2>$rc</td></tr>";
 }
 echo "<tr>\n";
 echo "<td>\n";
 echo "<table border=0>\n";
 echo "<tr><td>\n";
 echo "</td><td>\n";


 #
 # display all the stuff sorted by name and then sorted by count
 #
 $query = 'SELECT name,count FROM `counters` order by name, count';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 $query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query);
 $query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
 $numberofrows=0;
 #
 # display the selected stuff
 #
 echo "<table border=1>\n";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $numberofrows++;
    echo "<tr>\n";
    $i=0;
    $a="";
    foreach ($line as $col_value) {
        $i++;
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        if ($i > 1 ) {
          $a=' align="right"';
        }
        echo "<td $a>$col_value</td>\n";
    }
    echo "</tr>\n";
 } 
 if ($numberofrows == 0 ) {
    echo "<tr><td colspan=2>&nbsp;&nbsp;&nbsp;&nbsp;No Data for that key</td></tr>";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td>\n";
 echo "<td>\n";
 echo "<table border=0>\n";
 echo "<tr><td>\n";
 echo "</td><td>\n";
 #
 # show them the SQL database 
 # sorted by the counter value
 #
 $query = 'SELECT name,count FROM `counters` order by count, name';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 $query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query);
 $query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
 $numberofrows=0;
 #
 # display the selected stuff
 #
 echo "<table border=1>\n";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $numberofrows++;
    echo "<tr>\n";
    $i=0;
    $a="";
    foreach ($line as $col_value) {
        $i++;
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        if ($i > 1 ) {
          $a=' align="right"';
        }
        echo "<td $a>$col_value</td>\n";
    }
    echo "</tr>\n";
 }
 if ($numberofrows == 0 ) {
    echo "<tr><td colspan=2>&nbsp;&nbsp;&nbsp;&nbsp;No Data for that key</td></tr>";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td>\n";
 echo "</tr>\n";
 echo "</table>\n";
 echo "</table>\n";
 #
 # close the SQL connection
 #
 // Closing connection
 mysql_close($link);
 exit;
</script> 


<script language="php">
 #
 # this function updates the name if it exists
 # if the name does not exist it add the name
 #
 function update_insert($zname, $zvalue) {
  #
  # use to change the color of out put messages
  #
  $rcs="<DIV style=\"background-color: rgb(0,255,0)\">";
  $rce="</DIV>";
  $rces="<DIV style=\"background-color: rgb(255,0,0)\">";
  $rcee="</DIV>";
  $rc=0;
  $query = 'SELECT count FROM `counters` where name=\''.$zname.'\'';
  $result = mysql_query($query);
  $numberofrows=0;
  $numberofrows = mysql_num_rows($result);
  #
  # i am not sure but i think this frees the
  # stuff associated with the current select so
  # you can do a new select
  #
  // Free resultset
  mysql_free_result($result);
  if (  $numberofrows > 0 ) {
    $query = 'update `counters` set count='.$zvalue.' WHERE name=\''.$zname.'\'';
    $result = mysql_query($query) or die('Query failed: ' . mysql_error());
   if ($result) {
      $rc=$rcs.$zname." has been set to ".$zvalue.$rce;
   }
   else {
      $rc=$rces."Update of ".$zname." with a value of ".$zvalue." failed".$rcee;
   }
  }
  else {
   $query = 'INSERT into `counters` set name=\''.$zname.'\', count=\''.$zvalue.'\'';
   $result = mysql_query($query);
   if ($result) {
      $rc=$rcs.$zname." has been inserted with a value of ".$zvalue.$rce;
   }
   else {
      $rc=$rces."Insert of ".$zname." with a value of ".$zvalue." failed".$rcee;
   }
  }
  return $rc;
 }
</script>

../sql_stuff/sql_base.php

TOC

<script language="php">
 #
 # this include file has the passwords and 
 # database names defined in it  
 #
 require('../sql_passwords.php');
 echo "Database Server: :mysql1.100ws.com<br>";
 echo "database name:miksup_data<br>";
 echo "username <br>";
 echo "table counters<br>";
 echo "more<blockquote>MySQL 4.1.11-Debian_4sarge5 running on<br>mysql1.100ws.com as<br> miksup_data@ws2.100ws.com</blockquote>";
 #
 # connect to SQL
 #
 $link = mysql_connect($z_hardcoded_sqlurl, 
                       $z_hardcoded_database, 
                       $z_hardcoded_password )
                       or die('Could not connect: ' . mysql_error());
 echo 'Connected successfully<br>';
 #
 # select the database I want to use
 #
 mysql_select_db($z_hardcoded_database) or die('Could not select database');
 echo 'selected database<br>';
 $query = 'SELECT name, count FROM `counters` LIMIT 0, 30 ';

 echo "\$query=$query<br>";
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 echo "query worked<br>";
 echo "<table border=2>\n";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "\t<tr>\n";
    foreach ($line as $col_value) {
        echo "\t\t<td>$col_value</td>\n";
    }
    echo "\t</tr>\n";
 }
 echo "</table>\n";
 // Free resultset
 mysql_free_result($result);
 // Closing connection
 mysql_close($link);
</script> 

../sql_stuff/sql_i_u_d.php

TOC

<script language="php">
  require('../sql_passwords.php');
  echo "<h1>Insert, Update, and Delete Counters</h1>\n";
  $zname=$_POST['zname'];
  $zvalue=$_POST['zvalue'];
  $zdelete=$_POST['zdelete'];
  $zname=$_REQUEST['zname'];
  $zdelete=$_REQUEST['zdelete'];
  $zvalue=$_REQUEST['zvalue'];
  $errors=0;
  $errort="";
  #$zname=preg_replace ( "/'/i", '', $zname);
  $zpassword=$_REQUEST['zpassword'];
  #
  # if the counter is blank set it to zero
  #
  if ( preg_match ( '/^ *$/', $zvalue) || preg_match ( '/^ *00* *$/', $zvalue) ) {
     $zvalue=0;
  }
  #
  # if the counter is not blank make sure it is a number
  #
  if ( !preg_match ( '/^[+]{0,1}[0-9][0-9]*$/', $zvalue) ) {
     $errors++;
     $errort="counter is not numeric";
  }
</script>

 <FORM action="sql_i_u_d.php" method="post">
 <table border=0>
 <tr>
 <td align="right">
 Name:</td><td><INPUT type="text" name="zname"
<script language="php">
  echo " value=\"$zname\"";
</script>
></td></tr> 
<tr><td  align="right">Value:</td><td><INPUT type="text" name="zvalue" 
<script language="php">
  echo " value=\"$zvalue\"";
</script>
></td></tr>

<tr><td align="right">Delete:</td><td><INPUT type="CHECKBOX" name="zdelete"
<script language="php">
  #echo " value=\"$zdelete\"";
</script>
></td></tr>


<tr><td align="right">Password:</td><td><INPUT type="PASSWORD" name="zpassword"
<script language="php">
  echo " value=\"$zpassword\"";
</script>
></td></tr>


<tr><td>&nbsp;</td><td><INPUT type="submit" value="submit"></td></tr>
 </FORM>



<script language="php">
 #
 # they can only update the SQL tables if they have a kinda sorta public password
 #
 if ( $zpassword != $z_hardcoded_password ) {
  exit;
 }
 #
 # connect to SQL
 #
 $link = mysql_connect($z_hardcoded_sqlurl, 
                       $z_hardcoded_database, 
                       $z_hardcoded_password )
                       or die('Could not connect: ' . mysql_error());
 #
 # select the database I want to use
 #
 mysql_select_db($z_hardcoded_database) or die('Could not select database');
 #
 # go and either add the item or update the item
 #
 #
 # delete the counter?
 #
 if ( $zdelete == "on") {
    #
    # build a query to delete it
    #
    $query = 'DELETE from `counters_playpen` where name=\''.$zname.'\'';
    #
    # try to delete it
    #
    $result = mysql_query($query);
    #
    # check how many rows got deleted
    #
    #$numberofrows = mysql_num_rows($result);
    $numberofrows = mysql_affected_rows();
    if ($numberofrows > 0) {
       $rc="<SPAN style=\"background-color: rgb(0,255,0)\">";
       $rc.=$zname." has been deleted</span>";
    }
    else {
       $rc="<SPAN style=\"background-color: rgb(255,0,0)\">";
       $rc.=$zname." could not be deleted. It probably doesn't exist</span>";
    }
 }
 else {
    #
    # only update or insert if there are ZERO errors
    #
    if ( $errors == 0 ) {
       $rc=update_insert($zname, $zvalue);
    }
 }
 #
 # show them the contents of the SQl data base
 # sorted by the name
 #
 echo "<table>\n";
 #
 # dont let them update the SQL data if they entered garbage on the form
 #



 if ( $errors > 0 && $zdelete != "on" ) {
  echo "<tr><td colspan=2>";
  echo "<span style=\"background-color: rgb(255,0,0)\">";
  echo "$errors error(s) $errort</span></td></tr>";
 }
 if ( $rc ) {
  echo "<tr><td colspan=2>$rc</td></tr>";
 }
 echo "<tr>\n";
 echo "<td>\n";
 echo "<table border=0>\n";
 echo "<tr><td>\n";
 echo "</td><td>\n";


 #
 # display all the stuff sorted by name and then sorted by count
 #
 $query = 'SELECT name,count FROM `counters_playpen` order by name, count';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 $query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query);
 $query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
 $numberofrows=0;
 #
 # display the selected stuff
 #
 echo "<table border=1>\n";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $numberofrows++;
    echo "<tr>\n";
    $i=0;
    $a="";
    foreach ($line as $col_value) {
        $i++;
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        if ($i > 1 ) {
          $a=' align="right"';
        }
        echo "<td $a>$col_value</td>\n";
    }
    echo "</tr>\n";
 } 
 if ($numberofrows == 0 ) {
    echo "<tr><td colspan=2>&nbsp;&nbsp;&nbsp;&nbsp;No Data for that key</td></tr>";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td>\n";
 echo "<td>\n";
 echo "<table border=0>\n";
 echo "<tr><td>\n";
 echo "</td><td>\n";
 #
 # show them the SQL database 
 # sorted by the counter value
 #
 $query = 'SELECT name,count FROM `counters_playpen` order by count, name';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 $query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query);
 $query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
 $numberofrows=0;
 #
 # display the selected stuff
 #
 echo "<table border=1>\n";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $numberofrows++;
    echo "<tr>\n";
    $i=0;
    $a="";
    foreach ($line as $col_value) {
        $i++;
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        if ($i > 1 ) {
          $a=' align="right"';
        }
        echo "<td $a>$col_value</td>\n";
    }
    echo "</tr>\n";
 }
 if ($numberofrows == 0 ) {
    echo "<tr><td colspan=2>&nbsp;&nbsp;&nbsp;&nbsp;No Data for that key</td></tr>";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td>\n";
 echo "</tr>\n";
 echo "</table>\n";
 echo "</table>\n";
 #
 # close the SQL connection
 #
 // Closing connection
 mysql_close($link);
 exit;
</script> 


<script language="php">
 #
 # this function updates the name if it exists
 # if the name does not exist it add the name
 #
 function update_insert($zname, $zvalue) {
  #
  # use to change the color of out put messages
  #
  $rcs="<span style=\"background-color: rgb(0,255,0)\">";
  $rce="</span>";
  $rces="<span style=\"background-color: rgb(255,0,0)\">";
  $rcee="</span>";
  $rc=0;
  $query = 'SELECT count FROM `counters_playpen` where name=\''.$zname.'\'';
  $result = mysql_query($query);
  $numberofrows=0;
  $numberofrows = mysql_num_rows($result);
  #
  # i am not sure but i think this frees the
  # stuff associated with the current select so
  # you can do a new select
  #
  // Free resultset
  mysql_free_result($result);
  if (  $numberofrows > 0 ) {
    $query = 'update `counters_playpen` set count='.$zvalue.' WHERE name=\''.$zname.'\'';
    $result = mysql_query($query) or die('Query failed: ' . mysql_error());
   if ($result) {
      $rc=$rcs.$zname." has been set to ".$zvalue.$rce;
   }
   else {
      $rc=$rces."Update of ".$zname." with a value of ".$zvalue." failed".$rcee;
   }
  }
  else {
   $query = 'INSERT into `counters_playpen` set name=\''.$zname.'\', count=\''.$zvalue.'\'';
   $result = mysql_query($query);
   if ($result) {
      $rc=$rcs.$zname." has been inserted with a value of ".$zvalue.$rce;
   }
   else {
      $rc=$rces."Insert of ".$zname." with a value of ".$zvalue." failed".$rcee;
   }
  }
  return $rc;
 }
</script>

../sql_stuff/sql_i_u_d_from.php

TOC

<script language="php">
  $debug=0;
  require('../sql_passwords.php');
  $zname=$_POST['zname'];
  $zvalue=$_POST['zvalue'];
  $zdelete=$_POST['zdelete'];
  $zname=$_REQUEST['zname'];
  $zdelete=$_REQUEST['zdelete'];
  $zvalue=$_REQUEST['zvalue'];
  $errors=0;
  $errort="";
  $zpassword=$_REQUEST['zpassword'];
  $zvalue=0;
 #
 # connect to SQL
 #
 $link = mysql_connect($z_hardcoded_sqlurl, 
                       $z_hardcoded_database, 
                       $z_hardcoded_password )
                       or die('Could not connect: ' . mysql_error());
 #
 # select the database I want to use
 #
 mysql_select_db($z_hardcoded_database) or die('Could not select database');
 #
 # get a copy of the playpen database
 # we will merge it with the production database
 #
 $query = 'SELECT name,count FROM `counters_playpen`';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 #
 # display the selected stuff
 #
 $numberofrows=0;
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $i=0;
    foreach ($line as $col_value) {
        if ($i == 0 ) {
          $name[$numberofrows]=$col_value;
          $i++;
        }
        else {
          $data[$numberofrows]=$col_value;
          $numberofrows++;
          $i=0;
        }
    } 
 }
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 #
 # display the data in the counter playpen database
 #
 if ($debug) {
    echo "<table border=1>\n";
    for ($i=0;$i<$numberofrows;$i++) {
      echo "<tr><td>$name[$i]</td><td>$data[$i]</td></tr>";
    }
    echo "</table>";
 } 
 #
 # delete everything in the playpen database
 #
 #
 $query = 'DELETE from `counters_playpen` ';
 $result = mysql_query($query);
 #
 # check how many rows got deleted
 #
 #$numberofrows = mysql_num_rows($result);
 $numberofrows = mysql_affected_rows();
 if ($debug) {
    echo "$numberofrows have been deleted<br>";
 } 
 #
 # copy the counter database into the playpen counter database
 #   please note the data to insert is generated from a SELECT
 #   of another database ie: counters as opposed to 
 #   counters_playpen
 #
 $query = 'INSERT into `counters_playpen` 
                     (counters_playpen.name, counters_playpen.count)
          SELECT counters.name, counters.count FROM `counters` ';
 $result = mysql_query($query);
 #
 # add the orginal data back in
 # some will be rejected if they also exist in the production
 #
 for ($i=0;$i<$numberofrows;$i++) {
   $query = 'INSERT into `counters_playpen` (name, count) values 
                      (\''.$name[$i].'\',\''.$data[$i].'\') ';
   if ($debug) {
      echo "query=$query<br>";
   }
   $result = mysql_query($query);
   if ($result) {
      #echo "INSERT WORKED $name[$i] $data[$i] <br>";
   }
   else {
      #echo "Insert failed $name[$i] $data[$i]<br>";
   }
 }
 #
 # close the SQL connection
 #
 // Closing connection
 mysql_close($link);
 require('sql_i_u_d.php');
 exit;
</script>

../sql_stuff/sql_info.php

TOC

<script language="php">
 #
 # this include file has the passwords and 
 # database names defined in it  
 #
 require('../sql_passwords.php');
 echo "Database Server: :mysql1.100ws.com<br>";
 echo "database name:miksup_data<br>";
 echo "username <br>";
 echo "table counters<br>";
 echo "more<blockquote>MySQL 4.1.11-Debian_4sarge5 running on<br>mysql1.100ws.com as<br> miksup_data@ws2.100ws.com</blockquote>";
</script> 

../sql_stuff/sql_insert_delete.php

TOC

<script language="php">
 #
 # this include file has the passwords and 
 # database names defined in it  
 #
 require('../sql_passwords.php');
 echo "<h1>SQL insert &amp; delete statements</h1>\n";
 #
 # connect to SQL
 #
 $link = mysql_connect($z_hardcoded_sqlurl, 
                       $z_hardcoded_database, 
                       $z_hardcoded_password )
                       or die('Could not connect: ' . mysql_error());
 #
 # select the database I want to use
 #
 mysql_select_db($z_hardcoded_database) or die('Could not select database');








 echo "<h2>Does any data exists? Do a SELECT</h2>";
 echo "<table border=0>\n";
 echo "<tr><td>\n";
 echo "</td><td>\n";
 $query = 'SELECT name,count FROM `counters` where name=\'happydogmeat\'';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 $query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query);
 $query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
 $numberofrows=0;
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query</td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $numberofrows++;
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
 }
 if ($numberofrows == 0 ) {
    echo "<tr><td colspan=2>&nbsp;&nbsp;&nbsp;&nbsp;No Data for that key</td></tr>";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);





 echo "<h2>Try to INSERT some data</h2>";
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 #
 # if no data exists the first insert will work and the others will fail
 # if any data exists all the inserts will fail
 #
 for ($i=1;$i<4;$i++) {
    $query = 'INSERT into `counters` set name=\'happydogmeat\', count=\''.$i.'\'';
    #
    # this is a second way of doing it
    #
    #      INSERT INTO `counters` ( `name` , `count` ) 
    #           VALUES ('dogmeat', '0');
    #
    echo "<tr><td colspan=2>$query</td></tr>";
    $result = mysql_query($query);
    if ($result) {
       echo "<tr><td colspan=2>&nbsp;&nbsp;&nbsp;&nbsp;Insert worked</td></tr>";
    }
    else {



       echo "<tr><td colspan=2>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN style=\"color: red\">Insert failed</span></td></tr>";
    }
 }
 echo "</table>\n";










echo "<h2>SELECT the inserted data</h2>";
$query = 'SELECT name, count FROM `counters` where name=\'happydogmeat\'';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
$query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query);
$query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
$numberofrows=0;
#
# display the selected stuff
#
echo "<table border=2>\n";
echo "<tr><td colspan=2>$query</td></tr>";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
   echo "<tr>\n";
   $numberofrows++;
   foreach ($line as $col_value) {
       if ($col_value == '' ) {
          $col_value='&nbsp;';
       }
       echo "<td>$col_value</td>\n";
   }
   echo "</tr>\n";
   if ($numberofrows == 0 ) {
      echo "<tr><td colspan=2>&nbsp;&nbsp;&nbsp;&nbsp;No Data for that key</td></tr>";
   }
}
echo "</table>\n";









echo "<h2>DELETE all the data that matches this key</h2>";
echo "<table border=1>\n";
$query = 'DELETE from `counters` where name=\'happydogmeat\'';
echo "<tr><td colspan=2>$query</td></tr>";
$result = mysql_query($query);
if ($result) {
 echo "<tr><td colspan=2>&nbsp;&nbsp;&nbsp;&nbsp;Delete worked</td></tr>";
}
else {
 echo "<tr><td colspan=2>&nbsp;&nbsp;&nbsp;&nbsp;Delete failed</td></tr>";
}
echo "</table>\n";














echo "<h2>Do a SELECT to show no data exists</h2>";
$query = 'SELECT name, count FROM `counters` where name=\'happydogmeat\'';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
$query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query);
$query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
$numberofrows=0;
#
# display the selected stuff
#
echo "<table border=2>\n";
echo "<tr><td colspan=2>$query</td></tr>";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
   echo "<tr>\n";
   $numberofrows++;
   foreach ($line as $col_value) {
       if ($col_value == '' ) {
          $col_value='&nbsp;';
       }
       echo "<td>$col_value</td>\n";
   }
   echo "</tr>\n";

}
if ($numberofrows == 0 ) {
   echo "<tr><td colspan=2>&nbsp;&nbsp;&nbsp;&nbsp;No Data for that key</td></tr>";
}


echo "</table>\n";
#
# i am not sure but i think this frees the
# stuff associated with the current select so
# you can do a new select
#
// Free resultset
mysql_free_result($result);














#
# close the SQL connection
#
// Closing connection
mysql_close($link);
</script> 

sql_insert_us_states.php

TOC

<script language="php">
 #
 # this include file has the passwords and 
 # database names defined in it  
 #
 require('../sql_passwords.php');
 echo "<h1>SQL insert American States</h1>\n";
 #
 # connect to SQL
 #
 $link = mysql_connect($z_hardcoded_sqlurl, 
                       $z_hardcoded_database, 
                       $z_hardcoded_password )
                       or die('Could not connect: ' . mysql_error());
 #
 # select the database I want to use
 #
 mysql_select_db($z_hardcoded_database) or die('Could not select database');
 echo "<h2>Insert the 50+ states and terrorties!</h2>";
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 #
 # build an array of the 50 american states, terrorties and DC
 #
 $states=array('Alabama',
              'Alaska',
              'American Samoa',
              'Arizona',
              'Arkansas',
              'California',
              'Colorado',
              'Connecticut',
              'Delaware',
              'District of Columbia',
              'Federated States of Micronesia',
              'Florida',
              'Georgia',
              'Guam',
              'Hawaii',
              'Idaho',
              'Illinois',
              'Indiana',
              'Iowa',
              'Kansas',
              'Kentucky',
              'Louisiana',
              'Maine',
              'Marshall Islands',
              'Maryland',
              'Massachusetts',
              'Michigan',
              'Midway Islands',
              'Minnesota',
              'Mississippi',
              'Missouri',
              'Montana',
              'Nebraska',
              'Nevada',
              'New Hampshire',
              'New Jersey',
              'New Mexico',
              'New York',
              'North Carolina',
              'North Dakota',
              'Northern Mariana Islands',
              'Ohio',
              'Oklahoma',
              'Oregon',
              'Palua',
              'Pennsylvania',
              'Puerto Rico',
              'Rhode Island',
              'South Carolina',
              'South Dakota',
              'Tennessee',
              'Texas',
              'Utah',
              'Vermont',
              'Virgin Islands',
              'Virginia',
              'Washington',
              'West Virginia',
              'Wisconsin',
              'Wyoming');

 #
 # insert each state into the table
 #
 echo "we got HERE..................................<p>";

 foreach ($states as $i) {
    $query = 'INSERT into `rulers_states` set n=\'1\', state=\''.$i.'\'';
    #
    # this is a second way of doing it
    #
    #      INSERT INTO `counters` ( `name` , `count` ) 
    #           VALUES ('dogmeat', '0');
    #
    echo "<tr><td colspan=2>$query</td></tr>";
    $result = mysql_query($query);
    if ($result) {
       echo "<tr><td colspan=2>&nbsp;&nbsp;&nbsp;&nbsp;$i Insert worked</td></tr>";
    }
    else {



       echo "<tr><td colspan=2>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN style=\"color: red\">$i Insert failed</span></td></tr>";
    }
 }
 echo "</table>\n";

echo "<h2>SELECT the inserted data</h2>";
$query = 'SELECT ns, state FROM rulers_states';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$numberofrows=0;
#
# display the selected stuff
#
echo "<table border=2>\n";
echo "<tr><td colspan=2>$query</td></tr>";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
   echo "<tr>\n";
   $numberofrows++;
   foreach ($line as $col_value) {
       if ($col_value == '' ) {
          $col_value='&nbsp;';
       }
       echo "<td>$col_value</td>\n";
   }
   echo "</tr>\n";
   if ($numberofrows == 0 ) {
      echo "<tr><td colspan=2>&nbsp;&nbsp;&nbsp;&nbsp;No Data for that key</td></tr>";
   }
}
echo "</table>\n";
#
# close the SQL connection
#
// Closing connection
mysql_close($link);
</script> 

../sql_stuff/sql_select.php

TOC

<script language="php">
 #
 # this include file has the passwords and 
 # database names defined in it  
 #
 require('../sql_passwords.php');
 echo "<h1>SQL select statements</h1>\n";
 #
 # connect to SQL
 #
 $link = mysql_connect($z_hardcoded_sqlurl, 
                       $z_hardcoded_database, 
                       $z_hardcoded_password )
                       or die('Could not connect: ' . mysql_error());
 #
 # select the database I want to use
 #
 mysql_select_db($z_hardcoded_database) or die('Could not select database');
 echo "<table border=0>\n";




 echo "<tr><td>\n";
 #
 # select some stuff from the database
 #
 $query = 'SELECT name, count FROM `counters` ';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query<p></td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td><td>\n";
 

 $query = 'SELECT name, count FROM `counters` order by name, count';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 $query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query</td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td><td>\n";
 $query = 'SELECT name, count FROM `counters` order by  count,name';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 $query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query</td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td></tr>\n";
 echo "<tr><td>\n";
 #
 # select some stuff from the database
 #
 $query = 'SELECT name, count FROM `counters` where name like \'c%\' ';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from /i', '<br>&nbsp;from ', $query);
 $query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query);
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query<p></td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td><td>\n";
 $query = 'SELECT name, count FROM `counters`  where name like \'c%\' order by name,  count';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 $query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query);
 $query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query</td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td><td>\n";
 $query = 'SELECT name, count FROM `counters` where name like \'c%\' order by   count,name';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 $query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query);
 $query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query</td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td></tr>\n";
 echo "<tr><td>\n";
 #
 # select some stuff from the database
 #
 $query = 'SELECT name, count FROM `counters` where name=\'c\' ';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from /i', '<br>&nbsp;from ', $query);
 $query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query); 
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query<p></td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td><td>\n";
 $query = 'SELECT name, count FROM `counters`  where name=\'c\' order by name, count';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 $query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query);
 $query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query</td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td><td>\n";
 $query = 'SELECT name, count FROM `counters` where name=\'c\' order by  count,name';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 $query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query);
 $query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query</td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td></tr>\n";
 echo "</table>\n";
 #
 # close the SQL connection
 #
 // Closing connection
 mysql_close($link);
</script> 

../sql_stuff/sql_select_like_perl.php

TOC

<script language="php">
 #
 # this include file has the passwords and 
 # database names defined in it  
 #
 require('../sql_passwords.php');
 echo "<h1>SQL select statements</h1>\n";
 #
 # connect to SQL
 #
 $link = mysql_connect($z_hardcoded_sqlurl, 
                       $z_hardcoded_database, 
                       $z_hardcoded_password )
                       or die('Could not connect: ' . mysql_error());
 #
 # select the database I want to use
 #
 mysql_select_db($z_hardcoded_database) or die('Could not select database');
 echo "<table border=0>\n";




 echo "<tr><td>\n";
 #
 # select some stuff from the database
 #
 $query = 'SELECT name, count FROM `counters` ';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query<p></td></tr>";
 #
 # get the number of rows this query returned
 #
 $rows=mysql_num_rows($result);
 echo "<tr><td colspan=2>rows=$rows<p></td></tr>";
 #
 # basicly $line is a PERL hash 
 #
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    #
    # dump $line which is an hash array which gets the selected data
    #
    #echo "<tr><td colspan=2>";
    #var_dump($line);
    #echo "</td></tr>";
    echo "<tr><td colspan=2>Crude and Dirty Way</td></tr>";
    echo "<tr>\n";
    #
    # crude and dirty - loop thru the hash
    #
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
    echo "<tr><td colspan=2>PERL Way</td></tr>";
    echo "<tr>";
    #
    # clean - get the hash items we want and print them
    #
    $select_item_1=$line['name'];  # 'name' is the value selected 
    $select_item_2=$line['count']; # 'count' is the value selected
    if ($select_item_1 == '' ) {
       $select_item_1='&nbsp;';
    }
    echo "<td>$select_item_1</td>";
    echo "<td>$select_item_2</td>";
    echo "</tr>";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td><td>\n";
 

 $query = 'SELECT name, count FROM `counters` order by name, count';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 $query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query</td></tr>";
 $rows=mysql_num_rows($result);
 echo "<tr><td colspan=2>rows=$rows<p></td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr><td colspan=2>Crude and Dirty Way</td></tr>";
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
    echo "<tr><td colspan=2>PERL Way</td></tr>";
    echo "<tr>";
    #
    # clean - get the hash items we want and print them
    #
    $select_item_1=$line['name'];  # 'name' is the value selected 
    $select_item_2=$line['count']; # 'count' is the value selected
    if ($select_item_1 == '' ) {
       $select_item_1='&nbsp;';
    }
    echo "<td>$select_item_1</td>";
    echo "<td>$select_item_2</td>";
    echo "</tr>";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td><td>\n";
 $query = 'SELECT name, count FROM `counters` order by  count,name';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 $query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query</td></tr>";
 $rows=mysql_num_rows($result);
 echo "<tr><td colspan=2>rows=$rows<p></td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr><td colspan=2>Crude and Dirty Way</td></tr>";
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
    echo "<tr><td colspan=2>PERL Way</td></tr>";
    echo "<tr>";
    #
    # clean - get the hash items we want and print them
    #
    $select_item_1=$line['name'];  # 'name' is the value selected 
    $select_item_2=$line['count']; # 'count' is the value selected
    if ($select_item_1 == '' ) {
       $select_item_1='&nbsp;';
    }
    echo "<td>$select_item_1</td>";
    echo "<td>$select_item_2</td>";
    echo "</tr>";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td></tr>\n";
 echo "<tr><td>\n";
 #
 # select some stuff from the database
 #
 $query = 'SELECT name, count FROM `counters` where name like \'c%\' ';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from /i', '<br>&nbsp;from ', $query);
 $query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query);
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query<p></td></tr>";
 $rows=mysql_num_rows($result);
 echo "<tr><td colspan=2>rows=$rows<p></td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr><td colspan=2>Crude and Dirty Way</td></tr>";
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
    echo "<tr><td colspan=2>PERL Way</td></tr>";
    echo "<tr>";
    #
    # clean - get the hash items we want and print them
    #
    $select_item_1=$line['name'];  # 'name' is the value selected 
    $select_item_2=$line['count']; # 'count' is the value selected
    if ($select_item_1 == '' ) {
       $select_item_1='&nbsp;';
    }
    echo "<td>$select_item_1</td>";
    echo "<td>$select_item_2</td>";
    echo "</tr>";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td><td>\n";
 $query = 'SELECT name, count FROM `counters`  where name like \'c%\' order by name,  count';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 $query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query);
 $query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query</td></tr>";
 $rows=mysql_num_rows($result);
 echo "<tr><td colspan=2>rows=$rows<p></td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr><td colspan=2>Crude and Dirty Way</td></tr>";
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
    echo "<tr><td colspan=2>PERL Way</td></tr>";
    echo "<tr>";
    #
    # clean - get the hash items we want and print them
    #
    $select_item_1=$line['name'];  # 'name' is the value selected 
    $select_item_2=$line['count']; # 'count' is the value selected
    if ($select_item_1 == '' ) {
       $select_item_1='&nbsp;';
    }
    echo "<td>$select_item_1</td>";
    echo "<td>$select_item_2</td>";
    echo "</tr>";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td><td>\n";
 $query = 'SELECT name, count FROM `counters` where name like \'c%\' order by   count,name';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 $query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query);
 $query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query</td></tr>";
 $rows=mysql_num_rows($result);
 echo "<tr><td colspan=2>rows=$rows<p></td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr><td colspan=2>Crude and Dirty Way</td></tr>";
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
    echo "<tr><td colspan=2>PERL Way</td></tr>";
    echo "<tr>";
    #
    # clean - get the hash items we want and print them
    #
    $select_item_1=$line['name'];  # 'name' is the value selected 
    $select_item_2=$line['count']; # 'count' is the value selected
    if ($select_item_1 == '' ) {
       $select_item_1='&nbsp;';
    }
    echo "<td>$select_item_1</td>";
    echo "<td>$select_item_2</td>";
    echo "</tr>";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td></tr>\n";
 echo "<tr><td>\n";
 #
 # select some stuff from the database
 #
 $query = 'SELECT name, count FROM `counters` where name=\'c\' ';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from /i', '<br>&nbsp;from ', $query);
 $query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query); 
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query<p></td></tr>";
 $rows=mysql_num_rows($result);
 echo "<tr><td colspan=2>rows=$rows<p></td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr><td colspan=2>Crude and Dirty Way</td></tr>";
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
    echo "<tr><td colspan=2>PERL Way</td></tr>";
    echo "<tr>";
    #
    # clean - get the hash items we want and print them
    #
    $select_item_1=$line['name'];  # 'name' is the value selected 
    $select_item_2=$line['count']; # 'count' is the value selected
    if ($select_item_1 == '' ) {
       $select_item_1='&nbsp;';
    }
    echo "<td>$select_item_1</td>";
    echo "<td>$select_item_2</td>";
    echo "</tr>";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td><td>\n";
 $query = 'SELECT name, count FROM `counters`  where name=\'c\' order by name, count';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 $query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query);
 $query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query</td></tr>";
 $rows=mysql_num_rows($result);
 echo "<tr><td colspan=2>rows=$rows<p></td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr><td colspan=2>Crude and Dirty Way</td></tr>";
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
    echo "<tr><td colspan=2>PERL Way</td></tr>";
    echo "<tr>";
    #
    # clean - get the hash items we want and print them
    #
    $select_item_1=$line['name'];  # 'name' is the value selected 
    $select_item_2=$line['count']; # 'count' is the value selected
    if ($select_item_1 == '' ) {
       $select_item_1='&nbsp;';
    }
    echo "<td>$select_item_1</td>";
    echo "<td>$select_item_2</td>";
    echo "</tr>";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td><td>\n";
 $query = 'SELECT name, count FROM `counters` where name=\'c\' order by  count,name';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 $query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query);
 $query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query</td></tr>";
 $rows=mysql_num_rows($result);
 echo "<tr><td colspan=2>rows=$rows<p></td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr><td colspan=2>Crude and Dirty Way</td></tr>";
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
    echo "<tr><td colspan=2>PERL Way</td></tr>";
    echo "<tr>";
    #
    # clean - get the hash items we want and print them
    #
    $select_item_1=$line['name'];  # 'name' is the value selected 
    $select_item_2=$line['count']; # 'count' is the value selected
    if ($select_item_1 == '' ) {
       $select_item_1='&nbsp;';
    }
    echo "<td>$select_item_1</td>";
    echo "<td>$select_item_2</td>";
    echo "</tr>";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td></tr>\n";
 echo "</table>\n";
 #
 # close the SQL connection
 #
 // Closing connection
 mysql_close($link);
</script> 

../sql_stuff/sql_select_like_perl.php

TOC

<script language="php">
 #
 # this include file has the passwords and 
 # database names defined in it  
 #
 require('../sql_passwords.php');
 echo "<h1>SQL select statements</h1>\n";
 #
 # connect to SQL
 #
 $link = mysql_connect($z_hardcoded_sqlurl, 
                       $z_hardcoded_database, 
                       $z_hardcoded_password )
                       or die('Could not connect: ' . mysql_error());
 #
 # select the database I want to use
 #
 mysql_select_db($z_hardcoded_database) or die('Could not select database');
 echo "<table border=0>\n";




 echo "<tr><td>\n";
 #
 # select some stuff from the database
 #
 $query = 'SELECT name, count FROM `counters` ';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query<p></td></tr>";
 #
 # get the number of rows this query returned
 #
 $rows=mysql_num_rows($result);
 echo "<tr><td colspan=2>rows=$rows<p></td></tr>";
 #
 # basicly $line is a PERL hash 
 #
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    #
    # dump $line which is an hash array which gets the selected data
    #
    #echo "<tr><td colspan=2>";
    #var_dump($line);
    #echo "</td></tr>";
    echo "<tr><td colspan=2>Crude and Dirty Way</td></tr>";
    echo "<tr>\n";
    #
    # crude and dirty - loop thru the hash
    #
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
    echo "<tr><td colspan=2>PERL Way</td></tr>";
    echo "<tr>";
    #
    # clean - get the hash items we want and print them
    #
    $select_item_1=$line['name'];  # 'name' is the value selected 
    $select_item_2=$line['count']; # 'count' is the value selected
    if ($select_item_1 == '' ) {
       $select_item_1='&nbsp;';
    }
    echo "<td>$select_item_1</td>";
    echo "<td>$select_item_2</td>";
    echo "</tr>";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td><td>\n";
 

 $query = 'SELECT name, count FROM `counters` order by name, count';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 $query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query</td></tr>";
 $rows=mysql_num_rows($result);
 echo "<tr><td colspan=2>rows=$rows<p></td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr><td colspan=2>Crude and Dirty Way</td></tr>";
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
    echo "<tr><td colspan=2>PERL Way</td></tr>";
    echo "<tr>";
    #
    # clean - get the hash items we want and print them
    #
    $select_item_1=$line['name'];  # 'name' is the value selected 
    $select_item_2=$line['count']; # 'count' is the value selected
    if ($select_item_1 == '' ) {
       $select_item_1='&nbsp;';
    }
    echo "<td>$select_item_1</td>";
    echo "<td>$select_item_2</td>";
    echo "</tr>";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td><td>\n";
 $query = 'SELECT name, count FROM `counters` order by  count,name';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 $query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query</td></tr>";
 $rows=mysql_num_rows($result);
 echo "<tr><td colspan=2>rows=$rows<p></td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr><td colspan=2>Crude and Dirty Way</td></tr>";
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
    echo "<tr><td colspan=2>PERL Way</td></tr>";
    echo "<tr>";
    #
    # clean - get the hash items we want and print them
    #
    $select_item_1=$line['name'];  # 'name' is the value selected 
    $select_item_2=$line['count']; # 'count' is the value selected
    if ($select_item_1 == '' ) {
       $select_item_1='&nbsp;';
    }
    echo "<td>$select_item_1</td>";
    echo "<td>$select_item_2</td>";
    echo "</tr>";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td></tr>\n";
 echo "<tr><td>\n";
 #
 # select some stuff from the database
 #
 $query = 'SELECT name, count FROM `counters` where name like \'c%\' ';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from /i', '<br>&nbsp;from ', $query);
 $query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query);
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query<p></td></tr>";
 $rows=mysql_num_rows($result);
 echo "<tr><td colspan=2>rows=$rows<p></td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr><td colspan=2>Crude and Dirty Way</td></tr>";
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
    echo "<tr><td colspan=2>PERL Way</td></tr>";
    echo "<tr>";
    #
    # clean - get the hash items we want and print them
    #
    $select_item_1=$line['name'];  # 'name' is the value selected 
    $select_item_2=$line['count']; # 'count' is the value selected
    if ($select_item_1 == '' ) {
       $select_item_1='&nbsp;';
    }
    echo "<td>$select_item_1</td>";
    echo "<td>$select_item_2</td>";
    echo "</tr>";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td><td>\n";
 $query = 'SELECT name, count FROM `counters`  where name like \'c%\' order by name,  count';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 $query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query);
 $query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query</td></tr>";
 $rows=mysql_num_rows($result);
 echo "<tr><td colspan=2>rows=$rows<p></td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr><td colspan=2>Crude and Dirty Way</td></tr>";
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
    echo "<tr><td colspan=2>PERL Way</td></tr>";
    echo "<tr>";
    #
    # clean - get the hash items we want and print them
    #
    $select_item_1=$line['name'];  # 'name' is the value selected 
    $select_item_2=$line['count']; # 'count' is the value selected
    if ($select_item_1 == '' ) {
       $select_item_1='&nbsp;';
    }
    echo "<td>$select_item_1</td>";
    echo "<td>$select_item_2</td>";
    echo "</tr>";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td><td>\n";
 $query = 'SELECT name, count FROM `counters` where name like \'c%\' order by   count,name';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 $query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query);
 $query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query</td></tr>";
 $rows=mysql_num_rows($result);
 echo "<tr><td colspan=2>rows=$rows<p></td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr><td colspan=2>Crude and Dirty Way</td></tr>";
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
    echo "<tr><td colspan=2>PERL Way</td></tr>";
    echo "<tr>";
    #
    # clean - get the hash items we want and print them
    #
    $select_item_1=$line['name'];  # 'name' is the value selected 
    $select_item_2=$line['count']; # 'count' is the value selected
    if ($select_item_1 == '' ) {
       $select_item_1='&nbsp;';
    }
    echo "<td>$select_item_1</td>";
    echo "<td>$select_item_2</td>";
    echo "</tr>";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td></tr>\n";
 echo "<tr><td>\n";
 #
 # select some stuff from the database
 #
 $query = 'SELECT name, count FROM `counters` where name=\'c\' ';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from /i', '<br>&nbsp;from ', $query);
 $query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query); 
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query<p></td></tr>";
 $rows=mysql_num_rows($result);
 echo "<tr><td colspan=2>rows=$rows<p></td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr><td colspan=2>Crude and Dirty Way</td></tr>";
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
    echo "<tr><td colspan=2>PERL Way</td></tr>";
    echo "<tr>";
    #
    # clean - get the hash items we want and print them
    #
    $select_item_1=$line['name'];  # 'name' is the value selected 
    $select_item_2=$line['count']; # 'count' is the value selected
    if ($select_item_1 == '' ) {
       $select_item_1='&nbsp;';
    }
    echo "<td>$select_item_1</td>";
    echo "<td>$select_item_2</td>";
    echo "</tr>";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td><td>\n";
 $query = 'SELECT name, count FROM `counters`  where name=\'c\' order by name, count';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 $query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query);
 $query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query</td></tr>";
 $rows=mysql_num_rows($result);
 echo "<tr><td colspan=2>rows=$rows<p></td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr><td colspan=2>Crude and Dirty Way</td></tr>";
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
    echo "<tr><td colspan=2>PERL Way</td></tr>";
    echo "<tr>";
    #
    # clean - get the hash items we want and print them
    #
    $select_item_1=$line['name'];  # 'name' is the value selected 
    $select_item_2=$line['count']; # 'count' is the value selected
    if ($select_item_1 == '' ) {
       $select_item_1='&nbsp;';
    }
    echo "<td>$select_item_1</td>";
    echo "<td>$select_item_2</td>";
    echo "</tr>";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td><td>\n";
 $query = 'SELECT name, count FROM `counters` where name=\'c\' order by  count,name';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 $query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query);
 $query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query</td></tr>";
 $rows=mysql_num_rows($result);
 echo "<tr><td colspan=2>rows=$rows<p></td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr><td colspan=2>Crude and Dirty Way</td></tr>";
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
    echo "<tr><td colspan=2>PERL Way</td></tr>";
    echo "<tr>";
    #
    # clean - get the hash items we want and print them
    #
    $select_item_1=$line['name'];  # 'name' is the value selected 
    $select_item_2=$line['count']; # 'count' is the value selected
    if ($select_item_1 == '' ) {
       $select_item_1='&nbsp;';
    }
    echo "<td>$select_item_1</td>";
    echo "<td>$select_item_2</td>";
    echo "</tr>";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td></tr>\n";
 echo "</table>\n";
 #
 # close the SQL connection
 #
 // Closing connection
 mysql_close($link);
</script> 

../sql_stuff/sql_update.php

TOC

<script language="php">
 #
 # this include file has the passwords and 
 # database names defined in it  
 #
 require('../sql_passwords.php');
 echo "<h1>SQL select &amp; update statements</h1>\n";
 #
 # connect to SQL
 #
 $link = mysql_connect($z_hardcoded_sqlurl, 
                       $z_hardcoded_database, 
                       $z_hardcoded_password )
                       or die('Could not connect: ' . mysql_error());
 #
 # select the database I want to use
 #
 mysql_select_db($z_hardcoded_database) or die('Could not select database');
 echo "<table border=0>\n";
 echo "<tr><td>\n";
 #
 # select some stuff from the database
 #
 $query = 'SELECT name, count FROM `counters` ';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td><td>\n";
 $query = 'SELECT count FROM `counters` where name=\'test\'';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 $query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query);
 $query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query</td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
        $nextval=$col_value;
    }
    echo "</tr>\n";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td></tr>\n";
 #
 # add 1 to the counter
 #
 # update the counter value
 #
 $nextval=$nextval+1;
 $query = 'update `counters` set count='.$nextval.' WHERE name=\'test\'';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 #
 # display the table with the updated value
 #
 echo "<tr><td>\n";
 echo "</td><td>\n";
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 $query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query);
 $query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query</td></tr>";
 echo "</table>\n";
 echo "</td></tr>\n";
 echo "<tr><td>\n";
 #
 # select some stuff from the database
 #
 $query = 'SELECT name, count FROM `counters` ';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td><td>\n";
 $query = 'SELECT count FROM `counters` where name=\'test\'';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 $query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query);
 $query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query</td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);
 echo "</td></tr>\n";
 echo "</table>\n";
 #
 # close the SQL connection
 #
 // Closing connection
 mysql_close($link);
</script> 

temporary_file.php

TOC

<h1>Create a temporary_file in /tmp</h1>
<h2>How not to do it!</h2>
This two lines of code both blow up with the error 
<blockquote>
$file=tempnam();<br>
$file=tempnam('/tmp');
</blockquote>
blows up with
<blockquote>
Wrong parameter count for tempnam()
</blockquote>
<h2>How to do it!</h2>
This code creates a temporary file in /tmp
with a prefix of "stuff-"
<blockquote>
$file=tempnam('/tmp','stuff-');
</blockquote>
and generates this file name
<blockquote>
<?php
#
# create a temp file in /tmp 
# create a temporary file in /tmp 
# with a preffix of stuff-
#
$file=tempnam('/tmp','stuff-');
echo "temporary file=$file<br>";
?>
</blockquote>
<h2>Write to the temporary file</h2>
This code opens the file.
<br>
Writes some data to it.
<br>
Then closes the file.
<br>
And finally deletes the file.
<blockquote>
<tt>
<pre>
#
# open the file for writting
#
$handle = fopen($file, "w");
#
# write some stuff to the temporary file
#
$data="some stupid data to write to the temp file\n\nmore stinking data\n";
$data.="some MORE data to write to the file";
$bytes_written=fwrite($handle, $data);
#
# tell how many bytes we wrote to the file
#
echo "we wrote $bytes_written bytes to the file<p>";
echo "This is the data we wrote to the file";
echo "&lt; blockquote&gt;";
echo "&lt;pre&gt;";
echo $data;
echo "&lt;/pre&gt;";
echo "&lt;/blockquote&gt;";
#
# close the stinking temp or temporary file
#
fclose($handle);
#
# now delete the temp or temporary file 
#
unlink($file);
</pre>
</tt>
</blockquote>
<?php
#
# open the file for writting
#
$handle = fopen($file, "w");
#
# write some stuff to the temporary file
#
$data="some stupid data to write to the temp file\n\nmore stinking data\n";
$data.="some MORE data to write to the file";
$bytes_written=fwrite($handle, $data);
#
# tell how many bytes we wrote to the file
#
echo "we wrote $bytes_written bytes to the file<p>";
echo "This is the data we wrote to the file";
echo "<blockquote>";
echo "<pre>";
echo $data;
echo "</pre>";
echo "</blockquote>";
#
# close the stinking temp or temporary file
#
fclose($handle);
#
# now delete the temp or temporary file 
#
unlink($file);
?>
<h2>Create a temp file or temporary file with an unknow name</h2>
This code creates a file handle for a temp or temporary file.
<blockquote>
<tt>
#<br>
#&nbsp;create&nbsp;the&nbsp;temporary&nbsp;file<br>
#<br>
$temp&nbsp;=&nbsp;tmpfile();<br>
<br>
echo&nbsp;"file&nbsp;handle=$temp&lt;br&gt;";<br>
#<br>
#&nbsp;write&nbsp;to&nbsp;the&nbsp;temporary&nbsp;file<br>
#<br>
$bytes_written=fwrite($temp,&nbsp;$data);<br>
echo&nbsp;"we&nbsp;wrote&nbsp;$bytes_written&nbsp;bytes&nbsp;to&nbsp;the&nbsp;file&lt;p&gt;";<br>
#<br>
#&nbsp;rewind&nbsp;the&nbsp;file&nbsp;so&nbsp;we&nbsp;can&nbsp;read&nbsp;the&nbsp;data&nbsp;we&nbsp;wrote<br>
#<br>
fseek($temp,&nbsp;0);<br>
#<br>
#&nbsp;read&nbsp;the&nbsp;data&nbsp;we&nbsp;wrote<br>
#<br>
$bytes_to_read=$bytes_written;<br>
$dataread=fread($temp,&nbsp;$bytes_to_read);<br>
#<br>
#&nbsp;print&nbsp;the&nbsp;data&nbsp;we&nbsp;wrote<br>
#<br>
echo&nbsp;"This&nbsp;is&nbsp;the&nbsp;data&nbsp;we&nbsp;wrote,&nbsp;and&nbsp;just&nbsp;read&nbsp;back&nbsp;from&nbsp;the&nbsp;file";<br>
echo&nbsp;"&lt;blockquote&gt;";<br>
echo&nbsp;"&lt;pre&gt;";<br>
echo&nbsp;$dataread;<br>
echo&nbsp;"&lt;/pre&gt;";<br>
echo&nbsp;"&lt;/blockquote&gt;";<br>
#<br>
#&nbsp;close&nbsp;and&nbsp;delete&nbsp;the&nbsp;temp&nbsp;file<br>
#<br>
fclose($temp);&nbsp;//&nbsp;this&nbsp;removes&nbsp;the&nbsp;file<br>
</tt>
</blockquote>
Now we run the stinking code
<p>
<?php
#
# create the temporary file
#
$temp = tmpfile();

echo "file handle=$temp<br>";
#
# write to the temporary file
#
$bytes_written=fwrite($temp, $data);
echo "we wrote $bytes_written bytes to the file<p>";
#
# rewind the file so we can read the data we wrote
#
fseek($temp, 0);
#
# read the data we wrote
#
$bytes_to_read=$bytes_written;
$dataread=fread($temp, $bytes_to_read);
#
# print the data we wrote
#
echo "This is the data we wrote, and just read back from the file";
echo "<blockquote>";
echo "<pre>";
echo $dataread;
echo "</pre>";
echo "</blockquote>";
#
# close and delete the temp file
#
fclose($temp); // this removes the file
?> 
<h2>Create an image file in /tmp image file and let YOU view it</h2>
<h3>I'm pissed! You can't view the file</h3>
I am unhappy because while the code works
you CAN'T view the file on /tmp/xxx.
I figured if I set the permissions right you would
be able to see it.
<p>
The next set of code that follows works and instead of 
creating the file in /tmp it creates it in my area.
<p>
We are going to
<ol>
<li>Create a temporary file
<li>Copy an image to it from<br>&nbsp;&nbsp;&nbsp;images_for_counters/0.gif
<li>Create a link in the subdirectory<br>&nbsp;&nbsp;&nbsp;temporary_image_file_links
<li>Create a link on this page that lets you view image
</ol>
The code follows
<blockquote>
<tt>
#<br>
#&nbsp;create&nbsp;a&nbsp;temp&nbsp;file&nbsp;in&nbsp;/tmp&nbsp;<br>
#&nbsp;and&nbsp;a&nbsp;temp&nbsp;one&nbsp;in&nbsp;./temporary_image_file_links<br>
#<br>
$file=tempnam('/tmp','stuff-');<br>
#<br>
#&nbsp;lets&nbsp;try&nbsp;to&nbsp;rename&nbsp;it&nbsp;as&nbsp;.jpg<br>
#&nbsp;and&nbsp;see&nbsp;if&nbsp;that&nbsp;works<br>
#<br>
rename($file,&nbsp;$file.".jpg");<br>
$file=$file.".jpg";<br>
$link=tempnam("./temporary_image_file_links",'image-');<br>
#<br>
#&nbsp;now&nbsp;my&nbsp;file&nbsp;and&nbsp;make&nbsp;it&nbsp;a&nbsp;link&nbsp;to&nbsp;the&nbsp;file&nbsp;in&nbsp;/tmp&nbsp;<br>
#<br>
unlink($link);<br>
$link=$link.".jpg";<br>
if&nbsp;(0)&nbsp;{<br>
&nbsp;&nbsp;&nbsp;#<br>
&nbsp;&nbsp;&nbsp;#&nbsp;damn&nbsp;we&nbsp;cant&nbsp;create&nbsp;a&nbsp;link&nbsp;cuz&nbsp;they&nbsp;are<br>
&nbsp;&nbsp;&nbsp;#&nbsp;on&nbsp;different&nbsp;disks<br>
&nbsp;&nbsp;&nbsp;#<br>
&nbsp;&nbsp;&nbsp;$rc=link($file,&nbsp;$link);<br>
}<br>
else&nbsp;{<br>
&nbsp;&nbsp;&nbsp;#<br>
&nbsp;&nbsp;&nbsp;#&nbsp;but&nbsp;we&nbsp;can&nbsp;create&nbsp;a&nbsp;symbolic&nbsp;link!<br>
&nbsp;&nbsp;&nbsp;#<br>
&nbsp;&nbsp;&nbsp;$rc=symlink($file,&nbsp;$link);<br>
<br>
}<br>
echo&nbsp;"link&nbsp;rc=$rc&lt;p&gt;";<br>
$rc=`chmod&nbsp;666&nbsp;$file`;<br>
echo&nbsp;"chmod&nbsp;$file=$rc&lt;br&gt;";<br>
$rc=`chmod&nbsp;666&nbsp;$link`;<br>
echo&nbsp;"chmod&nbsp;$link&nbsp;=$rc&lt;br&gt;";<br>
echo&nbsp;"temporary&nbsp;file=$file&lt;br&gt;";<br>
#<br>
#&nbsp;read&nbsp;in&nbsp;this&nbsp;image&nbsp;file&nbsp;<br>
#&nbsp;it&nbsp;is&nbsp;a&nbsp;picture&nbsp;of&nbsp;the&nbsp;number&nbsp;zero<br>
#<br>
$data=file_get_contents("../images_for_counters/0.gif");<br>
#<br>
#&nbsp;write&nbsp;the&nbsp;gif&nbsp;to&nbsp;the&nbsp;/tmp&nbsp;file<br>
#<br>
$byteswritten=file_put_contents&nbsp;($file,$data);<br>
echo&nbsp;"we&nbsp;wrote&nbsp;$byteswritten&nbsp;bytes&nbsp;to&nbsp;$file&lt;br&gt;";<br>
#$byteswritten=file_put_contents&nbsp;($link,$data);<br>
#echo&nbsp;"we&nbsp;wrote&nbsp;$byteswritten&nbsp;bytes&nbsp;to&nbsp;$link&lt;br&gt;";<br>
#<br>
#&nbsp;how&nbsp;many&nbsp;bytes&nbsp;did&nbsp;we&nbsp;write<br>
#<br>
echo&nbsp;"we&nbsp;wrote&nbsp;$byteswritten&nbsp;bytes&nbsp;to&nbsp;$file&lt;br&gt;";<br>
echo&nbsp;"link&nbsp;file=$link&lt;p&gt;";<br>
echo&nbsp;"View&nbsp;the&nbsp;image&nbsp;by&nbsp;itself&nbsp;&lt;a&nbsp;href=\"$link\"&gt;&nbsp;here&lt;/a&gt;";<br>
echo&nbsp;"&lt;blockquote&gt;";<br>
echo&nbsp;"&lt;img&nbsp;src=\"$link\"&nbsp;alt=\"\the&nbsp;file&nbsp;is&nbsp;really&nbsp;here&nbsp;$file\"&gt;";<br>
echo&nbsp;"&lt;/blockquote&gt;";<br>
$rc=`ls&nbsp;-l&nbsp;$link`;<br>
echo&nbsp;"$rc&lt;br&gt;";<br>
$rc=`ls&nbsp;-l&nbsp;$file`;<br>
echo&nbsp;"$rc&lt;br&gt;";<br>
#<br>
#&nbsp;delete&nbsp;the&nbsp;2&nbsp;files&nbsp;so&nbsp;they&nbsp;won't&nbsp;effect&nbsp;my&nbsp;next&nbsp;example<br>
#<br>
unlink($file);<br>
unlink($link);<br>
</tt>
</blockquote>
The output of this code follows
<blockquote>
<?php
#
# create a temp file in /tmp 
# and a temp one in ./temporary_image_file_links
#
$file=tempnam('/tmp','stuff-');
#
# lets try to rename it as .jpg
# and see if that works
#
rename($file, $file.".jpg");
$file=$file.".jpg";
$link=tempnam("./temporary_image_file_links",'image-');
#
# now my file and make it a link to the file in /tmp 
#
unlink($link);
$link=$link.".jpg";
if (0) {
   #
   # damn we cant create a link cuz they are
   # on different disks
   #
   $rc=link($file, $link);
}
else {
   #
   # but we can create a symbolic link!
   #
   $rc=symlink($file, $link);

}
echo "link rc=$rc<p>";
$rc=`chmod 666 $file`;
echo "chmod $file=$rc<br>";
$rc=`chmod 666 $link`;
echo "chmod $link =$rc<br>";
echo "temporary file=$file<br>";
#
# read in this image file 
# it is a picture of the number zero
#
$data=file_get_contents("../images_for_counters/0.gif");
#
# write the gif to the /tmp file
#
$byteswritten=file_put_contents ($file,$data);
echo "we wrote $byteswritten bytes to $file<br>";
#$byteswritten=file_put_contents ($link,$data);
#echo "we wrote $byteswritten bytes to $link<br>";
#
# how many bytes did we write
#
echo "we wrote $byteswritten bytes to $file<br>";
echo "link file=$link<p>";
echo "View the image by itself <a href=\"$link\"> here</a>";
echo "<blockquote>";
echo "<img src=\"$link\" alt=\"\the file is really here $file\">";
echo "</blockquote>";
$rc=`ls -l $link`;
echo "$rc<br>";
$rc=`ls -l $file`;
echo "$rc<br>";
#
# delete the 2 files so they won't effect my next example
#
unlink($file);
unlink($link);
?>
</blockquote>
<h2>Create an image file in ./temporary_image_file_links image file and let YOU view it</h2>
We are going to
<ol>
<li>Create a temporary file
<li>Copy an image to it from<br>&nbsp;&nbsp;&nbsp;images_for_counters/0.gif
<li>Create a link on this page that lets you view image
</ol>
Here is the code that does this
<blockquote>



<tt>
#&nbsp;<br>
#&nbsp;and&nbsp;a&nbsp;real&nbsp;file&nbsp;in&nbsp;./temporary_image_file_links<br>
#&nbsp;i&nbsp;dont&nbsp;want&nbsp;to&nbsp;do&nbsp;this&nbsp;so&nbsp;create&nbsp;one&nbsp;file&nbsp;for&nbsp;all<br>
#&nbsp;all&nbsp;web&nbsp;requests!<br>
#<br>
$use_temporary_file=1;<br>
if&nbsp;($use_temporary_file)&nbsp;{<br>
&nbsp;&nbsp;$file=tempnam("./temporary_image_file_links",'image-');<br>
}<br>
else&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;$file="./temporary_image_file_links/stinking";<br>
}<br>
#<br>
#&nbsp;rename&nbsp;the&nbsp;file&nbsp;so&nbsp;the&nbsp;browser&nbsp;thinks&nbsp;its&nbsp;an&nbsp;image&nbsp;file<br>
#&nbsp;print&nbsp;an&nbsp;error&nbsp;message&nbsp;cuz&nbsp;sometimes&nbsp;I&nbsp;use&nbsp;a&nbsp;static&nbsp;file<br>
#<br>
$rc=@rename($file,&nbsp;"{$file}.jpg");<br>
$file=$file.".jpg";<br>
#<br>
#&nbsp;dump&nbsp;the&nbsp;file&nbsp;name<br>
#<br>
echo&nbsp;"temporary&nbsp;file=$file&lt;br&gt;";<br>
#<br>
#&nbsp;read&nbsp;in&nbsp;this&nbsp;image&nbsp;file&nbsp;<br>
#&nbsp;it&nbsp;is&nbsp;a&nbsp;picture&nbsp;of&nbsp;the&nbsp;number&nbsp;zero<br>
#<br>
$data=file_get_contents("../images_for_counters/0.gif");<br>
#<br>
#&nbsp;write&nbsp;the&nbsp;gif&nbsp;to&nbsp;the&nbsp;/tmp&nbsp;file<br>
#<br>
$byteswritten=file_put_contents&nbsp;($file,$data);<br>
#<br>
#&nbsp;how&nbsp;many&nbsp;bytes&nbsp;did&nbsp;we&nbsp;write<br>
#<br>
echo&nbsp;"we&nbsp;wrote&nbsp;$byteswritten&nbsp;bytes&nbsp;to&nbsp;$file&lt;br&gt;";<br>
#<br>
#&nbsp;make&nbsp;the&nbsp;file&nbsp;a&nbsp;666<br>
#&nbsp;<br>
$rc=`chmod&nbsp;666&nbsp;$file`;<br>
echo&nbsp;"chmod&nbsp;$file=$rc&lt;br&gt;";<br>
#<br>
#&nbsp;let&nbsp;them&nbsp;click&nbsp;on&nbsp;the&nbsp;image<br>
#<br>
echo&nbsp;"View&nbsp;the&nbsp;image&nbsp;by&nbsp;itself&nbsp;&lt;a&nbsp;href=\"$file\"&gt;&nbsp;here&lt;/a&gt;";<br>
echo&nbsp;"&lt;blockquote&gt;";<br>
echo&nbsp;"&lt;img&nbsp;src=\"$file\"&gt;";<br>
echo&nbsp;"&lt;/blockquote&gt;";<br>
#<br>
#&nbsp;for&nbsp;debugging&nbsp;list&nbsp;out&nbsp;the&nbsp;file&nbsp;and&nbsp;its&nbsp;permissions<br>
#<br>
$rc=`ls&nbsp;-l&nbsp;$file`;<br>
echo&nbsp;"$rc&lt;br&gt;";<br>
</tt>








</blockquote>
And here is the output of the above code
<blockquote>
<?php

# and a real file in ./temporary_image_file_links
# i dont want to do this so create one file for all
# all web requests!
#
$use_temporary_file=0;
if ($use_temporary_file) {
  $file=tempnam("./temporary_image_file_links",'image-');
}
else {
    $file="./temporary_image_file_links/stinking";
}
#
# rename the file so the browser thinks its an image file
# print an error message cuz sometimes I use a static file
#
$rc=@rename($file, "{$file}.jpg");
$file=$file.".jpg";
#
# dump the file name
#
echo "temporary file=$file<br>";
#
# read in this image file 
# it is a picture of the number zero
#
$data=file_get_contents("../images_for_counters/0.gif");
#
# write the gif to the /tmp file
#
$byteswritten=file_put_contents ($file,$data);
#
# how many bytes did we write
#
echo "we wrote $byteswritten bytes to $file<br>";
#
# make the file a 666

$rc=`chmod 666 $file`;
echo "chmod $file=$rc<br>";
#
# let them click on the image
#
echo "View the image by itself <a href=\"$file\"> here</a>";
echo "<blockquote>";
echo "<img src=\"$file\">";
echo "</blockquote>";
#
# for debugging list out the file and its permissions
#
$rc=`ls -l $file`;
echo "$rc<br>";
?>
</blockquote>
And last but not least do this code
some of which seems to be disabled
at this site and not work!
<blockquote>
<tt>
set_time_limit(30);<br>
#<br>
#&nbsp;flush&nbsp;the&nbsp;buffers&nbsp;so&nbsp;they&nbsp;get&nbsp;the&nbsp;output<br>
#<br>
flush();<br>
#<br>
#&nbsp;sleep&nbsp;for&nbsp;1&nbsp;second&nbsp;so&nbsp;their&nbsp;browser&nbsp;has&nbsp;a&nbsp;chance&nbsp;to&nbsp;get&nbsp;the&nbsp;file<br>
$rc=sleep(1);<br>
echo&nbsp;"$rc";<br>
flush();<br>
sleep(1);<br>
echo&nbsp;"$rc";<br>
flush();<br>
usleep(1000000);<br>
echo&nbsp;".";<br>
flush();<br>
usleep(1000000);<br>
echo&nbsp;".";<br>
flush();<br>
usleep(1000000);<br>
echo&nbsp;".";<br>
flush();<br>
usleep(1000000);<br>
echo&nbsp;".";<br>
flush();<br>
usleep(1000000);<br>
echo&nbsp;".";<br>
flush();<br>
usleep(1000000);<br>
echo&nbsp;".";<br>
flush();<br>
echo&nbsp;"the&nbsp;sleeps&nbsp;aint&nbsp;working&lt;br&gt;";<br>
sleep(5);<br>
#<br>
#&nbsp;hey&nbsp;since&nbsp;the&nbsp;waits&nbsp;and&nbsp;sleeps()&nbsp;aint&nbsp;working<br>
#&nbsp;lets&nbsp;do&nbsp;some&nbsp;work&nbsp;to&nbsp;generate&nbsp;a&nbsp;real&nbsp;wait!<br>
#&nbsp;read&nbsp;in&nbsp;the&nbsp;mp3&nbsp;file&nbsp;from&nbsp;a&nbsp;remote&nbsp;site<br>
#&nbsp;should&nbsp;cause&nbsp;us&nbsp;to&nbsp;do&nbsp;a&nbsp;wait<br>
#<br>
#http://la.indymedia.org/uploads/2007/11/wga-strk-2.mp3<br>
#<br>
echo&nbsp;"banging&nbsp;on&nbsp;LA&nbsp;Indy&nbsp;Media&lt;br&gt;";<br>
flush();<br>
$data=file_get_contents("http://la.indymedia.org/uploads/2007/11/wga-strk-2.mp3");<br>
echo&nbsp;"Done&nbsp;banging&nbsp;on&nbsp;LA&nbsp;Indy&nbsp;Media!!!&lt;br&gt;";<br>
flush();<br>
echo&nbsp;"banging&nbsp;on&nbsp;LA&nbsp;Indy&nbsp;Media&lt;br&gt;";<br>
flush();<br>
$data=file_get_contents("http://la.indymedia.org/uploads/2007/11/wga-strk-2.mp3");<br>
echo&nbsp;"Done&nbsp;banging&nbsp;on&nbsp;LA&nbsp;Indy&nbsp;Media!!!&lt;br&gt;";<br>
flush();<br>
echo&nbsp;"banging&nbsp;on&nbsp;LA&nbsp;Indy&nbsp;Media&lt;br&gt;";<br>
flush();<br>
$data=file_get_contents("http://la.indymedia.org/uploads/2007/11/wga-strk-2.mp3");<br>
$b=strlen($data);<br>
echo&nbsp;"Done&nbsp;banging&nbsp;$b&nbsp;bytes&nbsp;on&nbsp;LA&nbsp;Indy&nbsp;Media!!!&lt;br&gt;";<br>
flush();<br>
#<br>
#&nbsp;delete&nbsp;the&nbsp;file&nbsp;so&nbsp;it&nbsp;doesn't&nbsp;waste&nbsp;space<br>
#<br>
if&nbsp;($use_temporary_file)&nbsp;{<br>
&nbsp;&nbsp;&nbsp;unlink($file);<br>
}<br>
</tt>
</blockquote>
The output from this code follows
<blockquote>
<?php
set_time_limit(30);
#
# flush the buffers so they get the output
#
flush();
#
# sleep for 1 second so their browser has a chance to get the file
$rc=sleep(1);
echo "$rc";
flush();
sleep(1);
echo "$rc";
flush();
usleep(1000000);
echo ".";
flush();
usleep(1000000);
echo ".";
flush();
usleep(1000000);
echo ".";
flush();
usleep(1000000);
echo ".";
flush();
usleep(1000000);
echo ".";
flush();
usleep(1000000);
echo ".";
flush();
echo "the sleeps aint working<br>";
sleep(5);
#
# hey since the waits and sleeps() aint working
# lets do some work to generate a real wait!
# read in the mp3 file from a remote site
# should cause us to do a wait
#
#http://la.indymedia.org/uploads/2007/11/wga-strk-2.mp3
#
echo "banging on LA Indy Media<br>";
flush();
$data=file_get_contents("http://la.indymedia.org/uploads/2007/11/wga-strk-2.mp3");
echo "Done banging on LA Indy Media!!!<br>";
flush();
echo "banging on LA Indy Media<br>";
flush();
$data=file_get_contents("http://la.indymedia.org/uploads/2007/11/wga-strk-2.mp3");
echo "Done banging on LA Indy Media!!!<br>";
flush();
echo "banging on LA Indy Media<br>";
flush();
$data=file_get_contents("http://la.indymedia.org/uploads/2007/11/wga-strk-2.mp3");
$b=strlen($data);
echo "Done banging $b bytes on LA Indy Media!!!<br>";
flush();
#
# delete the file so it doesn't waste space
#
if ($use_temporary_file) {
   unlink($file);
}
?>
</blockquote>

upload_files.php

TOC

<?php
setcookie("FancyxxxFrogFood","hoxxxt SPICY food",time()+333333);
setcookie("foxxxod","everybody loxxxxves food",time()+333333);
setcookie("notxxxenough","and noboxxxdy gets enough of it",time()+333333);
$set_cookie="si";
#
# this session id stuff is for people who refuse to use cookies
# it keeps track of them on the server side instead of with
# cookies on their PC.
# the session lasts until they close their browser window
#
$mysessionid=session_start();
#
# include a function to display the info 
# about the files we upload
#
include "dump_uploaded_file_info.php";
?>
<html>
<?php
function move_the_stinking_file ($filename) {
   #
   # get the PC or remote file name they
   # entered on netscape, mozilla, or internet explorer
   #
   $zfile=$_FILES[$filename]['name'];
   #
   # if a filename was uploaded copy it
   # from the 
   #          /tmp/xxx 
   # area to my area
   #          cgi-bin/webpages/
   #
   if ($zfile != '' ) {
      #
      # it can be executed rename it!!!!
      #
      $zfile=preg_replace("/\.(php|perl|cgi|sh|pl|exe|com|bat)\$/i",".txt",$zfile);
      #
      # remove spaces from the saved file
      # 
      $zfile=preg_replace("/ /","",$zfile); 
      #
      # if the file has a . in it
      # meaning it ends in .xxx 
      # make sure we only download suffixes
      # i think are legal
      # which are:
      #
      # gif jpg jpeg png doc txt html htm zip
      # 
      if (preg_match("/\./",$zfile)) { 
         #
         # does it end in a suffix i think is OK
         #
         if (preg_match("/\.(gif|jpg|jpeg|png|doc|txt|html|htm|zip)\$/i",$zfile)) {
            #
            # do nothing! its a legal suffix 
            #echo "its a legal dot file $zfile<br>";
         }
         else {
            #
            # i dont know about that suffix
            # change it to .txt so they cant
            # hackme
            #echo "its a illegal suffix $zfile<br>";
            $zfile=preg_replace("/\.[^\.]*\$/",".txt",$zfile); 
         }
      }
      #
      # does the file already exist?
      #
      $subdir='../cgi-bin/webpages/';
      if (file_exists($subdir.$zfile)) {
         $rename=0;
         #
         # loop till we find a flavor of the filename
         # that doesnt exist
         #
         while (file_exists($subdir.$rename.$zfile)) {
            $rename++;
         }
         #
         # make this the new file name
         #
         $zfile=$rename.$zfile;
      }
      #
      # add in the correct subdirectory to save the file in
      #
      #$zfile="../cgi-bin/webpages/".$zfile;
      $zfile=$subdir.$zfile;
      #
      # get the name of the unix file in the
      #       /tmp subdirectory
      # that must be moved to my subdirectory
      $unixtmpfile=$_FILES[$filename]['tmp_name']; 
      #echo "moving $unixtmpfile  to $zfile<br>";
      #
      # move the file from /tmp to my subdirectory
      #
      $rc=move_uploaded_file($unixtmpfile,$zfile);
      if ($rc != 1 ) {
         echo "<h1>ERROR move of $unixtmpfile  to $zfile FAILED</h1>";
      }
      #echo "rc=$rc<p>";
   }
   return;
}
#
# move the stinking files that were uploaded
# from /tmp/xxx to my subdirectory ../cgi/webfiles/xxx
#
move_the_stinking_file ('file1');
move_the_stinking_file ('file2');
move_the_stinking_file ('file3');
move_the_stinking_file ('file4');
?>






<table>
<tr valign="top">
<td  style="background-color:#00ffff;">
Upload Files To
<blockquote>
<a href="../cgi-bin/dumpfiles.php">cgi-bin/webpages/</a>
</blockquote>
<FORM action="upload_files.php" 
      method="post"
      enctype="multipart/form-data">
<INPUT type="submit" value="Upload Files"> 
<P>
<INPUT type="file" name="file1"><BR>
<INPUT type="file" name="file2"><BR>
<INPUT type="file" name="file3"><BR>
<INPUT type="file" name="file4">
<p>
<input type="reset" name=reset value="RESET">
</FORM>
</td>
<td>
<?php
    #
    # get the data from the form
    # and display the files we uploaded
    # each file is displayed as a table
    #
    echo "<td>";
    dump_uploaded_file_info('file1');
    echo "</td>";
    echo "<td>";
    dump_uploaded_file_info('file2');
    echo "</td>";
    echo "<td>";
    dump_uploaded_file_info('file3');
    echo "</td>";
    echo "<td>";
    dump_uploaded_file_info('file4');
    echo "</td>";
?>
</td>
</tr>
</table>
</html>

../curl_ftp_stuff/verbose.php

TOC

<p>
Pass 1
<p>
<?php
#
# i bet it is writting the debug info to STDERR
# and that is why i am not seeing it
#
# well tell it to write the STDERR to this file
# so i can view it
#
$debug_file="a_debug_file.txt";
echo "view debug output <a href=\"$debug_file\">$debug_file</a><br>";
$debug_file_handle=fopen($debug_file,'w');
$curl=curl_init();



curl_setopt($curl,CURLOPT_STDERR,$debug_file_handle);
curl_setopt($curl,CURLOPT_URL,"http://www.php.net");
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl,CURLOPT_VERBOSE ,1);
curl_exec($curl);
curl_close($curl);
fclose($debug_file_handle);
?>

<p>
Pass 0
<p>
<?php
#
# in this script we turn on 
#        VERBOSE
# for debugging
#
# in this script we dont login like we do in
#    ftp_to_gnu.php
# but we do get a list of the files in the 
# root directory
#
#
# initialize curl
#
$debug_file_handle=fopen($debug_file,'a');
$curl=curl_init();
#
# do a ftp to
#    ftp.gnu.org
#
curl_setopt($curl,CURLOPT_STDERR,$debug_file_handle);
curl_setopt($curl,CURLOPT_URL,"ftp://ftp.gnu.org");
#
# i think this says go get the data
#
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
#
# the VERBOSE doesnt work like it says in the manual
# because in the manual the dummys didnt say the 
# output goes to the STDERR!!!!
# the examples have it being mixed with the HTML
#
echo "VERBOSE goes to the STDERR file which is redirected to ";
echo "<a href=\"$debug_file\">$debug_file</a><p>";
#
# use this command to debut CURL stuff
# it makes curl become VERBOSE and 
# tell you about everything it does
#  1 to turn on VERBOSE
#  0 to turn off VERBOSE
#
curl_setopt($curl,CURLOPT_VERBOSE,1);
#
# i think this says run all the stuff we just defined
# and place the data received in $result
#
$result=curl_exec($curl);
curl_exec($curl);
#
# close curl
#
curl_close($curl);
fclose($debug_file_handle);
#
# print the data we got with the ftp to ftp.gnu.org
#
echo "<pre>";
print $result;
echo "</pre>";
#
# the first time i ran this the results looked like this
#
#     lrwxrwxrwx    1 0        0               8 Aug 20  2004 CRYPTO.README -> .message
#     -rw-r--r--    1 0        0           17864 Oct 23  2003 MISSING-FILES
#     -rw-r--r--    2 0        0            4178 Aug 13  2003 MISSING-FILES.README
#     -rw-r--r--    1 0        0            1765 Feb 20  2007 README
#     -rw-r--r--    1 0        0          405121 Oct 23  2003 before-2003-08-01.md5sums.asc
#     -rw-r--r--    1 0        0          145971 Jan 24 11:32 find.txt.gz
#     drwxrwxr-x  261 0        1003         8192 Jan 23 19:26 gnu
#     drwxrwxr-x    3 0        1003         4096 Sep 23  2004 gnu+linux-distros
#     -rw-r--r--    1 0        0              90 Feb 16  1993 lpf.README
#     -rw-r--r--    1 0        0          300599 Jan 24 11:32 ls-lrRt.txt.gz
#     drwxr-xr-x    3 0        0            4096 Apr 20  2005 mirrors
#     lrwxrwxrwx    1 0        0              11 Apr 15  2004 non-gnu -> gnu/non-gnu
#     drwxr-xr-x   43 0        0            4096 Jan 04 15:02 old-gnu
#     lrwxrwxrwx    1 0        0               1 Aug 05  2003 pub -> .
#     drwxr-xr-x    2 0        0            4096 Nov 08 17:46 savannah
#     drwxr-xr-x    2 0        0            4096 Aug 02  2003 third-party
#     -rw-r--r--    1 0        0             954 Aug 13  2003 welcome.msg
?>

whi.php

TOC

<h1 align="center">Why does " -&gt; \" and ' -&gt; \' and \ -&gt; \\</h1>
<h2 align="center">It's a PHP problem, not in PERL</h2>
<table width="100%">
<tr>
<td width="40%">
I have written many PERL programs
that grab data from forms and never
had any problems.
<p>
I was suprized when PHP forms
returned extra data when you entered
any of these characters
<ul>
<li>"
<li>'
<li>\
</ul>
In all cases the PHP programs would return
the character preceded with a '\' such as
<ul>
<li>\"
<li>\'
<li>\\
</ul>
So I wrote a program in PERL and a program in
PHP to find out why. Hence the program names
<a href="why.pl">why.pl</a>
and
<a href="why.php">why.php</a>
Any how it turns out that PHP handles
data input via forms differently then
PERL programs.
<p>
PHP programs for some reason prefix
each ", ', and \ input on a form
with a "\" turning them into
\", \', and \\.
<p>
This gets real annoying if you redisplay
the data on the form.
<p>
So I wrote a function to fix this problem
which is essentially to remove the extra
backslashes returned on data input via
PHP forms.
<p>
The function is
<blockquote>
clean_php_form_data()
</blockquote>
in
<blockquote>
clean_php_form_data.php
</blockquote>
and the code follows
<tt>
<blockquote>
<pre>
function clean_php_form_data($data) {
   #
   # for some reason when you enter the characters
   #     ", ', and \
   # into a PHP form they are returned as
   #     \", \', and \\
   #
   # well this function cleans up the data
   # and removes the annoying backslashes
   #
   # oddly data is NOT returned this way in PERL
   #
   $data=preg_replace('/\\\\\'/',"'",$data);
   $data=preg_replace('/\\\\\"/','"',$data);
   $data=preg_replace('/\\\\\\\\/',"\\",$data);
   return $data;
}
</pre>
</blockquote>
</tt>






</td>
<td>
&nbsp;
</td>
</tr>
</table>

whois_this_url.php

TOC

<?php
function process_ip_address_data ($data, $color) {
   echo "<blockquote style=\"background-color:$color\">";
   echo "<pre>";
   echo $data;
   echo "</pre>";
   echo "</blockquote>";
   return;
}
?>
<h3>Who owns a URL or an IP Address</h3>
&nbsp;&nbsp;&nbsp;<span style="font-size: 90%;"><b>Enter a URL or IP address and find out who owns it!</b></span>
<br>
<table style="font-size: 90%;">
<tr>
<td>
Examples of URLs are
<table cellspacing="0" cellpadding="0" border=0 style="font-size: 90%;">
<tr><td>&nbsp;&nbsp;&nbsp;<i>arizona.indymedia.org</i></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;<i>indymedia.org</i></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;<i>tempe.gov</i></td></tr>
</table>
</td>
<td>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</td>
<td>
Examples of IP addresses are
<table cellspacing="0" cellpadding="0" border=0 style="font-size: 90%;">
<tr><td>&nbsp;&nbsp;&nbsp;<i>208.69.42.131</i></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;<i>208.109.102.48</i></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;<i>72.32.107.184</i></td></tr>
</table>
</td>
</tr>
</table>
<form action="whois_this_url.php" method="post">
<input type="submit" name=submit value="Submit"> 
<input type="text" name="stinkingserver" size="100"
<?php 
#
# get the data from the form
#
$stinkingserver=$_POST['stinkingserver'];
#
# if no form data see if they 
# passed us data as a parm via GET
#
if ($stinkingserver == '') {
   $stinkingserver=$_GET['stinkingserver'];
}
#
# remove leading and trailing spaces from URL
#
$stinkingserver=preg_replace("/ */","",$stinkingserver);  
$stinkingserver=preg_replace("/ *\$/","",$stinkingserver);
#
# remove leading http:// and https://
#
$stinkingserver=preg_replace("/^https?:\/\//","",$stinkingserver);
echo "value=\"$stinkingserver\""; 
?>
>
</form>
<?php
#
# analyize the URL if a name was entered

if ($stinkingserver != '') {
   #
   # if they entered an IP address 
   # 
   if (preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\$/",$stinkingserver)) {
      #
      # convert the ip address to a name
      #
      $their_name=gethostbyaddr($stinkingserver);
      $their_ip_address=$stinkingserver;
   }
   else {
      #
      # convert the NAME to an IP address
      #
      $their_ip_address = gethostbyname ($stinkingserver);
      $their_name=$stinkingserver;
   } 
   #
   # do a whois on their URL
   #
   $krapola=`whois $their_name`;
   #
   # display the whois data on their URL
   #
   echo "<span style=\"background-color:#00ffff;\">URL=";
   echo "<a href=\"http://$their_name\">$their_name</a>";
   echo "</span><br>";
   process_ip_address_data($krapola,'#00ffff');
   #
   # do a whois on their IP address
   #
   $krapola=`whois $their_ip_address`;
   echo "<span style=\"background-color:#ffff00;\">IP=";
   echo "<a href=\"http://$their_ip_address\">$their_ip_address</a>";
   echo "</span><br>";
   process_ip_address_data($krapola,'#ffff00');
}
?>

why.php

TOC

<h1 align="center">Why does " -&gt; \" amd ' -&gt; \' and \ -&gt; \\</h1>
<h2 align="center">This is in PHP. Does the problem exist in PERL?</h2>
Well looks like I have fixed the problem!
The code that follows fixes everything
<blockquote>
<tt>
$text=preg_replace('/\\\\\'/',"'",$text);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;/\\'/ <br>
$text=preg_replace('/\\\\\"/','"',$text);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;/\\\"/<br>
$text=preg_replace('/\\\\\\\\/',"\\",$text);&nbsp;&nbsp;&nbsp;#&nbsp;/\\\\/
</tt>
</blockquote>
<?php
   $help=$_GET['help'];
   # 3) for some reason when you type in the data
   #    it converts " to \" 
   #            and ' to \'
   #            and \ to \\
   #    i dont know why it is doing this but i 
   #    have to fix it. 
   # set the default values for this program
   #
   $total_errors=0;
   $size=60;
   $rows=10;
   #
   # grab the data the user typed into the HTML form
   #
   $text=$_POST['text'];
?>
<?php 
   #
   # bingo!!! this fixes the problem of
   #    " -> \"
   #    ' -> \'
   #    \ -> \\
   #
   $text=preg_replace('/\\\\\'/',"'",$text);     # re is /\\'/ 
   $text=preg_replace('/\\\\\"/','"',$text);     # re is /\\\"/
   $text=preg_replace('/\\\\\\\\/',"\\",$text);  # re is /\\\\/ 
?>
<table style="background-color:#dddddd">
<tr valign="top">
<td>
<!-- form action="send_an_email.php" method="post" -->
<!-- make it a miltipart/form so we can upload files -->
<FORM action="why.php"  
      method="post" 
      enctype="multipart/form-data"> 
<table border="1">
<tr valign="top">
<td>
<input type="submit" name=submit value="Submit">
</td>
</tr>
</table>
<p>
<table>
<tr>
   <td colspan="2">
       <textarea name="text" 
       <?php echo "cols=\"$size\" rows=\"$rows\" "; ?>><?php 

            echo "$text"; 
       ?></textarea>  
   </td>
</tr>
</table>
<input type="reset" name=reset value="RESET">
</form>
</td>
</tr>
</table>

why.pl

TOC

#!/usr/bin/perl
#
# print header stuff
#
print "Content-type: text/html", "\n\n";
print "<html>\n";
print "<br>";
require CGI;
use CGI;
$cgi = new CGI;
#
# set the rows and columns in the <textarea> box
#
$size=60;
$rows=10;
#
# get the data they entered in the text box
#
$text=$cgi->param('text');
#
# a lazy way to enter HTML :)
#
$heredoc = <<THISSHOULDNTMATCHANYTHING;
<h1 align="center">Why does " -&gt; \" amd ' -&gt; \' and \ -&gt; \\</h1>
<h2 align="center">The problem doesn't exist in PERL. The problem DOES exist in PHP!</h2>
The problem doesn't seem to exist in PERL.
<p>
In PHP when you enter
<ul>
<li>'
<li>"
<li>\\
</ul>
on the form it gets passed back to PHP as
<ul>
<li>\'
<li>\"
<li>\\\\
</ul>
And if you redisplay the data it has that
extra \ it.
<p>
In PHP I fixed the problem by using these
3 statements to remove the extra \'s from
the data.
<blockquote>
<tt>
\$text=preg_replace('/\\\\\'/',"'",\$text);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;/\\'/ <br>
\$text=preg_replace('/\\\\\"/','"',\$text);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;/\\\"/<br>
\$text=preg_replace('/\\\\\\\\/',"\\",\$text);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;/\\\\/
</tt>
</blockquote>
<table style="background-color:#dddddd">
<tr valign="top">
<td>
<!-- form action="send_an_email.php" method="post" -->
<!-- make it a miltipart/form so we can upload files -->
<FORM action="why.pl"  
      method="post" 
      enctype="multipart/form-data"> 
<table border="1">
<tr valign="top">
<td>
<input type="submit" name=submit value="Submit">
</td>
</tr>
</table>
<p>
<table>
<tr>
   <td colspan="2">
THISSHOULDNTMATCHANYTHING
#
# display the HTML
#
print $heredoc;
#
# display the <textarea>
#
print "<textarea name=\"text\" cols=\"$size\" rows=\"$rows\">";
print $text;
print "</textarea>";
#
# build the ending HTML the lazy way :)
#
$heredoc = <<THISSHOULDNTMATCHANYTHING2;
   </td>
</tr>
</table>
<input type="reset" name=reset value="RESET">
</form>
</td>
</tr>
</table>
THISSHOULDNTMATCHANYTHING2
#
# print the ending HTML
#
print $heredoc;
exit;

../words.pl

TOC

#!/usr/bin/perl
#
# i wrote this as an answer to an interview question
# some guy who was hiring programmers sent me
#
#require TripodCGI;
require CGI;
use CGI;
$cgi = new CGI;
$f=$cgi->param('f');
print "Content-type: text/html", "\n\n";
print "<html>\n";
%count=();
@list=();
$rc=open(WORDS,'words.txt');
if ($rc eq '' ) {
   print "Can't open file\n";
   exit;
}
#
# read the file
#
while(<WORDS>) {
  #
  # rip off the end of the line
  #
  chomp($_);
  #
  # remove leading white space
  #
  $_=~s/^\s*//g;
  # remove trailing white space
  #
  $_=~s/\s*$//g;
  #
  # remove extra white space
  #
  $_=~s/\s\s*/ /g;
  #
  # split into words
  #
  @words=split(/\s/,$_);
  #
  # count each word
  #
  foreach(@words) {
   #
   # if the word doesn't exist set the count to one
   #
   if ($count{$_} eq '' ) {
      $count{$_}=1;
   }
   else {
      #
      # word exists, add 1 to counter
      #
      $count{$_}++;
   }
  }
}
#
# close the file
#
close(WORDS);
#
# build something we can sort on
#
foreach(keys(%count)) {
   $n=$count{$_};
   while(length($n) < 10 ) {
      $n="0$n";
   }
   $key="$n=$_";
   push(@list, $key);
}
#
# no words found?
#
if ($#list == -1 ) {
   print "no words in file";
   exit;
}
#
# sort the words
#
@sortedlist=sort(@list);
foreach(@sortedlist) {
   print "sorted $_<br>";
}
exit;