doujizhong8352 2013-12-12 22:04
浏览 8
已采纳

仅会员页面[关闭]

I need help trying to make a member only page...so you can only get on it if you are logged in at login.php

This is the "login.php" page

<?php
require_once("db.php");


if(isset($_POST['submit'])) {
    global $connection; 

    $username = $_POST['username'];
    $safe_username = mysqli_real_escape_string($connection, $username);

    $password = $_POST['password'];

    $query = "SELECT * FROM members WHERE username = '{$safe_username}'";
    $result = mysqli_query($connection, $query);
    if($row = mysqli_fetch_assoc ($result)) {
        $set_password = $row['password'];
        $input_password = $password;

        if($input_password == $set_password) {
            header("Location: home.php");

    die();
        } else {
            header("Location: logfailed.html");
            die();
        }
    } else {
            header("Location: logfailed.html");
            die();
    }
}
?>

This is the page I want to make member only "home.php":

<!doctype html>
<html>
<head>
    <title>
        Congregate | Where Family Meets
    </title>
    <link rel="stylesheet" href="style.css"/>
</head>

<body bgcolor="grey">
    <center>
    <h1>Time Till This Website Goes Live:</h1>
    <span id="countdown"></span>
    <script>
        // set the date we're counting down to
var target_date = new Date("Mar 26, 2014").getTime();

// variables for time units
var days, hours, minutes, seconds;

// get tag element
var countdown = document.getElementById("countdown");

// update the tag with id "countdown" every 1 second
setInterval(function () {

// find the amount of "seconds" between now and target
var current_date = new Date().getTime();
var seconds_left = (target_date - current_date) / 1000;

// do some time calculations
days = parseInt(seconds_left / 86400);
seconds_left = seconds_left % 86400;

hours = parseInt(seconds_left / 3600);
seconds_left = seconds_left % 3600;

minutes = parseInt(seconds_left / 60);
seconds = parseInt(seconds_left % 60);

// format countdown string + set tag value
countdown.innerHTML = days + "d, " + hours + "h, "
+ minutes + "m, " + seconds + "s";  

}, 1000);
    </script>
    </center>
</body>
</html>
  • 写回答

2条回答 默认 最新

  • doutan3040 2013-12-12 22:11
    关注

    You must store the information that user is logged into the session :

    if($input_password == $set_password) {
        $_SESSION['logged_in'] = true;
        header("Location: home.php");
        die();
    }
    

    Then, in any page that requires users to be logged in (home.php), you check $_SESSION['logged_in']:

    if(!isset($_SESSION['logged_in']) || $_SESSION['logged_in'] !== true)
        header("Location: index.php");
    

    Also do not forget to add session_start(); in your login.php and home.php pages (and any other pages that requires authentication)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?