<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
        <!-- ************************************************** -->
        <!-- Pro Wrestling Name Generator                       -->
        <!-- www.wrestlingname.com                              -->
        <!-- By Jeffrey Kujath  jeffATkujosoft.com              -->
        <!-- Lots of CSS and HTML help from Justin Hurst        -->
        <!-- Based on the "Wu-Name Generator" at blazonry.com   -->
        <!-- You might want to use a good editor like           -->
        <!--   Crimson Editor (Win) or SciTE (Win/Linux)        -->
        <!--   or TextMate (Mac)                                -->
        <!-- ************************************************** -->
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" />
    <link rel="stylesheet" href="screen.css" />
    <title>Pro Wrestling Name Generator :: What is Your Pro Wrestling Name?</title>
</head>

<body>

<div id="wngmain">
    
    <h1>What is your Pro Wrestling Name?</h1>

    
    <div id="wngform">
        <h2>Enter your Real Name: <span class="blackEm">(ex. Terry Bollea)</span></h2>
        <form action="<?=$SCRIPT_NAME?>" method="post">
            <input type="text" name="realname" class="big" size="30" />
            <input type="submit" value="Submit" />
        </form>
    </div>
    
    <div id="wngcounter2">
<?
      error_reporting
(E_ALL);


    if (
$_SERVER['REQUEST_METHOD'] == 'POST')
    {
    
// initialize a variable to 
    // put any errors we encounter into an array
    
$errors = array();
    
// test to see if the form was actually 
    // posted from our form
    
$page $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
    if (!
ereg($page$_SERVER['HTTP_REFERER']))
        
$errors[] = "Invalid referer\n";
    
// check to see if a name was entered
    
if (!$_POST['realname'])
    
// if not, add that error to our array
        
$errors[] = "Name is required";
    
// if there are any errors, display them
    
if (count($errors)>0){
        echo 
"<strong>ERROR:<br>\n";
        foreach(
$errors as $err)
        echo 
"$err<br>\n";
   } 
   else {
        
// no errors, so we build our message
        //print "Please input your Name";
        
$displayname $_POST["realname"];
        
//make sure user doesnt try to insert any funky characters or html
        
$displayname preg_replace('/[^a-z0-9 ]/i'''$displayname); 
        
$realname strtolower($_POST["realname"]);
        
$realname preg_replace('/[^a-z0-9 ]/i'''$realname);
        
/*== generate seed number from name submitted ==*/
        
$len strlen($realname);
        
$seed 0$s 0;

        for (
$e=1$e<=$len$e++) 
        {
            
$chr substr($realname,$s,$e);
            
$seed $seed ord($chr)*$e;
        
// Added the extra piece below because too many names were matching each other
        // So now I add the ASCII value of a character to make it more unique
            
$seed $seed ord($chr);

            
$s=$e;
        }

        
/*== read in the two files into the arrays ==*/
        
$adj_array file("youradjs.txt");
        
$noun_array file("yournouns.txt");

        
/*== set random seed ==*/
        
srand($seed);

        
/*== get the random numbers for each name first/last or adj/noun ==*/
        
$arnd rand(0,sizeof($adj_array)-1);
        
$nrnd rand(0,sizeof($noun_array)-1);
        
        
$wuadj $adj_array[$arnd];
        
$wunoun $noun_array[$nrnd];
        
        
/*== create name from random numbers ==*/
        
$wuadj rtrim($wuadj);
        
$wunoun rtrim($wunoun);
        
//I modified this because there was a linefeed between the adj and noun
        
$wngname "$wuadj $wunoun";
        
        
//BEGIN_Specific_Name_Matches
        
if ($realname == "dwayne johnson")
        {
            
$wngname "The Rock";
        }

        if (
$realname == "terry bollea")
        {
            
$wngname "Hulk Hogan";
        }

        if (
$realname == "steve williams")
        {
            
$wngname "Stone Cold Steve Austin";
        }
        
        
//Add more here

        //END_Specific_Name_Matches
        
        
        //BEGIN_DEBUG
            //print "DEBUG: arnd value is $arnd<br>";
            //print "DEBUG: nrnd value is $nrnd<br>";
            //foreach ($_POST as $var => $value) { 
                //echo "$var = $value<br>"; 
            //}
        //END_DEBUG
        
        //Lets capitalize the first letter of each word the user inputted
        
$displayname ucwords(strtolower($displayname));

        print 
"        <div id=\"wngdisplayname\">$displayname<span class=\"wngnormal\">, your professional wrestling name is now:</span><br />\n";
        print 
"        <span id=\"wngwuname\"> $wngname\n        </span></div>\n";

        
        
//BEGIN_WRITE
        //We're logging all the entries here to a text file.
        //It's fun to see what people type in
        //More importantly, it's a good way to audit the generator to make sure 
        // we're getting good results and not too many duplicates
            
$ourFileName "name_log.txt";
            
$fh fopen($ourFileName'a') or die("Can't open file");
            
$ip $_SERVER['REMOTE_ADDR'];
            
$wngdate date('Y-m-d H:i:s');
            
$twuname rtrim($wngname);
            
$wnguserinfo "$ip\t$displayname\t$twuname\t$wngdate\n";
            
fwrite($fh$wnguserinfo);
            
fclose($fh);
        
//END_WRITE
        
        //BEGIN_DEBUG
        //Uncomment the stuff below if you want to display the log we wrote
        //$ourFileName = "name_log.txt";
        //$fh = fopen($ourFileName, 'r') or die("Can't open file");
        //  Perform a "tail" on a growing logfile
        //while( !feof($fh) ) {
        //    $log = fgets( $fh,10 );
        //    echo "$log<br>";
        //    }
        //fclose($fh);
        //END_DEBUG
        
        //BEGIN_COUNTER
        //I just want to see how many names are generated
        //The counter will increase at every press of the Submit button
        // or even a reload of the page.
            //variable declarations
            
$counter_data "count.txt"//counter data file
            //$image_dir = "/digits/1";    //image directory
            
$style "text"//enter text for text.Anything else for graphics
            //check if file exists
            
if(!($fp fopen($counter_data,"r+"))) die ("cannot open counter file");
            
//read in the current count from the file
            
$count = (int) fread($fp20);
            
//close the file
            
fclose($fp);
            
//increment count
            
$count++;
            
//text counter
            
if ($style == "text"
            {
                echo 
"        $count";
                
            }
            
//graphical counter
            //else 
            //{
            //    $digit = strval($count);
            //    for ($i = 0; $i < strlen($count); $i++) 
            //    {
            //        echo "<img src=$image_dir/$digit[$i].gif>";
            //    }
            //}
            
$fp fopen($counter_data"w");
            
fwrite($fp $count);
            
//close the file
            
fclose($fp);        
        
//END_COUNTER
        
    
}
    


?>

        Wrestling Names Served since May 18 2006
        <br />By <a href="http://www.kujosoft.com" target="_blank">Jeff Kujath</a>.  Based on the <a href="http://www.blazonry.com/scripting/wuname.php" target="_blank">Wu-Name Generator</a> at <a href="http://www.blazonry.com/scripting/wuname_how.php" target="_blank">www.blazonry.com</a>.
        <br />PHP code was heavily modified to provide additional security and functionality.
        <br />Download my modified source code <a href="http://wrestlingname.com/wng_code.phps" target="_blank">HERE</a>.
        <br />My stylesheet is <a href="http://wrestlingname.com/screen.css" target="_blank">HERE</a>.
        <br />Disclaimer: Use my code at your own risk.  :-)
        <br />Questions/Comments/Suggestions, please go to my forums <a href="http://www.kujath.com/kuBB/viewforum.php?f=8" target="_blank">HERE</a>.
        <br />Or email me: <a href="mailto://jeff@kujosoft.com">jeff@kujosoft.com</a>
        <br />Check out other fun Generators at <a href="http://generatorblog.blogspot.com/" target="_blank">generatorblog.blogspot.com</a>!
        <br />Check out my other sites: <a href="http://www.kujosoft.com" target="_blank">kujosoft.com</a> .:. <a href="http://www.kujath.com" target="_blank">kujath.com</a> .:. <a href="http://www.kumovies.com" target="_blank">kumovies.com</a> .:. <a href="http://www.sarahjo.com" target="_blank">sarahjo.com</a>
        <br />
    </div>    

    <div id="wngvalidate">
        <a href="http://validator.w3.org/check?uri=referer" target="_blank">
            <img src="valid-xhtml10.gif"
            alt="Valid XHTML 1.0 Transitional" height="31" width="88" border="0" />
        </a>
    </div>

</div>


</body>
</html>