简体   繁体   中英

{caching} issue in smarty login form

Again I'm stuck with Smarty, In a project that I'm work on, I have a register/login forms in login for example, when I try to enter a specific "user/pass" an sql query is being proceed but the problem:

Smarty is keeping caching an old template, ie: "Wrong username or password" I mean in simple words, php is working fine at the back, but the template are retrieved from previous caching!!

one more example, I have at the footer "Login" form, you enter the data, the script check your permissions and send you to the control panel, now at the control panel the , I made a check in the "footer" so if the user is logged just gimme back something else like, "Welcome user" but the script is not acting like that at the contrary it still bringing back the "login" form no matter the data entered were correct or incorrect!!

I hope I made it clear!!

I've told to change the chaching per every template to 0

$smarty->caching = 0;
$smarty->display("index.tpl");

====================================================

Here is the footer.tpl:

<footer class="page_row">
    <div id="footer3">
//If the user is logged in
        {if isset($smarty.session.logged) && $smarty.session.logged == true} 
        <span style='text-align:left; float:left; margin:4px;'>Login:</span>
        <a href=index.php?do=members_panel&id=$md>{$smarty.session.name}</a></br>
        <a href='index.php?do=logout'>Logout</a>

        {else} //if the user is not logged in
            <span style="text-align:left; float:left; margin:4px;">Login:</span>
            <table width="20px" style="margin-left:auto; margin-right:auto;">
            <form name="sign_in" method="POST" action="index.php?do=sign_in">
            <tr><td><input name="username" type="text" class="textfield" id="username" placeholder="Username"/></td></tr>
            <tr><td><input name="password" type="password" class="textfield" id="password" placeholder="Password"/></td></tr>
            <tr><td><input type="submit" class="btn-style" value="Sign in"></td></tr>
        </table>
        {/if}
    </div>

and here the PHP part:

elseif ($_REQUEST['do'] == 'sign_in') { //Sign_in page
$username = mysqli_real_escape_string ($db_handle, $_POST['username']);
$password = mysqli_real_escape_string ($db_handle, $_POST['password']);

$login_sql = "SELECT * FROM `database` WHERE Username='$username' AND Password='$password'";
$login_query = mysqli_query($db_handle, $login_sql) or die("Bad Query: " . mysqli_error($db_handle));

if (mysqli_affected_rows($db_handle) == 1) {
$user = mysqli_fetch_assoc($login_query) or die("Error: " . mysqli_error($db_handle));
$_SESSION['logged'] == true;
$_SESSION['name'] = $user['Name'];

$smarty->assign('NAME', $user['Name']);
$smarty->assign('PASSWORD', $user['Password']);
$smarty->assign('EMAIL', $user['Email']);
$smarty->caching = 0;
$smarty->display('login_good.tpl');

}

Again, the problem is that the .tpl part is not being changed after I check if the user logged or not! PS: the (footer.tpl) "which has the form login" is included in all files such as the one shown in the upper code "login_good.tpl"

The problem is with this line:

$_SESSION['logged'] == true;

Here you don't make assignment but just comparison, it should be:

$_SESSION['logged'] = true;

So the issue has nothing in common with Smarty caching but just for using PHP operators

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