doutu1889 2014-09-15 14:56
浏览 48

模块化登录页面

Currently, we have a page called login.php and whenever we determine that the user may need authorization for something, we include it:

if($userLevelNotHighEnough) {
    require "login.php";
}

This page checks that the user is logged in, but if not, it generates a login page and exits. There are a lot of optional things that the login page does (like printing certain messages, allowing certain special logins, etc.) which are messy business logic things. These options are currently handled by setting variables in the calling script, which are accessed by login.php, i.e.:

// in calling script
if($userLevelNotHighEnough) {
    $someOptionalParameter = "my value";
    require "login.php";
}

/** ============================ **/

// in login.php
if(!empty($someOptionalParameter)) {
    // do something
}

As you might imagine, this sort of code is prevalent throughout the codebase, and it makes adding to the codebase very difficult, especially for those who are relatively new to the code.

What alternatives are there to this sort of structure?

My initial idea was that we could make a function called checkLogin instead and pass it an associative array of optional parameters, but this doesn't seem that much better than the current system.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥65 永磁型步进电机PID算法
    • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
    • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
    • ¥15 如何处理复杂数据表格的除法运算
    • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
    • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
    • ¥200 uniapp长期运行卡死问题解决
    • ¥15 latex怎么处理论文引理引用参考文献
    • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
    • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?