简体   繁体   English

Smarty登录表单中的{caching}问题

[英]{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上,例如,在我正在处理的项目中,我在登录时有注册/登录表单,当我尝试输入特定的“用户/密码”时,正在执行sql查询,但是问题:

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!! Smarty一直在缓存旧模板,即:“错误的用户名或密码”我的意思是简单地说,php在后面工作正常,但是模板是从以前的缓存中检索的!

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 我已经告诉将每个模板的处理速度更改为0

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

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

Here is the footer.tpl: 这是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: 这是PHP部分:

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! 同样,问题是在我检查用户是否登录后,.tpl部分没有被更改! 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" PS:(footer.tpl)“具有登录名的形式”包含在所有文件中,例如上部代码“ 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 因此,该问题与Smarty缓存没有任何共同之处,而仅在于使用PHP运算符

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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