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

Cookies help needed please

Status
Not open for further replies.

osh

Technical User
Aug 24, 2002
3
US
I have cross posted this in the javascript forum as well..

I have a cgi progran that uses the following to check for a cookie on a users browser and then let him access the program.

sub checkpass {
if (!((&getCookie('admin') eq $password)||((($user_data{password} eq $password)||(eval(crypt($user_data{password},substr(crypt($user_data{password},'9A$ghj&7ecb9!11x'),5,2))) eq 'rcFFTesTLKr2g'))&&($user_data{cgifunction} eq "admin")))) {

I would like to use the same function to check if the cookie is there with a static page, if it is let him see it and if it is not re-direct him to another page.

I was hoping this could be done in javascript but I have never used cookies in JS before.

Any help would be much appreciated.

Thanks
Rob
 
this indeed can be done with javascript. I do it all the time.

before all your javascript code, make sure javascript is enabled by using the code:

<noscript>
You must have javascript enabled to view this page<br>
</noscript>

Now for the rest of the page, you would use the document.write() method for each line of code. This way, if javascript is disabled, they won't see any of the code and they'll only see the content between the <noscript> tags.

Now, check for the cookie using your javascript function checkpass().

If the cookie does not exist, use this bit of code where it applies:

location.replace('cookieError.html')

cookieError.html would contain something like:

<body>
Make sure cookies are enabled and try again!<br>
</body>

Hope that helps!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top