Kann mir jemand helfen?
Wenn ich das Loginskript ohne functions benutze funktioniert es.
Woran liegt es dass es mit functions nicht klappt?
Wenn ich das Loginskript ohne functions benutze funktioniert es.
Woran liegt es dass es mit functions nicht klappt?
PHP:
<?
function logged() {
include ("./includes/inc.php");
$db = mysql_connect($host, $user, $password);
mysql_select_db($datenbank,$db);
$ip_adresse = getenv("REMOTE_ADDR");
$query = @mysql_query("SELECT * FROM spieler WHERE ipadresse = '$ip_adresse' LIMIT 1");
$result = @mysql_fetch_array($query);
if (mysql_errno()) { die("MySQL sagt:<BR>". mysql_error() ."<BR>Query:<BR>". $query);}
$spitzname = $result['spitzname'];
$ipadresse = $result['ipadresse'];
if ($ipadresse != $ip_adresse )
{
login();
} else {
echo"$spitzname";
}
}
?>
<?php
function login() {
$dbHost = "localhost";
$dbUser = "USER";
$dbPass = "PASSWORT";
$dbName = "DATABASE";
$connect = @mysql_connect($dbHost, $dbUser, $dbPass) or die("Konnte keine Verbindung zum Datenbankserver aufbauen!");
$selectDB = @mysql_select_db($dbName, $connect) or die("Konnte die Datenbank <b>$dbName</b> nicht auswählen!");
if(!isset($_POST['submit'])) {
?>
<form action="<?php $PHP_SELF; ?>" method="post">
<table width="200" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="22"> <img src="pix/new_small.png" width="16" height="16"> LOGIN</td>
</tr>
<tr>
<td background="pix/menu_kopf01.gif"> </td>
</tr>
<tr>
<td background="pix/menu_bauch01.gif"><center>Benutzername</center></td>
</tr>
<tr>
<td background="pix/menu_bauch01.gif"><center><input type="text" name="username" size="20" class="input"<?php if($_POST['username'] != "") {echo ' value="'.$_POST['username'].'"';} ?>></center></td>
</tr>
<tr>
<td background="pix/menu_bauch01.gif"><center>Passwort</center></td>
</tr>
<tr>
<td background="pix/menu_bauch01.gif"><center><input type="password" name="password" size="20" class="input"></center></td>
</tr>
<tr>
<td align="center" colspan="2" background="pix/menu_bauch01.gif">
<center><input type="submit" name="submit" value="Anmelden" class="button"></center>
</td>
</tr>
<tr><td background="pix/menu_fuss01.gif"> </td></tr>
</table>
</form>
<?php
}elseif(!isset($_POST['username']) || $_POST['username'] == "") {
echo '<p align="center">Einen Benutzernamen brauchen wir schon ;-)<br><br><a href="index2.php">Zurück</a></p>';
}elseif(!$_POST['password'] || $_POST['password'] == "") {
echo '<form action="index2.php" method="post">';
echo '<p align="center">Ein Passwort brauchen wir schon ;-)<br><br>';
echo '<input type="hidden" name="username" value="'.$_POST['username'].'">';
echo '<input type="submit" name="zurueck" value="Zurück">';
echo '</p>';
echo '</form>';
}else{
//$password = md5($password);
$query = @mysql_query("SELECT * FROM spieler WHERE spitzname = '".$_POST['username']."' LIMIT 1");
$result = @mysql_fetch_array($query); // or die('<p align="center">Sorry, aber dieser Benutzername existiert nicht!<br><a href="index2.php">Zurück</a></p>');
if (mysql_errno()) { die("MySQL sagt:<BR>". mysql_error() ."<BR>Query:<BR>". $query);}
$log = $result['login_typ'];
if($password != $result['pass']){
echo '<form action="index2.php" method="post">';
echo '<p align="center">Sorry, aber dieses Passwort ist falsch!<br><br>';
echo '<input type="hidden" name="username" value="'.$_POST['username'].'">';
echo '<input type="submit" name="zurueck" value="Zurück"></p>';
echo '</form>';
die;
}else{
$log = $result['spitzname'];
$sid = $result['id'];
$user = $result['spitzname'];
$_SESSION["spitzname"] = $log;
$ip = getenv("REMOTE_ADDR");
$sql2 = "UPDATE spieler SET ipadresse='$ip' WHERE id='$sid'";
$result = mysql_query($sql2);
if (mysql_errno()) { die("MySQL sagt:<BR>". mysql_error() ."<BR>Query:<BR>". $sql2);}
echo"<table width=\"200\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
echo"<tr><td colspan=\"2\"> <img src=\"./pix/new_small.png\" width=\"16\" height=\"16\"> ADMINISTRATION</td></tr>";
echo"<tr><td colspan=\"2\" background=\"./pix/menu_kopf01.gif\"> </td></tr>";
echo"<tr><td background=\"./pix/menu_bauch01.gif\"> </td><td background=\"./pix/menu_bauch01.gif\"><b>Login erfolgreich</b></td></tr>";
echo"<tr><td background=\"./pix/menu_bauch01.gif\"> </td><td background=\"./pix/menu_bauch01.gif\"><img src=\"./pix/nonew_small.png\" width=\"16\" height=\"16\"> <a href=\"./admin/index.php?sid=$log\" target=\"_blank\">Dein Profil</a></td></tr>";
echo"<tr><td background=\"./pix/menu_bauch01.gif\"> </td><td background=\"./pix/menu_bauch01.gif\"><img src=\"./pix/nonew_small.png\" width=\"16\" height=\"16\"> <a href=\"./admin/forum/index.php\" target=\"_blank\">Forum</a></td></tr>";
echo"<tr><td background=\"./pix/menu_bauch01.gif\"> </td><td background=\"./pix/menu_bauch01.gif\"><img src=\"./pix/nonew_small.png\" width=\"16\" height=\"16\"> <a href=\"./admin/logout.php?ipadresse=$ip\">Logout</a></td></tr>";
echo"<tr><td colspan=\"2\" background=\"./pix/menu_fuss01.gif\"> </td></tr></table>";
}
}
}
logged();
?>