Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question How to block some urls from being accessed, and allow others based on conditions.

    I'm new to the forum, and hopefully I did a good job with the title.

    I'm trying to create a script that will block people from viewing certain pages of a site if they have not uploaded a photo. I don't have server side scripting access, so I'm limited to what can be done, and need to use Javascript.

    Essentially I want to block all urls except for a handful. When a person reaches a blocked page, I want to redirect them to the photo upload page.

    The way that I find out if they have uploaded a photo is by this: $member_profile_image. That is a snippet the the platform gives that will display the url in text on the webpage. It doesn't require anything other than what I've given to do that, so the <?php reference to it in the script isn't needed, nor will it work because I don't have access to php.

    What I've been trying to do thus far is finding out the indexOf a particular word in the default photo's address on the server. Default meaning, if you haven't uploaded a photo, you have the default one that everyone does when they first join. The address for the photo contains the word "Default", and it indexes out at 22.

    So, if the index value shows up at 22, and they are on a blocked page, redirect them to the photo upload page and alert("you have to upload a photo"). If the index value shows up at 22 and they are not on a blocked page, do nothing at all. What seems the easiest since I want pretty much all urls to blocked aside from a handful, would be to just say, if these urls and index of 22, do nothing, else redirect and alert.

    What I'm working with is below, but it's total fail and I don't know why:

    Code:
    image = "$member_profile_image"; // Displays the url as text, no <?php.
    upload = image.indexOf("Default") === 22; // Default indexes at 22 in the url
    myurls = [
              'http://www.myurl1.com',
              'http://www.myurl1.com/wiki.htm',
              'http://www.myurl1.com/?page=login&cmd=confirm,
              'http://www.myurl1.com/blog.htm'
                ];
        if(myurls.indexOf(window.location) > -1 && upload)
            {
               //This is where I need the code to do nothing at all.
            }
           else{
                  alert("you have to upload an image to access this page");
                window.location.replace("http://www.myurl1/member/?page=settings");
            }
    I've tried it this way and I can't get much of anything to happen at all. Anyone have any advice or tip on what could be going wrong?
    Last edited by Blinkin_Blippy; 11-09-2012 at 06:02 AM. Reason: fixed code tag

  • #2
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I'm not sure where my topic content went, or if I'm doing something wrong, but here it is again. I'm not able to see it anymore for some reason.

    @Mods, my apologies for the double posting of this topic, and please remove the other one that is identical.

    I'm new to the forum, and hopefully I did a good job with the title.

    I'm trying to create a script that will block people from viewing certain pages of a site if they have not uploaded a photo. I don't have server side scripting access, so I'm limited to what can be done, and need to use Javascript.

    Essentially I want to block all urls except for a handful. When a person reaches a blocked page, I want to redirect them to the photo upload page.

    The way that I find out if they have uploaded a photo is by this: $member_profile_image. That is a snippet the the platform gives that will display the url in text on the webpage. It doesn't require anything other than what I've given to do that, so the <?php reference to it in the script isn't needed, nor will it work because I don't have access to php.

    What I've been trying to do thus far is finding out the indexOf a particular word in the default photo's address on the server. Default meaning, if you haven't uploaded a photo, you have the default one that everyone does when they first join. The address for the photo contains the word "Default", and it indexes out at 22.

    So, if the index value shows up at 22, and they are on a blocked page, redirect them to the photo upload page and alert("you have to upload a photo"). If the index value shows up at 22 and they are not on a blocked page, do nothing at all. What seems the easiest since I want pretty much all urls to blocked aside from a handful, would be to just say, if these urls and index of 22, do nothing, else redirect and alert.

    What I'm working with is below, but it's total fail and I don't know why:

    [CODE]
    image = "$member_profile_image"; // Displays the url as text, no <?php.
    upload = image.indexOf("Default") === 22; // Default indexes at 22 in the url
    myurls = [
    'http://www.myurl1.com',
    'http://www.myurl1.com/wiki.htm',
    'http://www.myurl1.com/?page=login&cmd=confirm,
    'http://www.myurl1.com/blog.htm'
    ];
    if(myurls.indexOf(window.location) > -1 && upload)
    {
    //This is where I need the code to do nothing at all.
    }
    else{
    alert("you have to upload an image to access this page");
    window.location.replace("http://www.myurl1/member/?page=settings");
    }
    [CODE]

    I've tried it this way and I can't get much of anything to happen at all. Anyone have any advice or tip on what could be going wrong?

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,519
    Thanks
    77
    Thanked 4,381 Times in 4,346 Posts
    In what way does it not work?

    In this code:
    Code:
    if(myurls.indexOf(window.location) > -1 && upload) 
    { 
        //This is where I need the code to do nothing at all. 
    }
    Your comment *IS* "nothing at all", so indeed if it reached that point it will do nothing at all.

    But you need to be more speciific about what and how it doesn't work.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    In what way does it not work?

    In this code:
    Code:
    if(myurls.indexOf(window.location) > -1 && upload) 
    { 
        //This is where I need the code to do nothing at all. 
    }
    Your comment *IS* "nothing at all", so indeed if it reached that point it will do nothing at all.

    But you need to be more speciific about what and how it doesn't work.
    It doesn't block the urls I have listed, and indeed does do nothing, but it also does nothing on any of the pages that I don't have listed as well. So the else statement doesn't seem to be working at all.

    I've also tried to test each aspect of the code, as in before the else statement.

    Code:
    image = "$member_profile_image"; 
      upload= image.indexOf("Default") = "22";
     myurls = [ 
     'http://www.websiteforyou.spruz.com', 'http://www.websiteforyou.spruz.com/wiki.htm', 'http://www.websiteforyou.spruz.com/?page=login&cmd=confirm, 'http://www.websiteforyou.spruz.com/blog.htm' ]; if(myurls.indexOf(window.location) > -1 && upload) {
    alert("something");
    }
    I'm unable to figure out why that isn't firing at all. I go to those pages, and no alert box pops up.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,519
    Thanks
    77
    Thanked 4,381 Times in 4,346 Posts
    Well, you have two choices:

    (1) Learn to use a JavaScript debugger. I like the one in Chrome best, but the one in MSIE 9 is almost identical (just a tad harder to read) and FireBug for FireFox is fine as well. In the long run this is far far and away the better choice. It will save you dozens of hours of asking other people what is wrong with your code when 30 seconds in the debugger will point it out to you.

    (2) Post a link to your actual page so we can use a debugger on it.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    Blinkin_Blippy (11-09-2012)

  • #6
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    Well, you have two choices:

    (1) Learn to use a JavaScript debugger. I like the one in Chrome best, but the one in MSIE 9 is almost identical (just a tad harder to read) and FireBug for FireFox is fine as well. In the long run this is far far and away the better choice. It will save you dozens of hours of asking other people what is wrong with your code when 30 seconds in the debugger will point it out to you.

    (2) Post a link to your actual page so we can use a debugger on it.
    I'm thankful you mentioned the debugger. I don't have the foggiest idea how to use one, and would probably be best enlightened with a link of a good tutorial for it instead, so I can take some self help procedures, rather than temporary enlightenment.

    What we be the easiest way to educate myself on using the debugger?

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,519
    Thanks
    77
    Thanked 4,381 Times in 4,346 Posts
    https://developer.chrome.com/extensi...debugging.html

    That assumes you will use Chrome. I would; it's not a LOT different than the other debuggers, but it's just enough different to be a little more "friendly".
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    Blinkin_Blippy (11-10-2012)

  • #8
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    https://developer.chrome.com/extensi...debugging.html

    That assumes you will use Chrome. I would; it's not a LOT different than the other debuggers, but it's just enough different to be a little more "friendly".
    Thank you. After learning css and Html, I definitely use chrome or firefox. I soooo hate IE, and look forward to it's demise lol.


  •  

    Tags for this Thread

    Posting Permissions

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