Re-direct to page if user hasn't come from a preferred location

Discussion in 'JavaScript' started by Bobby Roy Bates, Feb 27, 2011.

  1. #1
    Hello all,

    Thought i would register here after looking through the forums and seeing alot of good advice. this is want i want to know.

    i know this is possible becuase i have seen it before a few years back but cant remember how to do it.

    To add extra security for a page on my website i want to build a javascript that redirects a user if they havnt come from a sertin page on my website.

    for example:

    download.html can only be accessed if its come from index.html so the user cannot put the web address directly in the address bar.

    can anyone help me with this:confused:

    Bobby
     
    Bobby Roy Bates, Feb 27, 2011 IP
  2. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #2
    you should do this serverside via checking the http_referer value and not in js, if security is the reason for it.
     
    dimitar christoff, Feb 27, 2011 IP
  3. Bobby Roy Bates

    Bobby Roy Bates Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    im sorry im quite a newb when it comes to things like that can you explain in more detail?
     
    Bobby Roy Bates, Feb 27, 2011 IP
  4. Buttondown

    Buttondown Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    JS is executed client-side, meaning that the client can choose to ignore or modify it. For this reason, it is not a safe way to secure your site. It would be better to look at the HTTP referer header server-side (e.g. PHP, ASP, Rails, etc.) that shows where the user has come from and redirect them if necessary.
     
    Buttondown, Feb 27, 2011 IP
  5. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #5
    Using asp.net something like:
    
    <%
    If Request.UrlReferrer.ToString.StartsWith("http://www.mypreferredreferringurl.com") Then
        Response.Redirect("Default.aspx")
    Else
        Response.Redirect("Default2.aspx")
    End If
    %>
    
    Code (markup):
     
    camjohnson95, Feb 28, 2011 IP