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
Solved

Session variable

Posted on 2002-05-18
15
765 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Make Session back to empty 9 30
How to pass JavaScript generated HTML text form values to PHP? 5 39
Load data upon clicking a button 8 35
forgetful about js objects 8 46
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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

829 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