472,371 Members | 1,336 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,371 software developers and data experts.

problem in logout session

vivekgs2007
Hi Sir,
I used the user login page..it works properly, but problem is when a user clicks on logout it will come to index page, but when CLICK back BUTTON, the session is still not destroyed...
here is the code
Expand|Select|Wrap|Line Numbers
  1. session_start();
  2. session_destroy();
  3. header("Location:index.php");
  4.  
Mar 29 '10 #1

✓ answered by chathura86

Expand|Select|Wrap|Line Numbers
  1. session_start();
  2.  
  3. if(!isset($_SESSION['username']))
  4. {
  5.        header("Location: login.php");
  6.        die();
  7. }
  8.  
add this code code to top of your secure page(s).

here if the $_SESSION['username'] is not set
client will be redirected to the login page (login.php for an example)
die(); will ensure that the script will terminate if the header failed to
execute (to ensure the privacy of data)

Regards

16 5069
chathura86
227 100+
are you sure that the session is not destroyed?

refresh and make sure that it is destroyed, because you may be getting
the page from the browser cache

Regards
Mar 29 '10 #2
HI sir,
I refresh it, but no changes,Please tell me how to destroy the cache from the browser.
Mar 30 '10 #3
chathura86
227 100+
remove the header("Location:index.php");
and see if you are getting any errors when you get to that page

Regards
Mar 30 '10 #4
ok i will try and get back to u.
Mar 30 '10 #5
Sir still the same problem...i opened in the new browser opera..where their is no cache or cookie..when i press a logout menu, It will move to the blank page, but when i press back button in browser, it will easily comes to the previous page...
Expand|Select|Wrap|Line Numbers
  1. session_start();
  2. session_destroy();
  3. //header("Location:admin.php");
  4. //include("Localconnection.php");
  5.  
Sir i started the session in all pages in the first line only..and after "Title" tag i written the code of checking session condition, is that correct
Mar 30 '10 #6
chathura86
227 100+
yes you can check the session condition after the title

could you pleas show me the code you are using to check the
session.

and does it only work if you press the back button, what if you type
a url of a secure page and try to access it.


Regards
Chathura Bamunusinghe
Mar 30 '10 #7
hello sir,
i written the code is..
Expand|Select|Wrap|Line Numbers
  1.  include("Localconnection.php");
  2. if(isset($_SESSION['username']))
  3. {
  4. $username = $_SESSION['username'];
  5.  
  6. }
  7. else
  8.  
  9. $username = null;
  10.  
Mar 30 '10 #8
chathura86
227 100+
code seems to be ok, so if the session is destroyed $username should be null
but you can still see the $username right?

and does it only work if you press the back button, what if you type
a url of a secure page and try to access it.


Regards
Chathura Bamunusinghe
Mar 30 '10 #9
when a user enters to the page by entering username and password..then the username is displaying along with welcome..here is the code
Expand|Select|Wrap|Line Numbers
  1.         <h1>Welcome <?php
  2.  
  3.         $username = $_SESSION['username'];
  4.           echo $username;
  5.         ?> !!
  6.         </h1>
  7.  
when i press logout..and comes press the back button..the above code will display only "Welcome" not the name of user.
Mar 30 '10 #10
chathura86
227 100+
so that means the session is destroyed and the $_SESSION['username'] is null
thats why you are not getting the username,

Regards
Mar 30 '10 #11
ya..but y it is going back to previous page....
Mar 30 '10 #12
chathura86
227 100+
although you destroyed the session, it doesn't mean that user cannot go back,
user can always use the back button or type the url to get the page

what you can do is if the session is not exists or invalid redirect the user to another page (maybe login page), that's how you can prevent an unauthorized user from viewing the content

Regards
Mar 30 '10 #13
ok...can u send me the code how to do this...
Mar 30 '10 #14
chathura86
227 100+
Expand|Select|Wrap|Line Numbers
  1. session_start();
  2.  
  3. if(!isset($_SESSION['username']))
  4. {
  5.        header("Location: login.php");
  6.        die();
  7. }
  8.  
add this code code to top of your secure page(s).

here if the $_SESSION['username'] is not set
client will be redirected to the login page (login.php for an example)
die(); will ensure that the script will terminate if the header failed to
execute (to ensure the privacy of data)

Regards
Mar 30 '10 #15
Thank you very much..its working perfectly...
Mar 31 '10 #16
i am very great full to this site..thank chathrua...

http://www.eitech.in/
Mar 31 '10 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Bartosz Wegrzyn | last post by:
I need help with sessions. I createt set of web site for nav with authorization. first I go into main.php which looks like this: <?php //common functions include_once '../login/common.php';...
7
by: Jack | last post by:
Hi, In my application, the main page is accessed via a login screen. A particular record is accessed based on the value of login page. Everything works fine. However, if this screen is kept idle...
3
by: JMUApache | last post by:
Hi: I have got a problem with FromsAuthentication for many days. I use "Forms" Authentication in my ASP.NET Web Froms, and I find that I can't singout.... Some Code Here: //In my...
4
by: ad | last post by:
I use the Login controls of Asp.net 2.0 in my program. I want to logout a user by program, I try Session.Abandon() for this. But I found that the user is the same after I execute Session.Abandon()....
2
by: dalsoth | last post by:
Hi Guys I have created a website and to makes things easier i decided to use dreamweaver to do the secure login section and access levels for the pages. When testing locally on wamp my website...
1
by: annie123 | last post by:
Ive destroyed the session by "session_destroy();" on my logout page. But after logging out when it goes to login page. but if i paste the previusly visited link it enters until and unless i close...
1
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. ...
1
by: gnewsgroup | last post by:
I am using forms authentication for a web application. Like many other member web application, my web application prints out Welcome! John Doe (Logout) on the top right corner of each...
4
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(); ...
6
by: Thiago Macedo | last post by:
I could not find on the web a complete solution for this task. This is not the perfect solution, because it's doesn't have the ability to log the logout if browser crash or user leave it open while...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.