Click to See Complete Forum and Search --> : ASP: Using session to track the user who logged in


thebluestar136
05-23-2010, 04:18 AM
I have tried to use session to track/ say 'Hello' to the user who is online.
However, I'm very new to use this object and actually, I'm still not clear all about the global.asa file. I mean we write all methods about sessions we'll in it , then call it in the asp file.
Sometimes, to start session, we have to start application first. I'm not clear about this, you can explain it for me? thank you!
and here is my source code:
(I have just made an example to try, it's not enough)
loginForm.asp
<html>
<body>

<form method="post" action="login.asp">
<p>Username:
<input type="text" name="user">
</p>
<p> Password:
<input type="password" name="pass">
</p>
<p>
<input type="submit" name="submit" value="Sign in">
<br>
</p>
</form>
</body>
</html>
login.asp

<html>
<body>

<form method="post" action="login.asp">
<p>Username:
<input type="text" name="user">
</p>
<p> Password:
<input type="password" name="pass">
</p>
<p>
<input type="submit" name="submit" value="Sign in">
<br>
</p>
</form>
</body>
</html>

login.asp
Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
Xin chao,
<%
session_OnStart()
'response.Write (session("started"))
session("user") = request.QueryString("user")
response.Write (session("user"))
%>
</body>
</html>

yamaharuss
05-23-2010, 08:56 AM
You should google global.asa.

You don't start a session within an asp page like you are trying to do. For that matter, you may not even need global.asa, I'm not sure what you're trying to accomplish.

If you want to set a session value, you can do that on any asp page.

session("user") = "Bob"
response.Write ("Hello my name is " & session("user"))

Global.asa can be used to define variables within a session and/or at the start of the application. Session variables are set when a new user visits your site, application variables are set when your website is started or restarted.

thebluestar136
05-23-2010, 09:06 AM
Thank you very much,
hmm, I want to display the name of user after he or she logs into the website
it''s like the value of session['''username'] is the value got from loginForm : request.Query['''username']

yamaharuss
05-23-2010, 09:07 AM
session("user") = request.Querystring("username")
response.Write ("Hello my name is " & session("user"))

thebluestar136
05-23-2010, 09:11 AM
Oh, I did it in my source code but I made a small mistake :session("user") = request.QueryString("user")
and I have to write the session_Onstart() method in the global.asa, right?
hmm, would you mind showing me it in details, please!

yamaharuss
05-23-2010, 09:13 AM
Forget about global.asa

session("user") = request.Querystring("username")
response.Write ("Hello my name is " & session("user"))

is all you need... as long as the querystring "username" has a value... if you are using a form then you need to use request.Form("username")

This is very basic ASP stuff, I suggest you use Google to get some basics

thebluestar136
05-23-2010, 09:25 AM
Thank you,
It turns out I used request.QueryString while I used method ""POST" in the form:D. A ''stupid'' mistake! :|

yamaharuss
05-23-2010, 10:12 AM
If this is a public website you need to be sure to clean your data for injection before doing any queries.