Link to home
Start Free TrialLog in
Avatar of meng032399
meng032399

asked on

Session variable

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>
Avatar of hongjun
hongjun
Flag of Singapore image

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


The above check will be true if session expires.

hongjun
ASKER CERTIFIED SOLUTION
Avatar of b1xml2
b1xml2
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fritz_the_blank
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
fritz, he is using JScript Server-Side as evidenced by the language value. I use JScript also on the server-side.
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
Avatar of meng032399
meng032399

ASKER

Hi all,

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

Meng
meng,
<%
Response.Buffer = true;
if (Session == null || Session("member_id") == null) {
 Response.Redirect("login.asp");

}
%>
Are you sure it's getting set correctly?
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


 
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();
%>
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");
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
Points to b1xml2.

Fritz the Blank
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
As recommended

Chmod
Community Support Moderator @Experts Exchange