Einzelnen Beitrag anzeigen

Benutzerbild von Meflin
Meflin

Registriert seit: 21. Aug 2003
4.856 Beiträge
 
#3

Re: Misteriöse PHP Malfunction

  Alt 18. Dez 2004, 14:38
edit: ein modul ist eher nicht verantwortlich, da hab ich lokal weniger als auf dem richtigen server!
ok: hier mit html
Code:
<?php $action = $_GET["action"];
$quant = $_GET["quant"];
$factor = $_GET["factor"];
$who = $_GET["who"];
if($action == "generate") {
$dateiname = "counter.txt";
$datei = fopen($dateiname,"r");
$zahl = fgets($datei,100);
fclose($datei);
$zahl = $zahl + $quant;
$datei = fopen($dateiname,"w");
fwrite($datei, $zahl);
fclose($datei);
}

function ConvertToName($string) {
 for($i = 1; $i < strlen($string); $i++) {
   $string[$i] = strtolower($string[$i]);
 }
 return $string;
}

function FuzzyLogic($seed) {
  if(($seed <=99) AND ($seed >= 50)) { return $seed - rand(1,10); }
  if(($seed >= 0) AND ($seed <= 49)) { return $seed + rand(1,10); }
  if(($seed >=100))                 { return $seed + rand(-20,20); }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Random Name Generator</title>
<style type="text/css">
<!--
.style1 {
   color: #FFFFFF;
   font-weight: bold;
}
body,td,th {
   font-family: Verdana, Arial, Helvetica, sans-serif;
   font-size: 10px;
}
.style2 {color: #CCCCCC}
a:link {
   color: #666666;
   text-decoration: none;
}
a:visited {
   text-decoration: none;
   color: #999999;
}
a:hover {
   text-decoration: underline;
   color: #000000;
}
a:active {
   text-decoration: none;
}
.style3 {font-size: 12px}
-->
</style>
</head>

<body>
<table width="500" border="0" cellspacing="0" cellpadding="5">
  <tr>
    <td bgcolor="#000000" class="style1">[img]stern.gif[/img] Random Name Generator </td>
  </tr>
  <tr>
    <td style="border: solid black 1px">Use this generator to create random names for your games, books, fake ids, movies and whatever you need it for!
      <form name="form1" method="GET" action="index.php">
        Create
        <input name="who" type="radio" value="male">
Male
<input name="who" type="radio" value="female">
Female
<input name="who" type="radio" value="both" checked>
Both names
 How Many? <select name="quant" id="quant">
   <option value="1">1</option>
   <option value="2">2</option>
   <option value="3">3</option>
   <option value="4">4</option>
   <option value="5" selected>5</option>
   <option value="10">10</option>
   <option value="20">20</option>
   <option value="30">30</option>
   <option value="50">50</option>
   <option value="100">100</option>
 </select>
 
 


 Obscurity factor:
 <input name="factor" type="text" id="factor" value="20" size="6" maxlength="2">
(1: Common, 99: totally obscure)





<input name="action" type="hidden" id="action" value="generate">
<input type="submit" name="Submit" value="Generate random Name(s)">
      </form> </td>
  </tr>
</table>






<? if($action == "generate") { ?><table width="500" border="0" cellspacing="0" cellpadding="5">
  <tr>
    <td bgcolor="#000000" class="style1">[img]stern.gif[/img] Results</td>
  </tr>
  <tr>
    <td align="left" style="border: solid black 1px"><span class="style3"><? 
   $nachnamen = file("lastnames.txt");
   $vornamen = file("malefirstnames.txt");
   $vornamen_w = file("femalefirstnames.txt");
   
    for ($i = 0; $i < count($nachnamen); $i++) {
     $nachnamen[$i] = trim($nachnamen[$i]);    
   }
   for ($i = 0; $i < count($vornamen); $i++) {
     $vornamen[$i] = trim($vornamen[$i]);    
   }
   
   for ($i = 0; $i < $quant; $i++) {
     if($who == "male") { 
       $list = $vornamen;
        $rand_vorname = rand(0,12);
     }
     if($who == "female") { 
       $list = $vornamen_w;
       $rand_vorname = rand(0,43);
     }
     if($who == "both") { 
       $rand = rand(1,2);
      if($rand == 1) { $list = $vornamen;
        $rand_vorname = rand(0,12); } 
      if($rand == 2) { $list = $vornamen_w;
        $rand_vorname = rand(0,43); }
     };
   
     $rand_nachname = rand(0,897);
     $rand_nachname = $rand_nachname * FuzzyLogic($factor);
     $str_nachname = $nachnamen[$rand_nachname];
     $str_nachname = explode("\t", $str_nachname);
     $str_nachname = ($str_nachname[0]);
     $str_nachname = ConvertToName($str_nachname);
    
     $rand_vorname = $rand_vorname * FuzzyLogic($factor);
     $str_vorname = $list[$rand_vorname];
     $str_vorname = explode("\t", $str_vorname);
     $str_vorname = ($str_vorname[0]);
     $str_vorname = ConvertToName($str_vorname);
    
     $name = $str_vorname." ".$str_nachname;
     echo $name."
\n";
    
   } 
   ?></span></td>
  </tr>
</table>




<? } ?>
<span class="style2">
This service is still in [b]BETA[/b] phase! Report bugs to [email="bugs@namegenerator.acira.net"]bugs@namegenerator.acira.net[/email]


This service is powered by [url="http://www.acira.net"][b]acira.net[/b][/url] which is a member of the [url="http://www.sqs-entertainment.de"][b]SQS Group[/b][/url].</span>



<span class="style2">Random names served:
<? $dateiname = "counter.txt";
$datei = fopen($dateiname,"r");
$zeile = fgets($datei,100);
echo "[b]".number_format($zeile)."[/b]";
fclose($datei); ?>
</span>
</body>
</html>
und hier ohne:
Code:
<?php $action = $_GET["action"];
$quant = $_GET["quant"];
$factor = $_GET["factor"];
$who = $_GET["who"];
if($action == "generate") {
$dateiname = "counter.txt";
$datei = fopen($dateiname,"r");
$zahl = fgets($datei,100);
fclose($datei);
$zahl = $zahl + $quant;
$datei = fopen($dateiname,"w");
fwrite($datei, $zahl);
fclose($datei);
}

function ConvertToName($string) {
 for($i = 1; $i < strlen($string); $i++) {
   $string[$i] = strtolower($string[$i]);
 }
 return $string;
}

function FuzzyLogic($seed) {
  if(($seed <=99) AND ($seed >= 50)) { return $seed - rand(1,10); }
  if(($seed >= 0) AND ($seed <= 49)) { return $seed + rand(1,10); }
  if(($seed >=100))                 { return $seed + rand(-20,20); }
}
?>
...
<? 
   $nachnamen = file("lastnames.txt");
   $vornamen = file("malefirstnames.txt");
   $vornamen_w = file("femalefirstnames.txt");
   
    for ($i = 0; $i < count($nachnamen); $i++) {
     $nachnamen[$i] = trim($nachnamen[$i]);    
   }
   for ($i = 0; $i < count($vornamen); $i++) {
     $vornamen[$i] = trim($vornamen[$i]);    
   }
   
   for ($i = 0; $i < $quant; $i++) {
     if($who == "male") { 
       $list = $vornamen;
        $rand_vorname = rand(0,12);
     }
     if($who == "female") { 
       $list = $vornamen_w;
       $rand_vorname = rand(0,43);
     }
     if($who == "both") { 
       $rand = rand(1,2);
      if($rand == 1) { $list = $vornamen;
        $rand_vorname = rand(0,12); } 
      if($rand == 2) { $list = $vornamen_w;
        $rand_vorname = rand(0,43); }
     };
   
     $rand_nachname = rand(0,897);
     $rand_nachname = $rand_nachname * FuzzyLogic($factor);
     $str_nachname = $nachnamen[$rand_nachname];
     $str_nachname = explode("\t", $str_nachname);
     $str_nachname = ($str_nachname[0]);
     $str_nachname = ConvertToName($str_nachname);
    
     $rand_vorname = $rand_vorname * FuzzyLogic($factor);
     $str_vorname = $list[$rand_vorname];
     $str_vorname = explode("\t", $str_vorname);
     $str_vorname = ($str_vorname[0]);
     $str_vorname = ConvertToName($str_vorname);
    
     $name = $str_vorname." ".$str_nachname;
     echo $name."
\n";
    
   } 
   ?>


<? $dateiname = "counter.txt";
$datei = fopen($dateiname,"r");
$zeile = fgets($datei,100);
echo "[b]".number_format($zeile)."[/b]";
fclose($datei); ?>
  Mit Zitat antworten Zitat