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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Page Restriction Code Needs Changing

Status
Not open for further replies.

Ladyborg

Programmer
May 11, 2002
208
US
I have a simple script on a page to restrict access based on whether the person is logged in to the site or not, it is:

<%@LANGUAGE=&quot;VBSCRIPT&quot;%>
<%
If Session(&quot;MM_UserName&quot;) = &quot;&quot; Then
Response.Redirect(&quot;../badpage.asp?pagetype=1&quot;)
End If
%>
<html>.................................

I'd like to make it so that only someone (say their log in name is jonathan) can see the page.

How do I do that? I tried
<%
If Session(&quot;MM_UserName&quot;) = &quot;jonathan&quot; Then

but that didn't work, it was as if the code wasn't there at all, anyone can see the page.
ladyborg64x64.gif
Ladyborg
&quot;Many of life's failures are people who did not realize how close they were to success when they gave up.&quot; [Thomas A. Edison]
 
did u do this?
Session(&quot;MM_UserName&quot;)=&quot;jonathan&quot; in any previous pages?
iie did u set ther session to jonathan?

if yes give me the code.
 
No, I figured if anyone tried getting on that page and their cookie was not set (i.e., they were not logged in as jonathan), they would get the redirect page.
ladyborg64x64.gif
Ladyborg
&quot;Many of life's failures are people who did not realize how close they were to success when they gave up.&quot; [Thomas A. Edison]
 
hmm....
if I get this right then set a variable (local) in the page
dim loginPerson
loginPerson = &quot;jonathan&quot;

' as stated there has got to be some way for you to be logging in the users. so perform the same type of function as you did there as you seem worried about session variables. ie: select from the DB where = to jonathan
if you are at EOF then the condition fails and you response.redirect them

hope that helps _________________________________________________________
for the best results to your questions: FAQ333-2924
01001111 01101110 01110000 01101110 01110100
onpnt2.gif
[/sub]
 
Thanks!
ladyborg64x64.gif
Ladyborg
&quot;Many of life's failures are people who did not realize how close they were to success when they gave up.&quot; [Thomas A. Edison]
 
If you already have all the login pages and stuff like that set up then all you need to do is change the security header on the page that you wish to restrict to one username slightly as shown below

<%@LANGUAGE=&quot;VBSCRIPT&quot;%>
<%
If Session(&quot;MM_UserName&quot;) <> &quot;jonathan&quot; Then
Response.Redirect(&quot;../badpage.asp?pagetype=1&quot;)
End If
%>
<html>.................................

That way, anyone who's username does not equal (<>) jonathan will be redirected to the badpage.asp
 
Thanks a million! That was EXACTLY what I needed!

I knew it would be simple!
ladyborg64x64.gif
Ladyborg
&quot;Many of life's failures are people who did not realize how close they were to success when they gave up.&quot; [Thomas A. Edison]
 
Question:

The code above worked great BUT it is requesting jonathan login before every single page! How do I make it hold the jonathan value? The original code does it just fine, you only need login once.

Thanks!
ladyborg64x64.gif
Ladyborg
&quot;Many of life's failures are people who did not realize how close they were to success when they gave up.&quot; [Thomas A. Edison]
 
beacuse the code given by AdmanOK will allow only &quot;jonathan&quot; and not other users. Known is handfull, Unknown is worldfull
 
But once jonathan is logged in, all the pages that contain the code below, shouldn't require him to login again should it? Because THAT is what is happening.

<%@LANGUAGE=&quot;VBSCRIPT&quot;%>
<%
If Session(&quot;MM_UserName&quot;) <> &quot;jonathan&quot; Then
Response.Redirect(&quot;../badpage.asp?pagetype=1&quot;)
End If
%>
ladyborg64x64.gif
Ladyborg
&quot;Many of life's failures are people who did not realize how close they were to success when they gave up.&quot; [Thomas A. Edison]
 
why dont u put a response.write in the page that is acting weird?

response.write Session(&quot;MM_UserName&quot;)
response.end
see what is the output
can u please give it to me?
Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top