2016-06-13 3 views
0

PHP에 익숙하지 않아 데이터베이스가없는 간단한 PHP 인증을 사용하여 특정 HTML 페이지를 표시하려고합니다. 로그인 배열에 다른 사용자 이름과 비밀번호를 저장합니다. 각 사용자 이름마다 다른 페이지를 표시하고 싶습니다. 예를 들어 if isset[Username]= Marc header("location:marc.html")데이터베이스없이 PHP 인증을 사용하여 특정 html 페이지를 표시하는 방법은 무엇입니까?

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

차갑다. 무슨 일 이니? –

+0

어떻게 PHP 파일을 html 파일로 만들 수 있습니까? – Andreas

+0

'header ("location :". strtolower ($ Username). ".html");'? –

답변

1

난 당신이 필요로 기대 :

header("location:marc.html"); 

가 변경 :

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

내 나쁜 ... 내가 말을하기 전에 해결책을 시도해야만 ... 그게 실제로 내가 필요한 것! 고맙습니다! –