Hi,I have created a script where I want to use onclick event and javascript to log out.Here r my coodes .. - <script type="text/javascript">
-
function logout(){
-
<?php session_destroy();?>
-
}
-
</script>
-
-
<body>
-
<a href="#" onclick="logout()">logout</a>
-
</body>
Whenever,I reload the page,the sessions variables are destroyed without pressing the logout link...
I want know how this is achieved and how can I logout from a session..
Any help will be kindly appreciated.Tha nk s
1 23216 Dormilich 8,658
Recognized Expert Moderator Expert
that is because the PHP (that is, the session_destroy () function) is executed before the complete HTML is sent to the browser and JavaScript can be executed. (also note the output of your PHP code in the HTML source code – there shouldn’t be any)
to solve this there are several possibilities
1) make an AJAX call to a PHP script file, that executes session_destroy () - // JavaScript, pseudo code
-
function logout()
-
{
-
// simply calling the logout.php page
-
Ajax.post("logout.php");
-
}
-
// PHP
-
<?php # file: logout.php
-
session_start();
-
session_destroy();
-
?>
2) submit a form (you only need the submit button) to this page and if the button was pressed, destroy the session. - // HTML/PHP
-
<form action="" method="post">
-
<input type="submit" name="logout" value="yes">
-
<?php
-
if (isset($_POST["logout"]))
-
{
-
session_destroy();
-
}
-
?>
-
</form>
3) reload the page via JavaScript, passing an URL parameter indicating the session to be killed. - // JavaScript
-
function logout()
-
{
-
window.location.href = "page.php?logout=yes";
-
<?php
-
if (isset($_GET["logout"]))
-
{
-
session_destroy();
-
}
-
?>
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Jon Natwick |
last post by:
I'm trying to add a dynamically created logout link on my pages.
The link to the logout page will show if the user is logged in.
I put a placeholder on the aspx page and then dynamically create the link,
if the user is logged.
So far, so good. It's working.
Aspx
|
by: ShailShin |
last post by:
Hi All,
Developing an VB App for Login and logout tracking.
In App Form there are two buttons login and logout. When user click on login the loginName, LoginTime and LoginDate get stored in .MDB file.
Same with the logout but i need that logout time should get stored in the row where login details get stored and "LoginTime - LogoutTime = Total Time" calulates and stored in last field name TotalTime.
Also how to check whether user...
|
by: crescent_au |
last post by:
Hi all,
I've written a login/logout code. It does what it's supposed to do but
the problem is when I logout and press browser's back button (in
Firefox), I get to the last login page. In IE, when I press back
button, I get to the page that says "Page has Expired" but Firefox does
not do this.
I think it's something to do with sessions not properly unset or
something like that but I haven't been able to figure it out. I am
|
by: kamill |
last post by:
I have done a logout page for logout from admin section and provides a link to logout from admin section.Whenever i clicked on logout link it redirected to index.php of admin section......BUT when i am tring to go back threw back button of Browser....it send me last visted pages(means sessons not expire properly). How can i solve it... One more thing is that the script is working properly on localhost....problem occures when i uploaded it on...
|
by: chaos |
last post by:
How to do logout alert message when i press on the logout image
<a href="../logout.php" target="_top" onClick="return logout()" "MM_nbGroup('down','group1','logout','',1)""MM_nbGroup('down','group1','logout','../button_images/logout_button_down.png',1)" onMouseOver="MM_nbGroup('over','logout','../button_images/logout_button_down.png','../button_images/logout_button_down.png',1)" onMouseOut="MM_nbGroup('out')" ><img name="logout"...
| |
by: shrik |
last post by:
hi everybody.
I have following problem.
There are two pages. index.jsp and main.jsp in my application
Index.jsp contains logging interface in .
It submits password and userid to loginform bean.
following are entries in struts-config.xml file
<action input="index.jsp" name="loginform" path="/login" scope="session" type="com.myapp.struts.loginaction">
<forward name="success" path="/main.jsp"/>
|
by: kpg* |
last post by:
Hi all,
I want to perform the same action the the loginstatus control
does to logout a user programatically, but I can't seem to find
a 'logout' method in any of the membership classes.
The user gets authenticated using the login control and the build-in
database, but there are times when I want to logout the user and
send them back to the login page. At this point the "isAuthenticated"
method should return false.
|
by: Kandiman |
last post by:
Hiya, i made a asp page, and one of my divs (as a include) is as below. the problem is if the main page is resubmitted, i get logged out again?...
heres the code.. i think its on the value=true for the hidden textbox on the logout sub.. but how do i get round this? can i not change the value onclick?
<div id=Rightbody>
<!--<form id="RightBodyForm" name="RightbodyForm" method="post" action="Guestbook2.asp">-->
<%
Response.Expires...
|
by: shahidrasul |
last post by:
hi
in my project when i click on logout anchor it goes to logout page and my code in logout page is
if (Session != null)
{
Session = null;
Session.Abandon();
Response.Clear();
FormsAuthentication.SignOut();
Response.Redirect("login.aspx");
}
|
by: DavidPr |
last post by:
When I logout as one user and log in under a different user, it opens with the last user's information.
User 1 - Unsername: Davey Jones
User 2 - Unsername: David Smith
I log out from Davey Jones, then login as David Smith the Welcome message below will show "Welcome Davey". And it will be Davey's information that is accessible - not David Smith's. So something is amiss but I don't know what.
(BTW, this login script is based on the...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |