SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 32 of 32
  1. #26
    SitePoint Evangelist Brandon Luhring's Avatar
    Join Date
    Apr 2002
    Location
    IN, USA
    Posts
    455
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, but since they were smart enough to open a new window to submit more, pretty much says that they are not your average AOL user, either...

    Many people have cookies turned off, and when they see your error message, they'll know they can f* with your cookies.

    It is the best choice you have if you don't want to have a login service. I was just letting you know that it's about as secure as your previous attempt.

  2. #27
    SitePoint Wizard
    Join Date
    Jan 2001
    Location
    Milton Keynes, UK
    Posts
    1,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't check to see whether Cookies are enabled/disabled in one ASP page. See the article below.

    ASP101 : An Overview of Cookie Detection in ASP (with Code!)

    The article shows how to check for enabled cookies by redirecting the user. However, if you're going to check for cookies after a form submission you can simply write a cookie value (eg Response.Cookies("cookiesenabled") = "true") on the page where the form is displayed. This will allow you to check this cookie value on the form processing page. If the cookie value matches what was set on the form page then they've got cookies enabled.

  3. #28
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Interesting article, but how do you explain this?
    Originally posted by JohnSaunders
    I GOT IT TO WORK!!!!!!!

  4. #29
    Git-R-Done
    Join Date
    Nov 2001
    Posts
    1,194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Interesting article, but how do you explain this?
    Actually, I thought it had worked the first time I tested it (I guess because my current browser session was still using cookie that had been set), but it didn't. When I tried it on the browser that had cookies turned off the whole time, it just displayed the form instead of the 'cookies must be enabled' message.

    I'm sure there's probably a tiny % of users out there who may go and delete the cookie but it's more difficult to get around then just opening a new browser window.

    Can somebody tell me what I need to do to get this thing working? Will this work if I add it to the script instead of having the line that contains isEmpty?

    If Len(Trim(ObjectName)) = 0 Then

    Or do I need to do something like this: http://www.asp101.com/articles/john/...ct/default.asp
    John Saunders

  5. #30
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by JohnSaunders
    Actually, I thought it had worked the first time I tested it (I guess because my current browser session was still using cookie that had been set), but it didn't.
    D'oh! Well shane's suggestion looks like your best bet. It's an interesting piece of info as well about processing order. Everyone knows the order scripts are executed in and things like that, but that's something I hadn't come across before having never tried to detect cookies. Nice one shane!

  6. #31
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just to clear up all the confusion about checking whether the cookie was equal to nothing or not.....

    Nothing is a special VBScript keyword, which acts as an null/empty object, i.e. setting an object to Nothing calls the object's deinitialisation routine, and assigns it a null pointer, thereby releasing the previously occupied memory.

    The statement "if x = 5" compares the value of the variable x with the number 5, i.e. these types of statement perform comparisons by value.

    Since objects aren't simply values, they cannot be compared in this way - surely no one would attempt to compare two objects a Dictionary object with an FSO object!!!?

    Likewise, we cannot compare an object with Nothing.

    So how do we see if an object is Nothing? It's breathtakingly simple - use the "If [objectname] Is Nothing" statement!!! e.g.[vbs]If MyObject Is Nothing Then[/vbs]
    This statement is admittedly VERY poorly documented in the VBScript help file, but that's pretty much all there is to it anyway!

    However, since cookies will only ever containt a value (not an object), there is no point performing such a check. I myself set a cookie called "CookiesEnabled" to the value "true" (as a string, not the VBScript True constant), and then see if the cookie is now equal to this value.

    Incidentally JohnSaunders, in your penultimate post (at this time anyway) your code is completely wrong because you appear to be interchangably using two variables called "stCount" and "Count" throughout!!! This will never work in the intended fashion!!!

    (Presumably at some point you decided to change the variable name from one to the other but never finished the job?!!)
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!

  7. #32
    Git-R-Done
    Join Date
    Nov 2001
    Posts
    1,194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK...I've put a lot of time in today trying to get this to work and I just can't seem to get it to do what I need to do. I have a form in an .html page that a visitor has to fill out before acessing a certain .asp page. In order for a visitor to access this page, the variables from the form need to be sent to it, or it will direct the visitor back to the .html page. Therefore, I put a code in the top of the cookies.asp file to try and pass the variable but it doesn't seem to be working. If the colEmail=request.form("colEmail") is at the top of the script, it comes up with an error, if it is at the bottom, it acts like it's not in the file and seems to ignore it.

    Can somebody look at my code below and tell me what I need to do to get this to work? I am not really familiar with ASP and this whole thing is way more advanced than I ever imagined it would be and I'm stumped. It is currently going back to the .html page (form) whether cookies are turned on or off. It is supposed to go to the .asp page if they are turned on and an error.html page if they are turned off.

    This is the .asp page the form posts to:
    Code:
    <%@Language="VBScript"%>
    
    <%
    Option Explicit
    Response.Buffer = True
    
    Dim bCookies ' T/F indicating cookies enabled.
    Dim strURL   ' URL to this page.
    Dim strQS    ' QueryString of initial request.
    
    bCookies = Request.QueryString("cookies")
    
    Select Case LCase(bCookies)
       Case "true", "false"
          bCookies = CBool(bCookies)
       Case Else
    
          If strQS <> "" Then strQS = "?" & strQS
    
          Response.Redirect "cookies.asp?from=" _
             & Server.URLEncode(strURL & strQS)
    End Select
    %>
    
    ' Redirect to an error page if cookies are not on
    <%
    bCookiesEnabled = Request.Cookies("cookie_test")
    If bCookiesEnabled = (bCookiesEnabled = "false") Then
      Response.Redirect "http://www.domain.com/error.html"
    End If
    %>
    
    ' If colEmail isn't being posted to the
    ' script send the visitor back to form
    <%
    If Request.Form("colEmail") = "" Then
      Response.Redirect "http://www.domain.com/form.html"
    End If
    %>
    
    <html>
    page here
    </html>

    This is the cookies.asp script that the .asp above is sent to, to check whether cookies are turned on or not:

    Code:
    <%@ Language="VBScript" %>
    
    ' Pass colEmail variable back to .asp script
    <%
    colEmail=request.form("colEmail")
    %>
    
    ' Tell the page whether cookies are turned on or off
    <%
    Option Explicit
    Response.Buffer = True
    
    Dim strThisScriptName
    strThisScriptName = Request.ServerVariables("URL")
    
    Dim strFrom
    
    If Request.QueryString("action") <> "checkcookie" Then
    
       strFrom = Request.QueryString("from")
       If strFrom = "" Then
          strFrom = Request.ServerVariables("HTTP_REFERER")
       End If
       If strFrom = "" Then
          strFrom = "/"
       End If
    
       Response.Cookies("cookie_test") = "true"
       Response.Cookies("cookie_test").Expires = Date + 1
    
       Response.Redirect strThisScriptName & "?from=" _
          & Server.URLEncode(strFrom) & "&action=checkcookie"
    Else
       Dim bCookiesEnabled
    
       bCookiesEnabled = Request.Cookies("cookie_test")
       bCookiesEnabled = (bCookiesEnabled = "true")
    
       strFrom = Request.QueryString("from")
    
       If InStr(1, strFrom, "?", 1) = 0 Then
          strFrom = strFrom & "?"
       Else
          strFrom = strFrom & "&"
       End If
    
       Response.Redirect strFrom & "cookies=" & bCookiesEnabled
    End If
    %>
    Any help would be greatly appreciated.
    Last edited by JohnSaunders; Sep 24, 2002 at 11:53.
    John Saunders


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •