Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing variables to pages etc....

Status
Not open for further replies.

dodgyone

Technical User
Jan 26, 2001
431
GB
Please could somebody give me an example of setting a variable and then on the upcoming page(s) have code to receive the variable and perform an action.

I have a simple login screen (only needs to be pretty simple as not too sensitive) and on the secure pages I would like to send the variable to every one I access. I would like to enter the asp code by where if the variable does not exist on the page (in the asp code) then the person is redirected to the login page and so on. In other words every page takes the variable and then passes it on to the next secure page accessed.

I hope this makes sense.... Thanks

Marcus
 
First is the Login form
-----------------------
<html>
<%@ Language=VBScript %>
<head>
<meta http-equiv=&quot;Content-Language&quot; content=&quot;en-us&quot;>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=windows-1252&quot;>
<meta name=&quot;GENERATOR&quot; content=&quot;Microsoft FrontPage 4.0&quot;>
<meta name=&quot;ProgId&quot; content=&quot;FrontPage.Editor.Document&quot;>
<title>Login</title>
</head>

<body>
<form action=&quot;tableof.asp&quot; method=get>

<p align=&quot;center&quot;><font size=&quot;5&quot;>Distributor Login Form</font></p>

<p align=&quot;center&quot;>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Login <input type=&quot;text&quot; name=&quot;login&quot; size=&quot;20&quot;></p>
<p align=&quot;center&quot;>Password <input type=&quot;text&quot; name=&quot;password&quot; size=&quot;20&quot;></p>
<p align=&quot;center&quot;><input type=&quot;submit&quot; value=&quot;Submit&quot; name=&quot;LoginButton&quot;><input type=&quot;reset&quot; value=&quot;Reset&quot; name=&quot;B2&quot;>&nbsp;&nbsp;
</p>
<p align=&quot;center&quot;><font size=&quot;2&quot;>Powered by SQL Server 7<br><br>
written by: Douglas Poston<br>
<a href=&quot;mailto:dposton@universal1.com&quot;>dposton@universal1.com</a>
</font>
</p>
</form>
</body>
</html>
----------------------------------
Second is the accepting page
----------------------------------

<html><head>
<TITLE>Parts Lookup.asp</TITLE>
</head><body bgcolor=&quot;#FFFFFF&quot;>
<%pass=request.querystring(&quot;password&quot;)%>
<br>
<%
Set Conn = server.CreateObject(&quot;ADODB.Connection&quot;)
Conn.Open &quot;driver=SQL Server;server=yoursite.com;uid=user;pwd=pass;database=YourDatabase;&quot;
Set RS1 = Conn.Execute(&quot;SELECT * From Customers Where [CUSTOMER] ='&quot; & pass & &quot;'&quot;)
%>
------------
This is looking up a password in a SQL server database
---------
The <input type=&quot;text&quot; name=&quot;password&quot; ... is the value being passed to the second page and it is received into
<%pass=request.querystring(&quot;password&quot;)%> on the second page.

So the ...request.querystring(&quot;password&quot;)... has to match exactly as the name of the text box on the first form.
DougP, MCP

Visit my WEB site to see how Bar-codes can help you be more productive
 
Thanks for the code but I'm not really looking for anything that advanced.... I don't need to keep passwords in a database etc.

All I need is to be able to pass over the password and username variables from the login page onto the secure pages to check whether the person has logged in or not. For every secure page I would like to be able to check against the variable passed along etc (from the old page to the new page and so on along the chain).

Cheers for your help

Marcus
 
Use a session variable.

Upon login set Session(&quot;LoggedIn&quot;)= True

Then before any HTML info on each member page check the value of Session(&quot;LoggedIn&quot;).

If Not Session(&quot;LoggedIn&quot;) Then
Response.Redirect 'to a login page.
Else
' You're all clear.
End If.

Sort of like that.

Pandyon
 
Sorry, but could could you explain things a little further to me (I've not been using asp for long). Where does the code actually go on the page etc????

THIS IS ON THE FIRST PAGE:

<%
If Request.Form(&quot;login&quot;) = &quot;username&quot; AND Request.Form(&quot;password&quot;) = &quot;password&quot; Then
Response.Redirect &quot;private.asp&quot;
Else
If Request.Form(&quot;login&quot;) <> &quot;&quot; AND Request.Form(&quot;password&quot;) <> &quot;&quot; Then
Response.Redirect &quot;AccessDenied.htm&quot;
'Response.End
End If
End If
%>

RECEIVING PAGE:

Where does the code go... above <html> to receive straight away??????

Thanks for your patience...

Marcus
 
the Session(&quot;loggedin&quot;) needs to go before you output anything to the browser. This way, you can redirect the user if they aren't logged in.

So - it should really be one of the first lines on your ASP script.

So the pages that the users need to login on would start something like this:
Code:
<%@ Language=VBscript%>
<%If not Session(&quot;LoggedIn&quot;) then
 Response.redirect &quot;private.asp&quot; 
End if
%>

The best way to do it is to put the if statement into a include, then include the pages on all the pages that need authentication.

Example:
contents of checkLogin.asp
Code:
<%If not Session(&quot;LoggedIn&quot;) then
 Response.redirect &quot;private.asp&quot; 
End if
%>

how to include a file
Code:
<!--#include file=&quot;checkLogin.asp&quot;-->

hope that helps
leo
 
Dont look anywhere else but session variables sort out the login on the login page then subsequent pages are thus:

If session(&quot;loggedin&quot;)
yepee!
else
go away
end if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top