Solved

Session variable

Posted on 2002-05-18
15
769 Views
Last Modified: 2012-06-27
I use Session variable to check if the user have login or not. I would like to detect if the seeion has expired. if so re-login is required.  I write the following code, but I did work as expected. It seems like (Session("member_id") != "undefined") is always true, even though it is equal some number. Can you tell me what is wrong with my code? and how to get it working.

<%@LANGUAGE="JAVASCRIPT"%>
<%
if (Session("member_id") != "undefined") {
  Response.Redirect("login.asp")
}

%>
<html>
<head>
<title>Brisbane Car Pooling Services</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">

</body>
</html>
0
Comment
Question by:meng032399
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +5
15 Comments
 
LVL 33

Expert Comment

by:hongjun
ID: 7019315
Try this
<%@LANGUAGE="JAVASCRIPT"%>
<%
if (Session("member_id") == "") {
 Response.Redirect("login.asp")
}


The above check will be true if session expires.

hongjun
0
 
LVL 23

Accepted Solution

by:
b1xml2 earned 50 total points
ID: 7019802
No, hongjun. That's not the answer.
<%@language="JScript"%>
<%
 if (Session("member_id") == null) {
  Response.Redirect("login.asp");
 }
%>
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 7019865
Meng,

Is this client-side or server-side code? I don't think that this will work client side. If it is server-side code, are you programming in JavaScript, JScript, or VBScript?

Fritz the Blank
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 23

Expert Comment

by:b1xml2
ID: 7020557
fritz, he is using JScript Server-Side as evidenced by the language value. I use JScript also on the server-side.
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 7020681
Brandon,

Fair enough--it's just that the first line of code that he wrote was: <%@LANGUAGE="JAVASCRIPT"%>

I just wanted to make sure that I understand what's going on before I chimed in.

Fritz the Blank
0
 

Author Comment

by:meng032399
ID: 7020724
Hi all,

I try all your way suggested, but it is still not working.

Meng
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7020727
meng,
<%
Response.Buffer = true;
if (Session == null || Session("member_id") == null) {
 Response.Redirect("login.asp");

}
%>
0
 
LVL 19

Expert Comment

by:webwoman
ID: 7022000
Are you sure it's getting set correctly?
0
 

Author Comment

by:meng032399
ID: 7022649
hi b1xm12,

Yeap. I set the session variable the first time the user login. and in any other asp pages, the session variable is still there with the correct value. But when I go in login asp page, the session variable become undefined.
anything special about my login.asp page? I use Dream Weaver UltraDev 4.0.


Meng


 
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7022952
Is there a directive like the EnableSessionState ?
<%@language="JScript" @EnableSessionState="False"%>

This will cause no Sessions to be available.

Or This somewhere in your Script

<%
 Session.Abandon();
%>
0
 
LVL 1

Expert Comment

by:johan_brohn
ID: 7037211
if(val) evaluates to
  numbers: null, < 0, undefined => false
  strings: null,  '', undefined => false
in Microsoft JavaScript.

So my suggestion would be:

if(!Session("member_id"))
   Response.Redirect("login.asp");
0
 
LVL 12

Expert Comment

by:ahosang
ID: 8257495
This question has been abandoned. I will make a recommendation to the moderators on its resolution in a week or so. I appreciate any comments that would help me to make a recommendation.
 
In the absence of responses, I may recommend DELETE unless it is clear to me that it has value as a PAQ. Silence = you don't care
 
ahosang
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8257510
Points to b1xml2.

Fritz the Blank
0
 
LVL 12

Expert Comment

by:ahosang
ID: 8354495
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

points to b1xml2
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
ahosang
EE Cleanup Volunteer
0
 

Expert Comment

by:Chmod
ID: 8404911
As recommended

Chmod
Community Support Moderator @Experts Exchange
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question