Close access to the site

    From time to time in our studio there are situations when, for one reason or another, you need to close access to a working site. For example, a new site that is only being configured on the server, or on a working project, functionality is being updated.

    Naturally, the question is to close access for ordinary visitors, and for trusted people the site should function.

    To be honest, I don’t remember how we did it before :), but now we are solving this issue by the next implementation in the index file, which all requests go to moderate. You can also embed a library in the file, which is called from all the scripts in the project.

    $ SecretKey = 'i-want-to-see-this-site';
    $ AdminCookie = 'HOHOHO! I am super hacker! ';
    if ($ _COOKIE ['AdminCookie']! = $ AdminCookie && $ _SERVER ['QUERY_STRING']! = $ SecretKey) {
        require_once 'page_park.html';
    } else {
        setcookie ('AdminCookie', $ AdminCookie, time () + 3600 * 24 * 365, '/');
        if ($ _SERVER ['QUERY_STRING'] == $ SecretKey) {
            header ('Location: /');

    Thanks to this small code, all people will get to page_park.html, and it’s enough for the chosen ones to follow the link http: // our_site/?i-want-to-see-this-site to get full access to the site. And most importantly, during subsequent visits, the chosen ones will immediately get to a working site without any problems, which is very useful if the site is configured and launched within a few days.

    UPD This is a temporary “blind”, and the key and value of cookies are specially made into variables so that they can be changed from update to update and from project to project.

    PS Just this morning we were setting up a new site on the server, so I decided to share such a simple chip with the public.

    Also popular now: