如何从php调用html文件

时间:2017-04-25 08:48:25

标签: php html

嗨,我是初学者,我正在尝试使用html和php创建一个管理员登录页面(这里的php也出于其他几个目的),一旦管理员登录,需要运行一个html文件,我将包括我的登录页面代码如下,我需要在php文件中的if语句中插入命令我尝试了不同的使用包含函数的方式也许我没有正确使用它 提前谢谢!!!

代码:     PHP文件:

    ?php

    $username = $_POST['username'];
    $password = $_POST['password'];

    if ($username =='admin' and $password =='Parthurnax')
    {
        include 'test.html';
    }
    else
    {
        echo 'you are not the admin';
    }
    ?>

HTML文件:

<html>
<body>


<div align="center">
<form action="page.php" method="POST">

<b>Username:</b><input type="text" name="username"><br>
<b>Password:</b><input type="password" name="password"><br>
<input type="submit">

</form>
</div>

</body>
</html>

3 个答案:

答案 0 :(得分:1)

如果您想重定向到新页面,请使用以下

if(whatever_condition_set_true) {
 header('Location: whatever_page.html');
 exit;
}

或   如果您想根据条件包含任何页面,请使用

if(whatever_condition_set_true) {
   include_once('whatever_page.html');
}

答案 1 :(得分:1)

更改

if ($username =='admin' and $password =='Parthurnax')
{
    <?php include 'test.html';?>
}
else
{
    echo 'you are not the admin';
}

if ($username =='admin' and $password =='Parthurnax')
{
    include 'test.html';
}
else
{
    echo 'you are not the admin';
}

您已在已打开的PHP脚本中打开PHP标记。

不要忘记在没有登录的情况下仍然可以访问test.html页面。 如果我要在我的浏览器中直接放入test.html,我会收到受保护的页面。

将其更改为PHP脚本并检查登录用户。如果用户未登录到登录页面,或者您的脚本已经死亡。

答案 2 :(得分:-1)

使用val data = spark.read.json("file") val ssn = data.filter(line => line.contains("ssn")).count() val tickets = data.filter(line => line.contains("tickets")).count() ,不要忘记header("yourlink.html");