Redirect after PHP Login

后端 未结 3 1427
我在风中等你
我在风中等你 2020-12-21 16:13

I have a subdomain

accounts.mysite.com

What i want is one login panel for that subdomain, then after a user logs in it directs them to their own page (and

相关标签:
3条回答
  • 2020-12-21 16:46

    Include a file at the top of every file that should be blocked that contains something like:

    <?php
    if (isset($_SESSION['user_id']) && $_SESSION['user_id']) {
        header('Location: user.php?id=' . $_SESSION['user_id']); 
        exit;
    }
    

    This will redirect the user to user.php everytime they try to visit another file.

    Edit: And don't forget to use session_start() at the beginning of every request.

    0 讨论(0)
  • 2020-12-21 17:00

    Your code looks bad.
    session_register("myusername"); - This function has been DEPRECATED as of PHP 5.3.0. Move your database config to another file.

    $host="localhost"; // Host name
    $username="******"; // Mysql username
    $password="*******"; // Mysql password
    $db_name="medpro_test"; // Database name
    $tbl_name="members"; // Table name
    

    Use header location http://php.net/manual/en/function.header.php to move user to the link.

    0 讨论(0)
  • 2020-12-21 17:07
    1. you need to get rid of your current PHP book and find yourself a modern one, at least published in the current century.
    2. Then rewrite your session code according to manual
    3. then use session_set_cookie_params() to set up a session domain.
    0 讨论(0)
提交回复
热议问题