|
Joined: Sep 2006
Posts: 1,111
Dawg Talker
|
OP
Dawg Talker
Joined: Sep 2006
Posts: 1,111 |
Hey all,
Anyone know how I can pull a cookie set by and .asp file into an html file using ???( i'm guessing java).
Here's the deal. I've got a site built with asp that has a members section (so, username and password) that set cookies for a successful login and member name and goes to subsequent pages using if/else statements. The client however wants to be able to edit these inside sections using macromedia contribute, meaning they have to be inside of html templates.
So I have the clientLogin.asp file running off of the link. On a correct login it redirects to clientContent.html. But I need the html page to check for a postive login before loading so you can't just copy and paste the clientContent.html url without hitting the login asp first.
Anyone done this before? Flap
Crowded elevators smell different to short people...
|
|
|
|
Joined: Sep 2006
Posts: 3,480
Hall of Famer
|
Hall of Famer
Joined: Sep 2006
Posts: 3,480 |
I'm not completely familiar with your set up, but if you want to write server side applications to check logins and the like, you should be using Perl, not Java.
What I would do is have the .asp file write a cookie with the username proclaiming a successful login, and then have a perl code which checks the login, and writes the correct output .html file only if the login is correct.
Basically you should be having a perl script check for a correct login (since HTML can't), and then writing out the html file if the login is correct. It's secure because the html file is never written if the login isn't successful, and thus can't be accessed illegitimately (without some access to the server)
~Lyuokdea
~Lyuokdea
|
|
|
|
Joined: Sep 2006
Posts: 520
All Pro
|
All Pro
Joined: Sep 2006
Posts: 520 |
http://www.quirksmode.org/js/cookies.html The link above explains cookies... cookies are stored on the client not on the server. This is not hard at all, simply place this in your asp code to write out the correct html using response.write("<script>blah</script>") Then inside the <script> have a javascript similar to below this... Code:
function checkCookie() { var nameEQ = "yourcookiename="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) document.redirect("whereever.html" else document.redirect("wherever2.html") } }
Syntax might not be right.. but this should get you on track. Also you should call this client side script by placing on your form tag onload="checkcookie()"
Last edited by Barfolemew; 08/29/07 03:49 PM.
"I'm a mog. Half man, half dog. I'm my own best friend."
|
|
|
|
Joined: Sep 2006
Posts: 520
All Pro
|
All Pro
Joined: Sep 2006
Posts: 520 |
Even easier why can't you use the Request.cookies("cookiename")... this calls the client to get a cookie by that name... if it exists the simply redirect like you have been doing using asp. I once was a web programmer and now am a dba... so forgive me as I haven't done web development in awhile and have lost touch a bit.
Nevermind I reread you post and see you need this done like I have above... that should work though.
Last edited by Barfolemew; 08/29/07 04:05 PM.
"I'm a mog. Half man, half dog. I'm my own best friend."
|
|
|
|
Joined: Sep 2006
Posts: 1,111
Dawg Talker
|
OP
Dawg Talker
Joined: Sep 2006
Posts: 1,111 |
yep, haven't got it working exactly yet, but that is definately down the right path.
Thanks
Crowded elevators smell different to short people...
|
|
|
|
Joined: Sep 2006
Posts: 15,015
Legend
|
Legend
Joined: Sep 2006
Posts: 15,015 |
I'm not 100% on what your trying to do.
But what I typically do, is use and <!-- #include file="<file name>" --> in my HTML code, and the include file is a small .asp script that checks the cookie for successful login, and if it fails, it redirects to the home page or something.
This way, if the login is not successful, they cannot get to the page, it redirects it before the rest of the HTML code displays.
I often set Session cookies for stuff like this as well, so I can just add a quick Authentication check whenever I need to without needing to verify the cookie repeatedly, particularly on a successful login, then when the session cookie expires(like 30 mins or so if unused), it requires them to login again.
We don't have to agree with each other, to respect each others opinion.
|
|
|
DawgTalkers.net
Forums DawgTalk Tailgate Forum Server side coding help
|
|