Autor Beitrag
Supernova
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 108

WinXP
D7 Prof
BeitragVerfasst: Mi 03.01.07 14:57 
Hallo,

ich beginne mich mal wieder ein wenig mit PHP zu beschäftigen ... und hab mal Versucht ein Login-Script zu machen ...

index.php

ausblenden volle Höhe Quelltext
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:
<?php

  include('login');
  
   if(isset($_GET['logout'])) {
      unset($_SESSION['success']);
      header("Location: index.php");
    }
    
    
      

?>

<html>
<head>
    <title>Administrations - Login</title>
</head>
<body margin="5">
  <?php
    if(isset($_SESSION['success'])) {    
      echo "drin<br><a href='index.php?logout=true'>Logout</a>";  
    }else {
  ?>
  <form target="_self" method="post" name="main">
    Username: <input type="text" name="username"><br>
    Password: <input type="text" name="password"><br>
    <input type="submit" name="sender" value="Login">
  </form>
<?php } ?>
</body>
</html>


login.php

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
<?php

  include('mysql_connect.php');
  @session_start();
  
  $sql_action = @mysql_query("SELECT user_id FROM tbl_user WHERE username = $username AND password = $password");
  
  if(@mysql_num_rows($sql_action) == 1) {
    $_SESSION['success'] = true;
    return true;
  } else {
    return false;
  }

?>


So wenn ich dass Script teste bekomme ich irg. immer den Wert FALSE zurück ... kann mir da vllt. jemand helfen warum dass so ist ... ^^
Entschuldigt wenn das Script ein wenig unübersichtlich ist ... aber ich komm einfach nicht weiter ^^

Beste Grüße,
Andi

_________________
Input - Output => Ganz Kaputt
*** MFG Supernova ***
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mi 03.01.07 15:03 
1. Mach erstmal alle @ weg - wir wollen ja keine Fehlermeldungen unterdrücken :lol:.
2. Dann glaube ich, dass return nur in Funktionen geht - du hast es aber in einer If-Abfrage.
3. Ruft dein Formular die index.php auf - du hast aber nirgends die Login.php inkludiert.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Flamefire
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Mi 03.01.07 15:25 
also...zu dem code brauch ich nix sagen oder?
return nur in funktionen...und die action im formular setzen
vorschlag:
ausblenden volle Höhe Quelltext
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:
<?php

  include('login[b].php[/b]');
  
   if(isset($_GET['logout'])) {
      unset($_SESSION['success']);
      header("Location: index.php");
    }
    
    
      

?>

<html>
<head>
    <title>Administrations - Login</title>
</head>
<body margin="5">
  <?php
    if(isset($_SESSION['success'])) {    
      echo "drin<br><a href='index.php?logout=true'>Logout</a>";  
    }else {
  ?>
  [b]<form method="post" name="main">[/b]
    Username: <input type="text" name="username"><br>
    Password: <input type="text" name="password"><br>
    <input type="submit" name="sender" value="Login">
  </form>
<?php } ?>
</body>
</html>

login.php
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
<?php

  if($_POST['sender']!=""){ //nur kontrolle bei neuem formularsenden
     include('mysql_connect.php');
     @session_start();
  
     $sql_action = @mysql_query("SELECT user_id FROM tbl_user WHERE username = $username AND password = $password");
  
     if(@mysql_num_rows($sql_action) == 1) $_SESSION['success'] = true;
   }//löschen wenn keine kontrolle

?>
LeoLöwe
ontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 45

Win XP Home
BDS 2006, PHPCoder
BeitragVerfasst: Mi 03.01.07 15:29 
Dein SQL-Query sieht falsch aus

Ausserdem - wieso packst du nicht die SQL-Abfrage mit in die andere Datei rein?
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mi 03.01.07 15:31 
Query sieht doch richtig aus :shock:

Und dann weis ich dich gleich noch auf die Gefahren von Suche bei Google XXS hin.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Mi 03.01.07 16:09 
Wo kommen denn die Variablen $username und $password her? Die werden doch soweit ich das sehe an keiner Stelle aus den POST-Daten rausgeholt, oder?

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
Supernova Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 108

WinXP
D7 Prof
BeitragVerfasst: Mi 03.01.07 16:40 
Erstmal besten Danke an alle die mir hier bis jetzt geholfen haben ^^

@GTA ... ich verstehe nich sonderlich viel was du mit XXS meinst, sorry, aber googlen bringt irg auch nix ...

@Martok ... Praktisch muss der Query dann so lauten:

ausblenden Quelltext
1:
SELECT user_id FROM tbl_user WHERE username = $_POST['username'] AND password = $_POST['password']					


Richtig ?

_________________
Input - Output => Ganz Kaputt
*** MFG Supernova ***
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mi 03.01.07 16:44 
Ist ja auch immer so schwer zu finden, wenn sich jeder XXS nennet :lol: -> Suche bei Google CROSS SITE SCRIPTING (oder gleich: Suche bei Google SQL-INJEKTION)

Ja, richtig, aber guck dir jetzt nochmal XXS an.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Supernova Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 108

WinXP
D7 Prof
BeitragVerfasst: Mi 03.01.07 17:01 
Mhm ... Danke ...

Wenn ich nun diese Funktion einbinde ...
ausblenden Quelltext
1:
2:
3:
4:
function check_string($string) {
    if((preg_match('/^[a-zA-Z0-9\-\_]+$/',$string))) return true;
    return false;
  }


sowie die PHP-Funktion

ausblenden Quelltext
1:
htmlspecialchars();					


dürfte das Script doch einigermaßen sicher sein, oder ?

Thanx a lot ...
Andi

_________________
Input - Output => Ganz Kaputt
*** MFG Supernova ***
Supernova Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 108

WinXP
D7 Prof
BeitragVerfasst: Mi 03.01.07 19:23 
Hallo,

so ich habe jetz nochmal alles komplett überarbeitet ... aber irg. funktioniert das einloggen einfach nicht ... immer bekomme ich den wert FALSE zurück ...

administration_login.php

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
<?php

  include('mysql_connect.php');
  session_start();
    
  $sql_action = mysql_query('SELECT user_id FROM administration_user WHERE username = $_POST["username"] AND password = $_POST["password"]');
  
  if(@mysql_num_rows($sql_action) == 1) {
    $_SESSION['success'] = true;
  } else {
    echo '<center>Login fehlgeschlagen!</center>';
  }
  

?>


administration_login_form.php

ausblenden volle Höhe Quelltext
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:
<?php

  include('administration_login.php');
  
  if(isset($_GET['logout'])) {
    unset($_SESSION['success']);
    header('Location: administration_login_form.php');
  }

?>

<html>
  <head>
    <title>« dieFanz.de | Administrations-Login »</title>
  </head>
  <body>
    <br>
    <br>
    <br>
    <br>
    <center>
      <?php
      
        if(isset($_SESSION['success'])) {    
          echo "Sie sind eingeloggt.<br><a href='index.php?logout=true'>Logout</a>";  
        }else {
      
      ?>
      <form target="_self" method="post" name="login">
        Benutzername: <input type="text" name="username">
        <br>
        Kennwort:       <input type="password" name="password">
        <br>
        <br>
        <input type="submit" name="transmitter" value="Login">
      </form>
      
      <?php
      
        } 
        
      ?>
    </center>
  </body>
</html>


Ich weis einfach echt nicht mehr was ich falsch mache ... ich vermute es liegt am Query und den $_POST Variablen ...

Beste Grüße,
Andi

Edit:

Die Datenbankstruktur sieht folgendermaßen aus:

ausblenden Quelltext
1:
2:
3:
4:
Feld       Typ             Null    Standard     Verweise    Kommentare    MIME
user_id    int(17)   Nein                                      // auto increment, Primärschlüssel
username    varchar(255)   Nein                 
password    varchar(255)   Nein

_________________
Input - Output => Ganz Kaputt
*** MFG Supernova ***


Zuletzt bearbeitet von Supernova am Mi 03.01.07 19:28, insgesamt 1-mal bearbeitet
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mi 03.01.07 19:28 
ausblenden Quelltext
1:
<form target="_self" method="post" name="login">					

Warum schreibst du bei target nicht den richtigen Dateinamen hin? So mache ich das immer und es klappt. ;) Tue es einfach mal!

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Supernova Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 108

WinXP
D7 Prof
BeitragVerfasst: Mi 03.01.07 19:32 
@Marco D. ... eig. ist es ja sinnlos, weil mit _SELF ja das obere script aufgerufen wird, und das hat ja die Datei includet ...

_________________
Input - Output => Ganz Kaputt
*** MFG Supernova ***
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mi 03.01.07 19:35 
Probiere mal den Query manuell in phpMyAdmin auszuführen. Außerdem solltest du die Werte im Query in Anführungszeichen setzen (z.B. WHERE username='$username' ...=

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Mi 03.01.07 19:37 
Aha! Da hast du das falsche Attribut. Target gibt an, in welchem Frame die Seite aufgemacht werden soll.

ausblenden Quelltext
1:
2:
3:
4:
<form target="_self" method="post" name="login">
         |
         V 
<form action="administration_login.php" method="post" name="login">

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mi 03.01.07 19:39 
user profile iconMartok hat folgendes geschrieben:
Aha! Da hast du das falsche Attribut. Target gibt an, in welchem Frame die Seite aufgemacht werden soll.

ausblenden Quelltext
1:
2:
3:
4:
<form target="_self" method="post" name="login">
         |
         V 
<form action="administration_login.php" method="post" name="login">

:autsch: Dass mir das nicht auffällt. :autsch:

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Mi 03.01.07 19:46 
Dein Unterbewusstsein hat das gemerkt, denn du hast ja oben von diesem Attribut geschrieben ;)
Habs auch nur wegen deinem Kommentar gesehen :mrgreen:

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mi 03.01.07 19:47 
user profile iconMartok hat folgendes geschrieben:
Dein Unterbewusstsein hat das gemerkt, denn du hast ja oben von diesem Attribut geschrieben ;)
Habs auch nur wegen deinem Kommentar gesehen :mrgreen:

Es kam mir gleich sehr verdächtig vor. :zwinker:

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Flamefire
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Mi 03.01.07 19:47 
FALSCH!!! Es kann gar nicht gehen! dein mysql-query ist falsch. so muss er heißen:
ausblenden Quelltext
1:
$sql_action = mysql_query('SELECT user_id FROM administration_user WHERE username ="'.$_POST["username"].'" AND password = "'.$_POST["password"]'.'"');					

ansonsten sucht er statt nach dem namen nach der zeichenkette $_POST["username"]
nicht nach dem inhalt davon!
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mi 03.01.07 19:49 
user profile iconFlamefire hat folgendes geschrieben:
FALSCH!!! Es kann gar nicht gehen! dein mysql-query ist falsch. so muss er heißen:
ausblenden Quelltext
1:
$sql_action = mysql_query('SELECT user_id FROM administration_user WHERE username ="'.$_POST["username"].'" AND password = "'.$_POST["password"]'.'"');					

ansonsten sucht er statt nach dem namen nach der zeichenkette $_POST["username"]
nicht nach dem inhalt davon!

Entweder so, oder:
ausblenden Quelltext
1:
 $sql_action = mysql_query('SELECT user_id FROM administration_user WHERE username="$_POST[username]" AND password="$_POST[password]"');					

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mi 03.01.07 20:11 
user profile iconFlamefire hat folgendes geschrieben:
FALSCH!!! Es kann gar nicht gehen! dein mysql-query ist falsch. so muss er heißen:
ausblenden Quelltext
1:
$sql_action = mysql_query('SELECT user_id FROM administration_user WHERE username ="'.$_POST["username"].'" AND password = "'.$_POST["password"]'.'"');					

ansonsten sucht er statt nach dem namen nach der zeichenkette $_POST["username"]
nicht nach dem inhalt davon!

Nein, sucht er nicht :zwinker:

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)