Login

Lektor21

Erfahrenes Mitglied
Hallo allerseits! :)

Ich habe ein Loginscript. Wenn aber jemand ausversehen auf Aktualisieren im Browser klickt, ist er wieder ausgeloggt!

Wie kann ich realisieren, dass wenn der $user noch eine gültige Session besitzt, er automatisch wieder eingeloggt ist?

Hier ein Teil meines Scripts:

PHP:
<?php




if      ($anmelden) { anmelden($fertig, $user, $password1, $password2, $email);}
else if ($abmelden) { abmelden($fertig, $user, $password);}
else if ($forgot)   { forgot($fertig, $email);}
else                { login($fertig, $user, $password);}




?>



<?php
function inhalt($user) 
{
session_start();
session_register("user");
?>


<?php

if ($user == "Administrator")
{
?>


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="format.css" type="text/css">
<script language="JavaScript">
<!--
if(top.frames.length == 0)       
{ top.location = "../index.php" }
// -->
</script>
<script type="text/javascript">
function frame_href(){
parent.content.location.href='admin/admin.php';
}
</script>
<script type="text/javascript">

function exit() {
  document.location.href="logout.php";
}
</script>
</head>
<body bgcolor="#DE001F" onLoad="frame_href()" onUnload="exit()" topmargin="0" leftmargin="0">
<table border="0" width="152">
<tr>
<td align="center"><b>Eingeloggt als:</b><br><font color="#FFFF00" size="4px"><b><?php echo("$user"); ?></b></font></td>
</tr>
<tr>
<td><p>&nbsp;</p></td>
</tr>
<tr>
<td align="center"><input type="button" class="button" value="Administration" style="width:146px;" onClick="parent.content.location.href='admin/admin.php'"><br><input type="button" class="button" value="Logout" style="width:146px; color:#FF0000;" onClick="window.location.href='logout.php'">
</td>
</tr>
</table>
</body>
</html>

<?php
}
elseif ($user != "Administrator")
{
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="format.css" type="text/css">
<script language="JavaScript">
<!--
if(top.frames.length == 0)       
{ top.location = "../index.php" }
// -->
</script>
<script type="text/javascript">
function frame_href(){
parent.content.location.href='userprofile.php';
}
</script>
<script type="text/javascript">

function exit() {
  document.location.href="logout.php";
}
</script>
</head>
<body bgcolor="#DE001F" onLoad="frame_href()" onUnload="exit()" topmargin="0" leftmargin="0">
<table border="0" width="152">
<tr>
<td align="center"><b>Eingeloggt als:</b><br><font color="#FFFF00" size="4px"><b><?php echo("$user"); ?></b></font></td>
</tr>
<tr>
<td><p>&nbsp;</p></td>
</tr>
<tr>
<td align="center"><input type="button" style="width:73px;" class="button" value="Support" onClick="parent.content.location.href='support.php'"><input type="button" class="button" value="Logout" style="width:73px; color:#FF0000;" onClick="window.location.href='logout.php'"><br>
<input type="button" class="button" value="Account" style="width:146px;" onClick="parent.content.location.href='userprofile.php'">
</td>
</tr>
</table>
</body>
</html>
	
<?php
}
}
?>


Und noch eine Frage; Wäre es sinnvoller, die Session $user in z.B. $user_domain umzubennen? Habe mir gedacht, dass wenn z.B. einer von einer Webseite kommt, aufder auch $user benutzt wird und diese Session nicht beendet wurde, dass er dann Zugriff hat? Also natürlich nur, wenn zufällig bei mir der gleiche User registriert ist!?
 
Zuletzt bearbeitet:
Globale Variablen sollten am besten gar nicht verwendet werden. Und den Status schreibst du einfach in die $_SESSION-Variable.
 
Warum denn nicht? Und was meinst du damit? Was kann da passieren?

Ist meine Lösung nicht sicher? Was ist sicherer als meine Variante?
 
Zuletzt bearbeitet:

Neue Beiträge

Zurück