Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
关于在加载HTML文件之前通过php修改HTML文件的内容_Php_Html - Fatal编程技术网

关于在加载HTML文件之前通过php修改HTML文件的内容

关于在加载HTML文件之前通过php修改HTML文件的内容,php,html,Php,Html,比如说,如果在运行PHP时密码/用户名不匹配,我想返回我的主登录页面,该页面全部为HTML/JS。我希望能够访问我的主登录html页面,并使包含错误消息的div可见 下面是一些代码片段,可以帮助您理解这个示例。一切都很好,我只是不喜欢这样,我所能做的就是加载索引页面,而不告诉我的用户出了什么问题。我一直在用谷歌搜索,但没能找到正确的答案 <?php //this is in a separate file "checklogin.php" . . . if ($count =

比如说,如果在运行PHP时密码/用户名不匹配,我想返回我的主登录页面,该页面全部为HTML/JS。我希望能够访问我的主登录html页面,并使包含错误消息的div可见

下面是一些代码片段,可以帮助您理解这个示例。一切都很好,我只是不喜欢这样,我所能做的就是加载索引页面,而不告诉我的用户出了什么问题。我一直在用谷歌搜索,但没能找到正确的答案

<?php //this is in a separate file "checklogin.php"
. 
. 
.

    if ($count == 1) {
            session_start();
            $_SESSION['loggedin'] = true;
            header('Location: loggedin.php');
        }
         else {
            header('Location: index.php');
        }   
.
.
.
?>



<html> //separate file "index.php"
    <body>
    .
    .
    .

       <div id = "nomatch" name = "nomatch" style = "display:none">
         <p>
           username and password don't match
         </p>
       </div>
    .
    .
    .
    </body>
 </html>

//单独的文件“index.php”
.
.
.

用户名和密码不匹配

. . .
您只需在index.php重定向中添加一个参数:

header('Location: index.php?error');
您的index.php文件:

<?php if (isset ($_GET['error'])) { ?>
<div id = "nomatch" name = "nomatch" style = "display:none">
     <p>
       username and password don't match
     </p>
   </div>
<?php } ?>


用户名和密码不匹配


您只需在index.php重定向中添加一个参数:

header('Location: index.php?error');
您的index.php文件:

<?php if (isset ($_GET['error'])) { ?>
<div id = "nomatch" name = "nomatch" style = "display:none">
     <p>
       username and password don't match
     </p>
   </div>
<?php } ?>


用户名和密码不匹配


大约有1000种不同的方法可以做到这一点。这完全取决于您如何处理您的登录表单。最简单(但不一定是最好)的方法是返回附加到URL的错误消息

例如,重定向到,然后在代码中,您可以使用以下方法检索它:

Error: <?php echo 'error:' . $_GET["error"]; ?>.
错误:。
更多信息请点击此处:


编辑:基本上与下面相同。。。必须是在我键入答案时提交的

有大约1000种不同的方法可以做到这一点。这完全取决于您如何处理您的登录表单。最简单(但不一定是最好)的方法是返回附加到URL的错误消息

例如,重定向到,然后在代码中,您可以使用以下方法检索它:

Error: <?php echo 'error:' . $_GET["error"]; ?>.
错误:。
更多信息请点击此处:


编辑:基本上与下面相同。。。必须是在我键入答案时提交的,用
index.php
替换
index.html
,并在调用
index.php
页面时传递URL变量,这意味着:

index.php:

<?php if(isset($_GET['errors'])) {
    $errors = $_GET['errors'];
?>

<html>
    // some html tags
    <?php if($errors): ?>
        <div> your div error </div>
    <?php endif; ?>
</html>

//一些html标记
你的div错误

然后像这样调用该文件:
header('Location:index.php?error=“what you want””)

在调用
index.php
页面时,将
index.html
替换为
index.php
,并传递URL变量,这意味着:

index.php:

<?php if(isset($_GET['errors'])) {
    $errors = $_GET['errors'];
?>

<html>
    // some html tags
    <?php if($errors): ?>
        <div> your div error </div>
    <?php endif; ?>
</html>

//一些html标记
你的div错误

然后像这样调用该文件:
header('Location:index.php?error=“what you want””)

请记住,您必须将文件名从index.html更改为index.php,假设它最初名为index.html,或者PHP解释器无法运行您添加到其中的新PHP代码。使用full
也是最安全的。请记住,您必须将文件名从index.html更改为index.PHP,假设它最初名为index.html,否则PHP解释器无法运行您添加到其中的新PHP代码。使用full
也是最安全的