简体   繁体   English

如何在没有数据库的情况下使用php身份验证显示特定的html页面?

[英]How to display specific html page using php authentication without database?

Being new to php, I'm trying to display a specific html page using simple php authentication without database. 作为php的新手,我正在尝试使用简单的php身份验证而不显示数据库来显示特定的html页面。 I store different usernames and passwords in logins array. 我在登录数组中存储了不同的用户名和密码。 I want to display a different page for each username. 我想为每个用户名显示不同的页面。 For example if isset[Username]= Marc header("location:marc.html") 例如, if isset[Username]= Marc header("location:marc.html")

login.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 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>";
        }
    }
?>

At a glance i expect you need: 我希望您一目了然:

 header("location:marc.html");

changing to: 更改为:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用php将特定值从数据库显示到页面? - How to display specific value from database to a page using php? 如何在HTML页面中使用php和mysql从数据库显示图像 - how to display image from database using php and mysql in a html page 如果在不使用Ajax的情况下PHP处理不在同一个页面中,如何在html中显示php表单结果? - How to display php form result in the html if php processing is not in the same page without using ajax? 如何使用php在html页面上显示消息 - how to display message on html page using php 使用PHP和HTML页面显示MySQL数据库中的数据 - Display data from MySQL database using PHP & HTML Page 如何使用php和mysqli在html页面的数据库中的框中显示用户帐户图片和名称? - How to display user accounts picture and name inside a box from database in html page using php and mysqli? 简单的表单提交和确认页面,无需使用HTML / PHP的数据库 - simple form submission and confirmation page without database using HTML/PHP 如何在没有php的情况下显示网页中数据库的信息 - how to display information from a database in a web page without php 如何在一页php html中显示数据库中的图像? - how to display image from database in one page php html? 如何在没有iFrame的情况下在HTML上显示来自其他服务器的PHP页面? - How to display PHP page from another server on an html without iFrame?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM