473,385 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 5238
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.