joseph stalin joseph stalin - 7 months ago 9
PHP Question

Inserting div after destroyed session in login page

How could I insert a div with message of successful password change, when after successful change i redirect to login page like this?

header("Location: login.php");

Answer

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.