Sicherungscode (Bild) und Session

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Sicherungscode (Bild) und Session

    Hi Leute,

    also ich binde mein php-Datei, die das Sicherungsbild generiert als Bild auf meine Loginseite ein. In der PHP-Datei wo das Bild generiert wird setze ich ausserdem eine Session-Variable mit dem Code, nur habe ich nun das Problem, das ich die Session-Variable nicht nutzen kann, weil Sie wohl nicht gesetzt wird.

    Ist das einfach so, das das nicht geht, oder wo habe ich einen Denkfehler und wie stelle ich es nun an, das es doch geht ?

    gruß Picard

  • #2
    code? oder sollen wir raten?

    gruß
    peter
    Nukular, das Wort ist N-u-k-u-l-a-r (Homer Simpson)
    Meine Seite

    Kommentar


    • #3
      Home-Seite:
      PHP-Code:
      <form action="?page=login&action=login" method="POST">
                        
      Benutzername: <input type="text" name="name"><br>
                        
      Passwort: <input type="password" name="password"><br>
                        <
      img src="images.php" title="Sicherheitscode"> <input type="text" name="code"><br>
                        <
      input type="submit" value="'.$lang_home_login.'">
                    </
      form
      images.php:
      PHP-Code:
      <?php
          
      function RandomX($chars=6,$cs=true) { //------------------------ RandomX --------------------------
          
      mt_srand((double)microtime()*1000000);
          
      $s='';
          
      $aa=ord('a');

          
      $AA=ord('A');
          for(
      $i=0;$i<$chars*2;$i++) {
              if(
      mt_rand(0,1)==1) {
              
      $s.=mt_rand(1,9);
              } else {
                  
      mt_srand((double)microtime()*1000000);
                  if(
      mt_rand(0,1)==OR $cs==false) {
                      
      $s.=chr(mt_rand(0,25)+$aa);
                  } else {
                      
      $s.=chr(mt_rand(0,25)+$AA);
                  }
              }
          }
          
      $s=substr($s,mt_rand(0,$chars),$chars);
          return 
      $s;
          }

          @
      $fonts[1]=imageloadfont('fonts/atommicclock.gdf');
          @
      $fonts[0]=imageloadfont('fonts/almosnow.gdf');
          function 
      generate_char(){
              
      $pool  "qwertzupasdfghkyxcvbnm";
              
      $pool .= "23456789";
              
      $pool .= "WERTZUPLKJHGFDSAYXCVBNM";
              
      $char "";

              
      srand ((double)microtime()*1000000);
              for(
      $index 0$index 1$index++){
                  
      $char .= substr($pool,(rand()%(strlen ($pool))), 1);
              }
              return 
      $char;
          }

      $chars='';

      function 
      print_char($x)
      {
        global 
      $hImg$fonts$chars$clr_ix;
        
        switch(
      mt_rand(0,2))
        {
        case 
      0:
          
      $char=generate_char();
          
      $hFont=mt_rand(0,count($fonts)-1);
          break;
        case 
      1:
          
      $char=generate_char();
          
      $hFont=0;
          break;
        case 
      2:
          
      $char=generate_char();
          
      $hFont=mt_rand(0,count($fonts)-1);
          break;
        }
        
        
      $chars.=$char;
        
        if(
      $clr_ix == 0)
        {
          
      $forecolor=imagecolorallocate($hImgmt_rand(0,255), mt_rand(0,100), 0);
        }
        else
        {
          
      $forecolor=imagecolorallocate($hImgmt_rand(0,255), 255mt_rand(0,255));
        }
        
        
      $hFont=$fonts[$hFont];
        
      $y=mt_rand(150-imagefontheight($hFont));
        
        
      imagestring($hImg$hFont$x$y$char$forecolor);
      }
        

        
        
      $hImg=imagecreate(10050);
        
        
      $clr_ix=mt_rand(0,1);
        if(
      $clr_ix == 1)
        {
          
      $bgcolor=imagecolorallocate($hImgmt_rand(0,255), mt_rand(0,100), 0);
        }
        else
        {
          
      $bgcolor=imagecolorallocate($hImgmt_rand(0,255), 255mt_rand(0,255));
        }
        
        
      ImageFill($hImg00$bgcolor);

      imageline ($hImgmt_rand(-1001), mt_rand(-50,100), mt_rand(100,200), mt_rand(-50100), 1);
      imageline ($hImgmt_rand(-1001), mt_rand(-50100), mt_rand(100,200), mt_rand(-50100), 2);
      imageline ($hImgmt_rand(-1001), mt_rand(-50100), mt_rand(100,200), mt_rand(-50100), 3);

      imageellipse($hImgmt_rand(1100), mt_rand(150), 10102);
      imageellipse($hImgmt_rand(1100), mt_rand(150), 112);
      imageellipse($hImgmt_rand(1100), mt_rand(150), 113);
      imageellipse($hImgmt_rand(1100), mt_rand(150), 111);
      imageellipse($hImgmt_rand(1100), mt_rand(150), 112);
      imageellipse($hImgmt_rand(1100), mt_rand(150), 113);
      imageellipse($hImgmt_rand(1100), mt_rand(150), 111);
      imageellipse($hImgmt_rand(1100), mt_rand(150), 112);
      imageellipse($hImgmt_rand(1100), mt_rand(150), 113);
      imageellipse($hImgmt_rand(1100), mt_rand(150), 111);
      imageellipse($hImgmt_rand(1100), mt_rand(150), 112);
      imageellipse($hImgmt_rand(1100), mt_rand(150), 113);
      imageellipse($hImgmt_rand(1100), mt_rand(150), 111);

      imageellipse($hImgmt_rand(1100), mt_rand(150), 112);
      imageellipse($hImgmt_rand(1100), mt_rand(150), 113);
      imageellipse($hImgmt_rand(1100), mt_rand(150), 111);
      imageellipse($hImgmt_rand(1100), mt_rand(150), 112);
      imageellipse($hImgmt_rand(1100), mt_rand(150), 113);
      imageellipse($hImgmt_rand(1100), mt_rand(150), 111);

        
        
      $chars='';
        
      print_char(mt_rand(110));
        
      print_char(mt_rand(3540));
        
      print_char(mt_rand(6070));
          
      session_start();
          
      $_SESSION['code'] = $chars;

        
      $key=randomx(6);

        
      header("Content-type: image/png");
        
      imagepng($hImg);
        
      imagedestroy($hImg);
      ?>
      Hoffe man kann mir jetzt helfen

      Kommentar


      • #4
        EDIT:
        session_start() übersehen - mein Fehler
        Nieder mit der Camel Case-Konvention

        Kommentar


        • #5
          PHP-Code:
          // HIER, WICHTIG!
          $chars='';
          print_char(mt_rand(110));
          print_char(mt_rand(3540));
          print_char(mt_rand(6070));
          session_start();
          $_SESSION['code'] = $chars
          da wird $chars wieder geleert.

          gruß
          peter
          Nukular, das Wort ist N-u-k-u-l-a-r (Homer Simpson)
          Meine Seite

          Kommentar


          • #6
            Ja, das stimmt schon, da aber in den 3 Funktionsaufrufen danach wieder gefüllt wird, da es dich dabei um eine globale Variable handelt steht zum Zeitpunkt der Übergabe an die Session-Variable wieder was drinn. Das kann es also auch nicht sein.

            Kommentar


            • #7
              und was sagt ein
              PHP-Code:
              print_r($_SESSION); 
              an gewünschter stelle? und setz mal an den anfang ein
              PHP-Code:
              error_reporting(E_ALL); 
              gruß
              peter
              Nukular, das Wort ist N-u-k-u-l-a-r (Homer Simpson)
              Meine Seite

              Kommentar


              • #8
                Hm, ... also die Variabe gesetzt, aber entspricht immer dem Vorhergehendem Bild. Nur wo habe ich da dann den Fehler drinn ???

                EDIT: Jetzt versteh ich gar nichts mehr, also der Wert steht wohl richtig in der Variablen drinn, nur wird der nicht richtig gegengeprüft.

                EDIT2: Nun noch der Quellcode der login.php

                PHP-Code:
                echo 'DEBUG1 :';
                    
                print_r($_SESSION);
                    if(!@include 
                'languages/'.$language.'/login.lang.php'){
                        
                error(true'lang');
                    } else {
                        switch(
                $action){
                            case 
                'login':
                                
                $name $_POST['name'];
                                
                $code $_POST['code'];
                                
                $password $_POST['password'];
                                
                $password_md5 md5($password);

                                
                $sql_user mysql_query('SELECT * FROM `user` WHERE `name` = "'.$name.'" AND `password` ="'.$password_md5.'";');
                                if(
                mysql_num_rows($sql_user) == 1){
                                    
                $_SESSION['authenticated'] = true;
                                    while(
                $data_user mysql_fetch_assoc($sql_user)){
                                        
                $_SESSION['user_id'] = $data_user['id_user'];
                                        
                $_SESSION['user_name'] = $data_user['name'];
                                        
                $user_locked $data_user['locked'];
                                        
                $user_locked_comment $data_user['locked_comment'];
                                    }
                                    if(
                $user_locked == "true"){
                                        echo 
                $lang_login_locked.'<br>'.$lang_login_reason.': '.$user_locked_comment;
                                        
                session_destroy();
                                        echo 
                '<meta http-equiv="refresh" content="2; URL=?page=home">'."\n";
                                    } else {
                                        echo 
                'DEBUG2 : '.$_SESSION['code'];
                                        if(
                $code == $_SESSION['code']){
                                            echo 
                $lang_login_access;
                                            
                //echo '<meta http-equiv="refresh" content="1; URL=?page=overview">'."\n";
                                        
                } else {
                                            echo 
                $lang_login_codeerr;
                                        }
                                    }
                                } else {
                                    echo 
                $lang_login_noaccess;
                                }
                            break; 
                Die Ausgabe auf dem Bilschirm sieht dann ungefähr so aus:

                DEBUG1 :Array ( [level] => 0 [code] => 4zr ) DEBUG2 : Du hast dich erfolgreich eingeloggt

                Hinter Debug2 sollte dann doch eigentlich auch nochmal 4zr stehen, oder ???
                Zuletzt geändert von Picard; 10.01.2007, 19:50.

                Kommentar


                • #9
                  schmeiss in der image.php mal hier das @ raus:
                  PHP-Code:
                  $fonts[1]=imageloadfont('fonts/atommicclock.gdf');
                  $fonts[0]=imageloadfont('fonts/almosnow.gdf'); 
                  da gibt es schon ein problem.

                  gruß
                  peter
                  Nukular, das Wort ist N-u-k-u-l-a-r (Homer Simpson)
                  Meine Seite

                  Kommentar


                  • #10
                    Geht doch nicht !
                    Zuletzt geändert von Picard; 10.01.2007, 20:39.

                    Kommentar


                    • #11
                      Original geschrieben von Picard
                      Ne, da gibts kein Problem, habs nun zwar rausgenommen, hat sich aber nichts geändert !
                      also bei mir hängt er sich an der stelle auf.



                      peter
                      Nukular, das Wort ist N-u-k-u-l-a-r (Homer Simpson)
                      Meine Seite

                      Kommentar


                      • #12
                        Ja, weil bei dir die beiden Dateien nicht vorhanden sind, die er bei mir lädt.

                        Also wenn du die zum testen haben willst, hier kannst du sie runterladen:

                        http://game.htn-contact.de/data/atommicclock.gdf
                        http://game.htn-contact.de/data/almosnow.gdf

                        Kommentar

                        Lädt...
                        X