Solved

jsp or javascript - cookies enabled

Posted on 2002-07-30
2
305 Views
Last Modified: 2008-02-01
I was using the followign script - and all is good except
that is was discovered that when a person first opens there browser and if they first go to the page with this code, they will be forwarded to the disable cookies page even if there cookies are not disable, a refresh will solve the problem, but is there another way???

<%-- if cookies are disabled - will forward to enable cookies page--%>
<%
   String cookies = request.getHeader("Cookie");
   boolean  cookiesEnabled = true;
   if (cookies == null) {
   cookiesEnabled = false;
%>  
   <jsp:forward page="enable-cookies-e.jsp"/>
<%
   } else {
%>
  <%-- cookies are fine - stay here--%>
<% } %>
0
Comment
Question by:schroom
2 Comments
 
LVL 22

Expert Comment

by:CJ_S
ID: 7188165
Write a cookie first then read the cookie. Don't know the JSP code.

CJ
0
 
LVL 15

Accepted Solution

by:
OMC2000 earned 200 total points
ID: 7188261
There are two possible solutions: server and client based.
CJ S mentioned Server side solution.
Since there is no relaible way to check whether cookies enabled or not in general from server side
You may make the first page that
- attempts to set your application cookies and
- contains only Javascript code that loads another page that will check your application cookies;
<script language="javascript">
     window.navigate("checkCookies.jsp");
</script>

checkCookies.jsp will look like your code above with only exception. You should check your application cookies, not general ones.

client side solution based on DHTML
<script language="javascript">
var bEnabled = navigator.cookieEnabled;
if ( bEnabled ) {
window.navigate("good-luck-you-are-able-to-work.jsp");
} else {
window.navigate("enable-cookies-e.jsp");
}
</script>




0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now