简体   繁体   中英

Inserting div after destroyed session in login page

如何在成功更改密码后像这样重定向到登录页面,如何插入包含密码更改成功消息的div?

header("Location: login.php");

You can put a query parameter in that redirect, and verify, in the redirected page, if that value is set. If is the case, make visible the div you want, which, previously, was set to be invisible, with css.

Like this:

header("Location: login.php?div=enabled");

Then, in the login.php page:

<style type="text/css">
.div{
    display: none;
    visibility: hidden;
 }
</style>
...

<?php
if (isset($_GET['div']) and $_GET['div'] == 'enabled'){
    ?>
    <style type="text/css">
    .div{
        display: block;
        visibility: visible;
    }
    </style>
    <?php
}

So, if that query parameter is not set, or does'nt have "enabled" as value, the div will be hidden. But if the query param is set and have "enabled" as its value, then display the div .

If you want to do that by header then pass your message as a query string

header("Location: login.php?msg=password changed");

And the receive the message on login page print it

if(isset($_GET['msg'])){
    echo "<div class='class_name'>".$_GET['msg']."</div>"
}

Use GET method and try something like this :

header("Location: login.php?str=successfull");

And on login.php page :

<?php
if(isset($_GET['str'])){ ?>
  <div><?php echo $_GET['str'];?></div>
<?php
}
?>

Here is a little bit secure way to do it :

Use COOKIES if you don't want to do anything unsecure in header :

if ($query) {
    setcookie("password_changed", "password_changed", time()+5);
    header("Location: login.php");
}

And then fetch the cookie at your login page as :

if (isset($_COOKIE['password_changed']) && $_COOKIE['password_changed'] == "password_changed") {
    $message = "Your Password Is Successfuly Changed.!";
}

And then echo the $message with using isset() in an if function inside a Div ..!

OR

You can directly do it like this way :

if (isset($_COOKIE['password_changed']) && $_COOKIE['password_changed'] == "password_changed") {
    echo "<div class='class_name'><h2 align='center'>Hey,Your Password Is Changed<h2></div>";
}

you just set a session variable .

<?php

$_SESSION['LOGIN_MSG']="<DIV>SUCCESS</DIV>";
$_SESSION['LOGIN_MSG']="<DIV>FAILED</DIV>";

if(isset($_SESSION['LOGIN_MSG']))
{

    echo $_SESSION['LOGIN_MSG'];

    unset($_SESSION['LOGIN_MSG']);

}  ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM