简体   繁体   English

如何为php创建注销代码

[英]How to create a logout code for php

i'm using this code: but doesnt seem to work because the structure of my html file has 3 frames, a sidebar, title, and the main. 我正在使用此代码:但似乎不起作用,因为我的html文件的结构具有3个框架,一个侧边栏,标题和主要内容。

Now, the user will have two buttons, the call new sidebar. 现在,用户将有两个按钮,即“调用新边栏”。 Which is only accessible if he has logged in. And the other button is log out. 只有他登录后才能访问。另一个按钮是注销。 When the user press the call new sidebar. 用户按下呼叫新边栏时。 The sidebar will change into a user-only sidebar. 侧边栏将变为仅用户侧边栏。 Now, when the user clicks the logout button the sidebar which is only for users is still there. 现在,当用户单击注销按钮时,仅适用于用户的侧边栏仍然存在。 Is it possible to target two frames in html. 是否可以在html中定位两个框架。 Any other technique that you can recommend so that when the user logs off. 您可以推荐的其他任何技术,以便在用户注销时使用。 There will be no other way to access the user-only sidebar. 没有其他方法可以访问仅用户侧栏。

     session_start();
    session_destroy();

       ?>

You can specify a target for your form which could be _parent to reload the whole page: 您可以为表单指定一个目标,该目标可以是_parent以重新加载整个页面:

<form action="[..]logout[..]" method="post" target="_parent">
</form>

I'd recommend in your logout code to erase $_SESSION to make sure you have no data left in there, simply do 我建议您在注销代码中删除$ _SESSION,以确保其中没有剩余数据,只需执行

session_start();
session_destroy();
$_SESSION = array();

您可以注销并使用javascript刷新整个窗口。

Make this into a habit, after do a state change, reload the page or redirect to other page. 养成习惯,在更改状态后,重新加载页面或重定向到其他页面。 State change is including logout, add, edit, delete, etc. By doing this, you can make sure that the action result reflected in the new page, and the user can see it. 状态更改包括注销,添加,编辑,删除等。通过这样做,您可以确保操作结果反映在新页面中,并且用户可以看到它。

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

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