Problem mit functions und Dateiende

tilman

Mitglied
Problem mit Variablen Uebergabe

also ich habe an einem Admin mit Userdaten aenderung gearbeitet. zur zeit bin ich mit datei auslesen und userlisten wenn man adminrechte hat, gekommen. das neu schreiben kommt spaeter.

also ich habe ein problem mit der uebergabe der variable $admin_stat von admin() nach listuser(). wenn ihr ne idee habt, bitte melden.


admin.php:
PHP:
<?
////////////////////////////////////////////////////////////////////////////////
// read, save, and manage user login data                                     //
// using plain text file                                                      //
// 2001 version  0.8                                                          //
////////////////////////////////////////////////////////////////////////////////

// used variables, configuration

$datafile          =            "user.dat.php";
$show_user_list    =            true;              // true = yes,  false = no
$show_admin        =            true;              // true = form, false = link

////////////////////////////////////////////////////////////////////////////////
//                        no changes nessecary below here                     //
////////////////////////////////////////////////////////////////////////////////

$found             =            false;
$check             =            false;
$admin_stat        =            0;
$flogin            =            "";
$fpass             =            "";
$user_name         =            "";
$user_geburtstag   =            "";
$user_mail         =            "";
$user_icq          =            "";
$user_url          =            "";
$user_comment      =            "";

// general changes

// general changes
require ("lib.php");

function admin(){
         GLOBAL $datafile, $admin, $apass, $ulogin, $upass, $found, $check, $flogin, $fpass, $administrator;

         $eintr = readF($datafile);

	                // variablen fuer auslese
                    if(!isset($upass)) $upass = "w";
                    if(!isset($ulogin)) $ulogin = "w";
	                // auslese

        for ($i = sizeof($eintr)- 2; $i >= 0; $i--) {

                $pieces = explode("#",$eintr[$i]);

		              if($pieces[0] == $ulogin){
			                           $flogin         = $pieces[0];
			                           $fpass 		   = $pieces[1];
			                           $found 		   = true;
			                           $pointer 	   = $i;
                                       $admin_stat     = $pieces[5];
                      }

        if($found){ if($ulogin == $flogin && $upass == $fpass) $check = true;}
}
}
function error(){
         echo "<p>Entweder du hast keine Administrationsrechte oder bist kein
         registriertes Mitglied.</p>";
}

function listuser(){
         GLOBAL $datafile, $input_admin, $input_apass, $admin_stat, $check, $flogin;

         admin(); // check password
         //echo $flogin;  // gibt das richtige aus, aus der datei
         //echo $check;   // gibt gar nix aus
         //echo $admin_stat; // gibt gar nix aus
         if($admin_stat == 1 or $check == false or $check == "" or !isset($check)) error();
         if($admin_stat == 2 && $check == true){

         $readF_userlist();

         for ($i = 0; $i < sizeof($user) - 1; $i++) {
                $flogin            = $pieces[0];
                $fpass 		       = $pieces[1];
                $count 		       = $pieces[2];
                $administrator     = $pieces[5];
                $user_name         = $pieces[6];
                $user_geburtstag   = $pieces[7];
                $user_mail         = $pieces[8];
                $user_icq          = $pieces[9];
                $user_url          = $pieces[10];
                $user_comment      = $pieces[11];
                $pointer 	       = $i;
                read_user_list();
         }
         }
         else
         error();

}
if(!isset($action)) $action = "listuser";

$action();

?>

...
 
Zuletzt bearbeitet:
...

lib.php:
PHP:
<?
function readF($datafile) {
                $fh = fopen($datafile,"r");
                $contents = fread($fh, filesize($datafile));
                $contents = str_replace("\r","",$contents);
                fclose($fh);
                $parts = explode("\n", $contents);
                return $parts;
        }

function setE(){
                $date = date("d-m-y");
                $time = date("H.i");

                if(!isset($count_piece)) $count_piece = 0;
                $count = $count_piece;
  	            $count++;

                // neu schreiben
                $eintrag = $flogin."#".$fpass."#".$count."#".$date."#".$time."#".$administrator."#".$user_name."#".$user_geburtstag."#".$user_mail."#".$user_icq."#".$user_url."#".$user_comment."\n";
}
        
function writeF($datafile) {
         if($found && $check){
	        $fh = readF($datafile,"w");
	        $pointer;

         for ($i = 0; $i < sizeof($eintr) - 1; $i++) {
                if ($pointer != $i && $pointer < $i) {
                        fwrite($fh,$eintr[$i]);
                        fwrite($fh,"\n");
                        }
                if($pointer == $i){
                        setE();
                        fwrite($fh, $eintrag);
                        fwrite($fh,"\n");
                }
                if ($pointer != $i && $pointer > $i) {
                        fwrite($fh,$eintr[$i]);
                        fwrite($fh,"\n");
                        }
         }
         fclose($fh);
}

function readF_userlist(){
         $eintr = readf($datafile);
                for ($i = 0; $i < sizeof($eintr) - 1; $i++) {
                $user[$i] = $pieces[0]."#".$pieces[1]."#".$pieces[2]."#".$pieces[3]."#".$pieces[4]."#".$pieces[5]."#".$pieces[6]."#".$pieces[7]."#".$pieces[8]."#".$pieces[9]."#".$pieces[10]."#".$pieces[11];
                }
}
         
function userlist(){
         ?>
         <form action="<? echo $incdir; ?>admin.php&function=change_user" method="post" name="form">
<input type="hidden" value="<? echo $pointer; ?>" name="pointer">
<div align="center"><table width="60%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td class="maincell" colspan="2">Benutzer <? echo $pointer ?> // <? echo $flogin; ?> <br>
<a href="<? echo $incdir; ?>admin.php&function=delet_user_quest&user=<$ echo $pointer; ?>">loeschen?</a>
</td>
</tr>
<tr>
<td class="cell" valign="top" width="20%"><b>Login</td>
<td class="cell" valign="top" width="80%">&nbsp;<input value="<? echo $flogin; ?>" class="tin1" type="text" maxlenght="300" name="user_login_neu"></td>
</tr>
<tr>
<td class="cell" valign="top" width="20%"><b>Passwort</td>
<td class="cell" valign="top" width="80%">&nbsp;<input value="<? echo $fpass; ?>" class="tin1" type="text" maxlenght="300" name="user_pass_neu"></td>
</tr>
<tr>
<td class="cell" valign="top" width="20%"><b>Adminstatus</b></td>
<td class="cell" valign="top" width="80%">&nbsp;<input value="<? echo $administrator; ?>" class="tin1" type="text" maxlenght="1" name="administrator_neu"></td>
</tr>
<tr>
<td class="cell" valign="top" width="20%">Name</td>
<td class="cell" valign="top" width="80%">&nbsp;<input value="<? echo $user_name; ?>" class="tin1" type="text" maxlenght="300" name="user_name_neu"></td>
</tr>
<tr>
<td class="cell" valign="top" width="20%">Geburtstag</td>
<td class="cell" valign="top" width="80%">&nbsp;<input value="<? echo $user_geburtstag; ?>" class="tin1" type="text" maxlenght="300" name="user_geburtstag_neu"></td>
</tr>
<tr>
<td class="cell" valign="top" width="20%">Mail</td>
<td class="cell" valign="top" width="80%">&nbsp;<input value="<? echo $user_mail; ?>" class="tin1" type="text" maxlenght="300" name="user_mail_neu"></td>
</tr>
<tr>
<td class="cell" valign="top" width="20%">ICQ</td>
<td class="cell" valign="top" width="80%">&nbsp;<input value="<? echo $user_icq; ?>" class="tin1" type="text" maxlenght="300" name="user_icq_neu"></td>
</tr>
<tr>
<td class="cell" valign="top" width="20%">Url</td>
<td class="cell" valign="top" width="80%">&nbsp;<input value="<? echo $user_url; ?>" class="tin1" type="text" maxlenght="300" name="user_url_neu"></td>
</tr>
<tr>
<td class="cell" valign="top" width="20%"><?php echo $user_comment; ?><br>
<table width="100%" cellspacing="1" cellpadding="2" border="0">
<tr>
    <td class="celli"><a href="javascript: rt()" onClick="smilie(' :) ');"><img src="<?php echo $gfxdir; ?>smi1.gif" width="15" height="15" border="0"></a></td>
    <td class="celli"><a href="javascript: rt()" onClick="smilie(' ;) ');"><img src="<?php echo $gfxdir; ?>smi2.gif" width="15" height="15" border="0"></a></td>
</tr>
<tr>
    <td class="celli"><a href="javascript: rt()" onClick="smilie(' :P ');"><img src="<?php echo $gfxdir; ?>smi3.gif" width="15" height="15" border="0"></a></td>
    <td class="celli"><a href="javascript: rt()" onClick="smilie(' :D ');"><img src="<?php echo $gfxdir; ?>smi4.gif" width="15" height="15" border="0"></a></td>
</tr>
<tr>
    <td class="celli"><a href="javascript: rt()" onClick="smilie(' 8) ');"><img src="<?php echo $gfxdir; ?>smi5.gif" width="15" height="15" border="0"></a></td>
    <td class="celli"><a href="javascript: rt()" onClick="smilie(' :( ');"><img src="<?php echo $gfxdir; ?>smi6.gif" width="15" height="15" border="0"></a></td>
</tr>
</table></td>
<td class="cell" valign="top" width="80%">&nbsp;<textarea class="tin1" rows="9" name="user_comment_neu" wrap="virtual"><? echo $user_comment; ?></textarea></td>
</tr>
<tr>
<td class="cell" valign="top" width="100%" colspan="2"><div align="center"><input class="but" type="submit" value="Aendern"></div></td>
</tr>
</table>
</form></div>
<?
}
}
?>


user.dat.php:
PHP:
karl#klaresuppe#10#12-10-01#00.23#1#
ottmar#huehnchen#210#13-10-01#20.02#1#
maulesel12#ochse#271#13-10-01#21.48#1#
admin#geheim#201#13-10-01#22.47#2#

viel erfolg
 

Neue Beiträge

Zurück