dongmo6937 2019-08-03 04:21
浏览 98

客户端授权

I'm wanting to move away from *.php extensions for my markup pages to essentially break my code down to having the front-end handle just the markup and some javascript stuff and having the back-end handle just my database transactions.

Traditionally all of my markup pages would have a *.php extension and then the authorization would occur at the top of the file in a php tag.

Because I am fine with requiring the user have Javascript enabled, the idea that I had was to create an HTML page that has a noscript that redirects to a "the website requires Javascript" page and alternatively a script that submits an AJAX request for authentication and redirects if there is valid authentication. Demonstrated with the following markup:

<html lang="en">
<head>
    <title>Authentication Demo</title>
</head>

<body>
    <noscript>
        <meta http-equiv="refresh" content="0;url=noscript.html">
        <p>Javascript is required for Authentication. If you are not automatically redirect, please go to this page: <a href="noscript.html">noscript.html</a></p>
    </noscript>
    <script>
        function getParameterByName(name, url) {
            if (!url) url = window.location.href;
            name = name.replace(/[\[\]]/g, '\\$&');
            var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
                results = regex.exec(url);
            if (!results) return null;
            if (!results[2]) return '';
            return decodeURIComponent(results[2].replace(/\+/g, ' '));
        }

        function authenticateUser() {
            var xmlhttp = new XMLHttpRequest();

            xmlhttp.onreadystatechange = function() {
                if (xmlhttp.readyState == XMLHttpRequest.DONE) {
                    if (xmlhttp.status == 200) {
                        return xmlhttp.responseText;
                    }
                    else {
                        return null;
                    }
                }
            };

            xmlhttp.open("POST", "authenticate.php", true);
            xmlhttp.send();
        }

        var redirect = getParameterByName('redirect');

        if (this.authenticateUser === true) {
            window.location = redirect;
        }
    </script>
</body>
</html>

This would require that I setup my navigation anchors to be formatted as such authenticate.html?redirect=going-to-webpage.html

My question is two-fold:

  1. What are the security implications of this?
  2. Aside from requiring Javascript (as mentioned I'm cool with this) what are some other downsides associated with this approach?
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 镍氢电池充电器设计实物使用原理
    • ¥15 逻辑谓词和消解原理的运用
    • ¥15 三菱伺服电机按启动按钮有使能但不动作
    • ¥15 js,页面2返回页面1时定位进入的设备
    • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?