简体   繁体   中英

login/logout, config, session inactivity codes in php

I have a php file admin_trace.php in which I have integrated everything (config, session inactivity, login/logout, username/password verification and JS codes).

The php file admin_trace.php belongs to the following url http://example.com/admin_trace.php (let us suppose)

In the php file admin_trace.php , I have

a. database configuration code

b. session inactivity code (which forces logout of the page when there is no activity)

c. login/logout code

d. username/password verification code

e. if user is not logged in then it it will display the login page .

// Is user logged in?
<?php
if(!isset($_SESSION['pageadmin'])){ ?>
    <form action="/admin_trace.php" method="post">
        <div style='width:350px;'>
            <fieldset>
                <legend>Login</legend>
                <div>
                    <label for="user_name">User Name</label>
                    <input type="text" name="user_name">
                </div>
                <div>
                    <label for="user_pass">Password</label>
                    <input type="password" name="user_pass">
                </div>
                <div>
                    <button type="submit">Login</button>
                </div>
            </fieldset>
        </div>
    </form>
    <?PHP } else { ?>

f. JS code at the bottom

The issue which I am having right now that all my codes are in one file admin_trace.php which is making things difficult and making some part of the code (like JS) not working

Problem Statement:

I am wondering what would be the best way to architect any login form page that has config code , session inactivity code , login/logout code , username/password verification code and JS code . When I say architect I meant to say the relative locations of the files w.r.t. to admin_trace.php where config code , session inactivity code , login/logout code , username/password code etc will be placed.

PHP has the ability to split code into multiple files. You can bring this code in conditionally with if statements via the include and require statements (and corresponding include_once and require_once .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM