The forum of the forums

Would you like to react to this message? Create an account in a few clicks or log in to continue.
The forum of the forums
4 posters

    HTML page accessible only to logged in users

    Ayushka
    Ayushka
    New Member


    Posts : 7
    Reputation : 1
    Language : en

    Solved HTML page accessible only to logged in users

    Post by Ayushka June 25th 2023, 5:13 pm

    Hello, I'd like to ask - is it possible to make HTML pages only visible to logged in users?
    Razor12345
    Razor12345
    Support Moderator
    Support Moderator


    Male Posts : 1575
    Reputation : 266
    Language : Ukr, Rus, Eng
    Location : Ukraine

    Solved Re: HTML page accessible only to logged in users

    Post by Razor12345 June 25th 2023, 5:19 pm

    Good evening!

    This issue has been discussed in this topic.

    If you need more detailed instructions, please specify:
    1) link to the HTML page.
    2) what do you want to make available to guests and what do you want to make available to registered users



    HTML page accessible only to logged in users Screen51

    skouliki and TonnyKamper like this post

    Ayushka
    Ayushka
    New Member


    Posts : 7
    Reputation : 1
    Language : en

    Solved Re: HTML page accessible only to logged in users

    Post by Ayushka June 26th 2023, 2:32 am

    Razor12345 wrote:Good evening!

    This issue has been discussed in this topic.

    If you need more detailed instructions, please specify:
    1) link to the HTML page.
    2) what do you want to make available to guests and what do you want to make available to registered users

    Thank you for answering I love you I looked at the topic and tried using that code, but it didn't work for me blackeye but then again, I might've used it wrongly :/ could you please specify how to use that code, just to make sure I didn't make a mistake?

    Basically, that is what I'd like to do - I want my HTML pages and their content to be only accessible to users who're logged in. For guests it could say something like "You don't have a permission to view this page" or so.
    I deleted the page after I couldn't make it inaccessible to guests :/
    Niko
    Niko
    Helper
    Helper


    Male Posts : 3231
    Reputation : 248
    Language : English, Italian, French
    Location : Italy

    Solved Re: HTML page accessible only to logged in users

    Post by Niko June 26th 2023, 8:46 am

    Coucou @Ayushka

    that is actually possible, if you select to use the header and footer of the forum for the HTML page Wink
    Despite being possible, it is a really weak solution, so any visitor only has to disable javascript to access the content easily

    I don't know if you still want to try in this way Embarassed
    If so, please provide a demo HTML page so that I can provide you a code based on your forum and forum version
    Razor12345
    Razor12345
    Support Moderator
    Support Moderator


    Male Posts : 1575
    Reputation : 266
    Language : Ukr, Rus, Eng
    Location : Ukraine

    Solved Re: HTML page accessible only to logged in users

    Post by Razor12345 June 26th 2023, 10:19 am

    Ayushka wrote:

    Thank you for answering I love you I looked at the topic and tried using that code, but it didn't work for me blackeye but then again, I might've used it wrongly :/ could you please specify how to use that code, just to make sure I didn't make a mistake?

    Basically, that is what I'd like to do - I want my HTML pages and their content to be only accessible to users who're logged in. For guests it could say something like "You don't have a permission to view this page" or so.
    I deleted the page after I couldn't make it inaccessible to guests :/

    As Niko said above, this code will work if you enable the forum header and footer to be displayed on the HTML page

    HTML page accessible only to logged in users Scree179

    If you don't use a forum header and footer, we need an extra action - we load the data from the forum homepage and check if the "Logout" button is available. If it is, we show the content to the user. If not, we show the content to the guest.

    You still haven't specified the forum address and version, so this code is like a demo for Invision.

    Code:
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /><style>
     
    .users {
    background-color: green;
    border: 3px solid green;
    display: none;
    }
     
    .guests {
    display:none;
    background-color: blue;
    border: 3px solid blue;
    }
     
    </style>      <title>Заголовок страницы</title>     
    <div class="guests">
                        
       <h1>
                            <span class="text__guest">Hello, guest! You need to register or log in to see this page.</span>           
       </h1>
    </div>
    <div class="users">
                        
       <h1>
                            <span class="text__user">Hello, user!You see this page because you are authorised</span>           
       </h1>
    </div><script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>          <script>
          window.addEventListener('load', function() {
            let url = location.origin;
              $.ajax({
            url: url,
            method: "GET",
            data: 'a.mainmenu',
            dataType: "html",
            success: function (data) {

              let div = document.createElement('div');
              div.innerHTML = data;
              let find_el = div.querySelector('#submenu');

              let checkAuth = find_el.querySelector("a#logout");

            if (checkAuth) {
    document.querySelector('div.users').style.display = 'block';
    } else {
    document.querySelector('div.guests').style.display = 'block';
    }
              },
            error: function (xhr, status, error) {
              console.log("AJAX request error:" + error);
            }
          });
              });
        </script>

    Result:

    HTML page accessible only to logged in users Scree180

    Text on the HTML page if I log out of my account

    HTML page accessible only to logged in users Scree181

    For me to be able to make this code to fit your forum version, please specify the forum address, the HTML page address and the forum version.



    HTML page accessible only to logged in users Screen51

    TonnyKamper likes this post

    Ayushka
    Ayushka
    New Member


    Posts : 7
    Reputation : 1
    Language : en

    Solved Re: HTML page accessible only to logged in users

    Post by Ayushka June 27th 2023, 4:27 am

    Wow, thank you both so much for explaining this to me! I love you

    On my HTML pages I don't want to have the forum header and footer displayed if possible - here's the link for the html page I just created for this purpose: click, forum version should be ModernBB
    Razor12345
    Razor12345
    Support Moderator
    Support Moderator


    Male Posts : 1575
    Reputation : 266
    Language : Ukr, Rus, Eng
    Location : Ukraine

    Solved Re: HTML page accessible only to logged in users

    Post by Razor12345 June 27th 2023, 8:27 am

    Code:
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /><style>
     
    .users {
    background-color: green;
    border: 3px solid green;
    display: none;
    }
     
    .guests {
    display:none;
    background-color: blue;
    border: 3px solid blue;
    }
     
    </style>      <title>Заголовок страницы</title>   
    <div class="guests">
                                
       <h1>
                                  <span class="text__guest">Hello, guest! You need to register or log in to see this page.</span>             
       </h1>
    </div>
    <div class="users">
                                
       <h1>
                                  <span class="text__user">Hello, user!You see this page because you are authorised</span>             
       </h1>
    </div><script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>          <script>
          window.addEventListener('load', function() {
            let url = location.origin;
              $.ajax({
            url: url,
            method: "GET",
            data: 'ul#modernbb-nav-menu',
            dataType: "html",
            success: function (data) {
     
              let div = document.createElement('div');
              div.innerHTML = data;
     console.log(div);
              let find_el = div.querySelector('ul#modernbb-nav-menu');
              let checkAuth = find_el.querySelector("li a#logout");
     
            if (checkAuth) {
    document.querySelector('div.users').style.display = 'block';
    } else {
    document.querySelector('div.guests').style.display = 'block';
    }
              },
            error: function (xhr, status, error) {
              console.log("AJAX request error:" + error);
            }
          });
              });
        </script>

    Insert anything you want to show guests on the HTML page into this container

    Code:
    <div class="guests">
    ...
    </div>

    Insert anything you want to show users on the HTML page into this container

    Code:
    <div class="users">
    ...
    </div>



    HTML page accessible only to logged in users Screen51

    TonnyKamper, poesia-verses and Ayushka like this post

    Ayushka
    Ayushka
    New Member


    Posts : 7
    Reputation : 1
    Language : en

    Solved Re: HTML page accessible only to logged in users

    Post by Ayushka June 29th 2023, 4:10 am

    yes! thank you very much! HTML page accessible only to logged in users 1f60d
    skouliki
    skouliki
    Manager
    Manager


    Female Posts : 15311
    Reputation : 1705
    Language : English,Greek
    Location : Greece

    Solved Re: HTML page accessible only to logged in users

    Post by skouliki June 29th 2023, 7:45 am

    Problem solved & topic archived.
    Please read our forum rules: ESF General Rules


      Current date/time is September 23rd 2024, 1:25 am