When login appears a message

Asked

Viewed 353 times

1

Hi, I was wondering how to do for when the user logs in, a message contained in this code appears:

<div class="alert alert-success" role="alert">
  <strong>Login realizado com sucesso, aguarde o carregamento.</strong>
</div>

The login code to sign in to the account is this

if(isset($_POST['login'])) {
co();
$u = addslashes($_POST['username']);
$p = strtoupper(md5($_POST['password']));
$app  = 'DanDanTang';
$uid  = 0;
$data = array(
    array($app, SQLSRV_PARAM_IN),
    array($u, SQLSRV_PARAM_IN),
    array($p, SQLSRV_PARAM_IN),
    array($uid, SQLSRV_PARAM_OUT)
);
$check = sqlsrv_query($conn, "{CALL Mem_Users_Accede (?,?,?,?)}", $data);
sqlsrv_next_result($check);
if($uid <= 0)
{
**echo 'Aqui no caso ficaria o codigo de login realizado';**
}
else
{
    q("Update Db_Tank.dbo.Sys_Users_Detail Set ActiveIP = '".$_SERVER['REMOTE_ADDR']."' Where UserName = '{$u}'");
    $_SESSION['UserName'] = $u;
    $_SESSION['UserId']   = $uid;
    $_SESSION['PassWord'] = $p;
    $_SESSION['Coin']   = loadCoin($uid);
    $q = q("SELECT TOP 1 NickName FROM {$dbtank}.dbo.Sys_Users_Detail Where UserName = '{$u}'");
    $info = qa($q);
    $_SESSION['NickName'] = $info['NickName'];
    $qe = q("SELECT TOP 1 UserID FROM {$dbtank}.dbo.Sys_Users_Detail Where UserName = '{$u}'");
    $infoo = qa($qe);
    $_SESSION['UserID'] = $infoo['UserID'];

    echo '<script type="text/javascript">window.location="index.php";</script>';
    exit();
}
}

1 answer

1

Before anything, log in: if(!isset($_SESSION)){session_start();}. When $uid <= 0, define $_SESSION['session_alert']['msg']:

$_SESSION['session_alert']['msg'] = 'Login realizado com sucesso, aguarde o carregamento.'

You will need a function that only shows the warning when $_SESSION['session_alert'] is set:

function session_alert() {
    if(isset($_SESSION['session_alert'])) {?>
      <div class="alert alert-success" role="alert">
      <strong><?php echo $_SESSION['session_alert']['msg']; ?></strong>
      </div>
    <?php }
    unset($_SESSION['session_alert']);
}

This function will only display the warning when the session variable $_SESSION['session_alert'] has some content. After showing, it eliminates it using unset($_SESSION['session_alert']);.

At the place where the message should appear, do the include of the file that contains the function, then just call: session_alert();.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.