Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Protected access to a page

  1. #1
    Join Date
    Dec 2005
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Protected access to a page

    Is there any javascript code available that will allow a page to display only when there is additional text added to the url? I tried using a password protect code but it did not work.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <script type="text/javascript">
    if(window.location.href.indexOf("?redcrestedwarbler") == -1 && window.location.href.indexOf("&redcrestedwarbler") == -1) window.location.replace("http://www.google.com/");
    </script>
    Note that it doesn't actually offer any additional security at all.
    Last edited by Twey; 03-27-2006 at 08:57 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    redcrestedwarbler?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I think it's a rare bird. I just scraped it off the wall.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I guess my question was - Won't that be almost as good as hard coded link to Google?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It's one line of Javascript... hardly "hard-coded"
    Code:
    <script type="text/javascript">
    var keyword = "redcrestedwarbler", // Keyword
      badurl = "http://www.google.com/"; // Page to go to on failure
    
    if(window.location.href.indexOf("?" + keyword) == -1 && window.location.href.indexOf("&" + keyword) == -1) window.location.replace(badurl);
    </script>
    techsol: Change the bits in red, if you didn't figure that out already
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I was thinking more along the lines of testing for any appended characters via a regex. Mike and you are probably better at this than I but isn't there a token for any letter and one for any number? Just check against a 'one or more occurrences' of either and you've got it.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Quote Originally Posted by John
    I was thinking more along the lines of testing for any appended characters via a regex.
    I sort of got the impression the OP wanted a specific string.
    isn't there a token for any letter and one for any number?
    \d for a digit, or [a-zA-Z] for a letter. But I don't think that's what was wanted here.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Dec 2005
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I put the code into my page and replaced the items in red. I tried to get to the correct page by putting this url in my browser: http://www.mysite.com?keyword="redcrestedwarbler" where www.mysite.com is the protected page on my site and "redcrestedwarbler" would be the keyword but I could not get it to work.

    What am I doing wrong? I am not javascript savvy…thanks

  10. #10
    Join Date
    Dec 2005
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I finally figured it out. You have to add ?keyword to the end of the page url. Is there any way to write the code such that the keyword would disappear from the URL when the correct page is selected. When I add this to the end of my page url it goes to the right page but the ?keyword appears in the URl.

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
  •