Search code examples
javascriptphpjqueryhtmljgrowl

i want jgrowl only pop up once after login


Here's my problem, I tried make notification with jgrwol and done. now I want the notification just pop up once after login. it should be not pop up anymore when I refresh the page or move another menu and back to the notification menu.

CODE :

<script type="text/javascript">
    $(function() {
        $.jGrowl("<p class='upper'><i class='fa fa-exclamation-triangle' aria-hidden='true'></i> <?=$row['NTFY_TTL'];?></p><?=$row['NTFY_DESC'];?><br> <small>Posted <?=$row['BEG_DT'];?></small>", { 
             theme: 'test',
             position: 'top-right',
             life: 3000 
        });
    });
</script>

CODE LOGIN :

<?php
include "framework/database/connect.php";

$loginUserID=$_POST['userID'];
$password=$_POST['password'];
if(substr($password,-1)=="~"){
    $display="?DISP=ON";
    $password=substr($password,0,-1);
}
if(substr($password,-1)=="+"){
    $display="?DISP=TRIM";
    $password=substr($password,0,-1);
}
if($password!=''){
    $query="SELECT SEC_KEY,PRSN_NBR,PWD FROM CMP.PEOPLE PPL INNER JOIN CMP.POS_TYP POS ON PPL.POS_TYP=POS.POS_TYP WHERE PRSN_ID='".$loginUserID."' AND (PWD='".$password."' OR PWD='".hash('sha512',$password)."') AND TERM_DTE IS NULL";
    //echo $query;
    $result=mysql_query($query);
    $row=mysql_fetch_array($result);
    if(mysql_num_rows($result)==0){
        $warning="<font color='red'>Id or Pass is wrong.</font><br />";
    }else{
        $warning="<br/>";
        $_SESSION['userID']=$loginUserID;
        $_SESSION['personNBR']=$row['PRSN_NBR'];
        //Enforce hashing
        if($row['PWD']==$password){
            $query="UPDATE CMP.PEOPLE SET PWD='".hash('sha512',$password)."' WHERE PRSN_NBR=".$_SESSION['personNBR'];
            //echo $query;
            $result=mysql_query($query);
        }
        header('Location:index.php'.$display);
        exit;
    }
}elseif($_GET['COMMAND']=="LOGOUT"){
    unset($_SESSION['userID']);
    unset($_SESSION['personNBR']);
}elseif($_GET['COMMAND']=="LOCK"){
    $defServer=$OLTA;
    mysql_connect($defServer,"root","Pr0reliance");
    mysql_select_db("cmp");
    $query="UPDATE NST.PARAM_LOC SET TAX_LOCK=1";
    $result=mysql_query($query);
}elseif($_GET['COMMAND']=="UNLOCK"){
    $defServer=$OLTA;
    mysql_connect($defServer,"root","Pr0reliance");
    mysql_select_db("cmp");
    $query="UPDATE NST.PARAM_LOC SET TAX_LOCK=0";
    $result=mysql_query($query);
    $defServer=$OLTP;
}
?>

Solution

  • Use localstorage for set and get value. Check this fiddle , Clear localstorage when you in login page , so it will display again when you back into the menu page from login page.

    $(function() {  
       if(!localStorage.getItem('growl')){
            $.jGrowl("<p class='upper'><i class='fa fa-exclamation-triangle' aria-hidden='true'></i> <?=$row['NTFY_TTL'];?></p><?=$row['NTFY_DESC'];?><br> <small>Posted <?=$row['BEG_DT'];?></small>", { 
                 theme: 'test',
                 position: 'top-right',
                 life: 3000 
            });
    
                    localStorage.setItem('growl', true);
       }
    
    });
    

    For localstorage remove.

    localStorage.removeItem('growl');