2016-06-13 9 views
0

Die neu in php, ich versuche, ohne Datenbank eine bestimmte HTML-Seite mit einfacher PHP-Authentifizierung angezeigt werden soll. Ich speichere verschiedene Benutzernamen und Passwörter im Login-Array. Ich möchte für jeden Benutzernamen eine andere Seite anzeigen. Zum Beispiel if isset[Username]= Marc header("location:marc.html")Wie man spezifische HTML-Seite mit PHP-Authentifizierung ohne Datenbank anzeigen?

login.html

<form action="login.php" method="post" name="Login_Form"> 
    <table width="400" border="0" align="center" cellpadding="5" cellspacing="1" class="Table"> 
    <?php if(isset($msg)){?> 
    <tr> 
     <td colspan="2" align="center" valign="top"><?php echo $msg;?></td> 
    </tr> 
    <?php } ?> 
    <tr> 
     <td colspan="2" align="left" valign="top"><h3>Client identification</h3></td> 
    </tr> 
    <tr> 
     <td align="right" valign="top"></td> 
     <td><input name="Username" type="text" placeholder="Username" class="Input"></td> 
    </tr> 
    <tr> 
     <td align="right"></td> 
     <td><input name="Password" type="password" placeholder="Password" class="Input"></td> 
    </tr> 
    <tr> 
     <td> </td> 
     <td><input name="Submit" type="submit" value="Enter" class="Button3"></td> 
    </tr> 
    </table> 
</form> 

login.php

<?php session_start(); /* Starts the session */ 

    /* Check Login form submitted */  
    if(isset($_POST['Submit'])){ 

     /* Define username and associated password array */ 
     $logins = array(
        'Marc' => 'pass','username1' => 'password1', 
        'Guy' => 'pass','username2' => 'password2', 
        'Lucie' => 'pass','username3' => 'password3', 
        'Eva' => 'pass','username4' => 'password4'); 

     /* Check and assign submitted Username and Password to new variable */ 
     $Username = isset($_POST['Username']) ? $_POST['Username'] : ''; 
     $Password = isset($_POST['Password']) ? $_POST['Password'] : ''; 

     /* Check Username and Password existence in defined array */   
     if (isset($logins[$Username]) && $logins[$Username] == $Password){ 

        /* Success: Set session variables and redirect to Protected page */ 
      $_SESSION['UserData']['Username']=$logins[$Username]; 
      header("location:marc.html"); 
      exit; 
     } else { 
      /*Unsuccessful attempt: Set error message */ 
      $msg="<span style='color:red'>Invalid Login Details</span>"; 
     } 
    } 
?> 
+1

kühlen. Was funktioniert nicht? –

+0

Wie können Sie PHP-Code in einer HTML-Datei haben? – Andreas

+0

'header ("Location:" strtolower ($ username).. "Html.");'? –

Antwort

1

Auf einen Blick i erwarten Sie brauchen:

header("location:marc.html"); 

Wechsel zu:

$url = strtolower($Username); 
header("location:".$url.".html"); 
+0

Meine schlechten ... Ich soll Ihre Lösung versucht, bevor etwas zu sagen ... Es ist eigentlich genau das, was ich brauche! Vielen Dank! –