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

Cookie Hell

Status
Not open for further replies.

craigward

Programmer
Nov 13, 2007
230
GB
Hi,

Not sure anyone is going to know why this is happening but here it goes.

I have a href which has a hard coded querystring with a username and password when you click on this you get sent through to login.asp below that checks the database and assigns a value to idadmin which is then stored in a cookie response.cookies("idAdmin").

At the bottom of login.asp the user is redirected to menu.asp, menu.asp has an include file called adminverify.asp that checks to see if request.cookies("idAdmin") is alive.

If I response.write(request.cookies("idAdmin")) response.end at the bottom of login.asp I always get the value I want problem is it doesn’t pass the value or should I say, adminverify.asp cannot see the value so redirects the user away.

However, if I just have response.write(request.cookies("idAdmin"))
response.end on the adminverify.asp which comes up blank and then right click and refresh that page the request.cookies("idAdmin”) value appears…. Where does it go and why does it take a second refresh to find it.

Any help would be appreciated.



Default.asp

Code:
<a href='[URL unfurl="true"]http://ip/uk?AdminPassword=password&adminName=admin'>Enter</a>[/URL]


Login.asp

Code:
<!--#include file="./includes/languages.asp"-->
<!--#include file="../inc/dbFunctions.asp"-->
<!--#include file="../inc/settings.asp"-->
<!--#include file="../inc/getSettingKey.asp"-->
<!--#include file="../inc/allSettings.asp"-->
<!--#include file="../inc/stringFunctions.asp"-->
<%

	adminname = Request.QueryString("adminName")
	adminPassword = Request.QueryString("AdminPassword")

'on error resume next
dim mySQL, conntemp, rstemp, pemail, ppassword

' form parameters
pAdminName		= formatfordb(getuserinput(request.QueryString("adminName"), 250))
pAdminPassword	= formatfordb(getuserinput(request.QueryString("adminPassword"), 250))

'response.write(pAdminName)
'response.write(pAdminPassword)

'response.end

if (pAdminName) = "" or (pAdminPassword) = "" then
	response.redirect "[URL unfurl="true"]http://ip/uk"'index.asp?message="&dictLanguageAdmin.Item(session("adminlanguage")&"_admin_login_2")[/URL]
end if

' check if data is correct and initialize admin session
'mySQL="SELECT * FROM wce_sys..wces_users WHERE wce_uid='" &pAdminName& "' AND wce_pw='" &pAdminPassword& "'"
mySQL="SELECT * FROM admins WHERE adminName='" &pAdminName& "' AND adminPassword='" &pAdminPassword& "'"
call getFromDatabase(mySQL, rstemp, "login")


if rstemp.eof then
  response.redirect "http:/ip /wceweb.dll"
end if

response.cookies("idAdmin")= rstemp("idAdmin")
response.cookies("idAdmin").Expires=date+1

‘response.write(request.cookies("idAdmin"))
‘response.end

call closeDb()

response.redirect "menu.asp"
%>



Top section of Menu.asp

Code:
<%
pidadmin= request.cookies("idAdmin")
pageId = 19
%>

<!--#include file="adminVerify.asp"-->
<!--#include file="../inc/settings.asp"-->
<!--#include file="../inc/dbFunctions.asp"-->
<!--#include file="../inc/getSettingKey.asp"-->
<!--#include file="./includes/auxFunctions.asp"-->
<%pcompany = getsettingkey("pcompany")%>
<!--#include file="header.asp"-->

<%



Adminverify.asp

Code:
<%

response.write(request.cookies("idAdmin"))
response.end

idAdmin = request.cookies("idAdmin")
if idAdmin="" then
 response.redirect "[URL unfurl="true"]http://ip/uk/wceweb.dll"[/URL]
end if

%>
 
Cookies are sent by the web server (IIS/APACHE) when the site is first requested. You cannot set and use a cookie without making another non-cached call to the server.

Try disabling the page cache on your asp page, this might resolve the re-fresh issue:

At the very top of the page:

Code:
<% 
Response.Expires = 0
Response.Expiresabsolute = Now() - 1 
Response.AddHeader "pragma","no-cache" 
Response.AddHeader "cache-control","private" 
Response.CacheControl = "no-cache"  
 %>

Everytime the page is requested, it will make a call back to the server (even when the back button is pressed). If a cookie exists, IIS will send it to your code and you can use it from there.



--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
Thanks for that. I tried it but it still doesn't work. As soon as i refresh the page the value appears. So odd.

Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top