Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Session variable

Posted on 2002-05-18
15
Medium Priority
?
774 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
  • 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 200 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
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!

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
Suggested Courses

916 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