Solved

Session variable

Posted on 2002-05-18
15
762 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 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now