473,396 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Comparing a session value to a querystring

Hi,

I'm attempting to limit access to a page without creating a whole load of session values and there for re-writing the page. So I've come up with the following code on a test page
Expand|Select|Wrap|Line Numbers
  1. <%@ Language=VBScript %>
  2. <%Option Explicit%>
  3. <%
  4. IF session("Userid")<>request.Querystring("Stu") and session("Userid2")<>request.Querystring("Stu") Then
  5.         response.redirect "../../login/errors/notloggedin.asp"
  6. End if
  7. %>
  8.  
This in theory should prevent the user from editing the url themselves as if their session value doesn't match the value in the url it should re-direct them to an error. For some reason it's not working though even though that's literally all the code there is on the page.

If I get it to print out the session userid and the url stu value they are the same yet it still redirects me to the error page. What am I missing?
Apr 24 '08 #1
4 1980
deric
92
How about the Userid2, is it the same with the Stu value?
I'm not sure, but you can try converting the session values to string...
Apr 25 '08 #2
userid2 would be blank if userid has a value. It's basically 2 different applications sharing the same pages so the user will only ever have one or the other. I'll give the string thing a try. Thanks
Apr 25 '08 #3
deric
92
So that's it.. either of the two condition should work, then you should use the OR operator and not the AND.
Expand|Select|Wrap|Line Numbers
  1. IF session("Userid")<>request.Querystring("Stu") OR session("Userid2")<>request.Querystring("Stu") Then
If any one of them is true, then the result is true.
If both are false, then the condition is not satisfied, it will result to false and will not go inside of the IF.
Btw, you need not convert them to string.
Apr 26 '08 #4
So that's it.. either of the two condition should work, then you should use the OR operator and not the AND.
Expand|Select|Wrap|Line Numbers
  1. IF session("Userid")<>request.Querystring("Stu") OR session("Userid2")<>request.Querystring("Stu") Then
If any one of them is true, then the result is true.
If both are false, then the condition is not satisfied, it will result to false and will not go inside of the IF.
Btw, you need not convert them to string.
Thanks but using OR wouldn't work. The aim is to redirect the user if they try to access a page that doesn't have their userid in the url. So as they will only have either userid or userid2 and the other will always be blank switching it to an or will cause them to be re-directed all the time even when trying to access their own page.
May 8 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: PM | last post by:
I'm trying to make a kind of search history containing the 3 last searched words. So I'm using 3 Session Variables: Word1 / Word2 / Word3. In order to get this history working, I need to put the...
15
by: Thomas Scheiderich | last post by:
I am trying to understand Session variables and ran into a question on how they work with data that is passed. I have an HTM file that calls an ASP file and sends the name either by GET or POST....
3
by: catweezle2010 | last post by:
Hello NG, I have three files (default.aspx, search.aspx and work.aspx). The way is: login on default (if session is newsession). The loginname I write into as sessionvariable (username). So I...
12
by: MrHelpMe | last post by:
Hello again all, I've finished my whole application and now I don't like the whole session variables that I am using. I have a form, user fills in info clicks submit and using CDOSYSMail an...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.