0

したがって、私のWebサイトにはログインがありますが、ユーザーはすべてのページを表示するためにログインする必要がありますセッションを追加するたびにログインさせたくないので、コードに何を追加する必要があるかログアウトするまでログインする必要はありません。 http://pastebin.com/dbE3mAKV

4

3 に答える 3

1

ログインページ

<?php
session_start(); 

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = new mysqli("localhost", "", "", "");

//if post and encryption
if(isset($_POST['Submit'])){

    $userEmail=strip_tags(trim($_POST['userEmail']));
    $userPassword=SHA1(trim($_POST['userPassword']));

    //Check to see if the user left any space empty! For browsers that do not support the HTML5 'required' atribute.
    if($userEmail==""||$userPassword=="") 
        { 
        $error="Please fill in all of the information"; 
        } else {


    if ($stmt = $mysqli->prepare("SELECT userID FROM users WHERE userEmail = ? and userPassword = ? LIMIT 1")) {
        $stmt->bind_param("ss", $userEmail, $userPassword);
        $stmt->execute();
        $stmt->store_result();
        if($stmt->num_rows > 0) {
            $_SESSION['Email'] = $userEmail;
            $stmt->close();
            //go to next page
            header ("location: nextpage.php");    
        }
        $error="Email and Password do not match, please try again."; 
    }
}}
?>

<!DOCTYPE html>
<head>
</head>

<body>
    <!--Display errors-->
<div class="errorbox">
    <?php if(isset($error)){?><strong class="error"><?php echo $error;?></strong><?php } ?>
</div>

ログイン

                    <form action="#" name="loginform" method="post" >

                    <!--change input type to email if desired but then Spanish accented characters will fail validation -->
                    <label>Email </label>
                    <input type="text" class="styleinput" name="userEmail" maxlength="50" title="Enter Your email" autocomplete="off" placeholder="enter email" required/><br />

                    <label>Password </label>
                    <input type="password" class="styleinput" name="userPassword" maxlength="50" title="Enter Your Password" autocomplete="off" placeholder="enter password" required/>

                    <a href="help.php" class="stylelink"> Forgot your password? </a>
                    <input type="submit" name="Submit" class="stylesubmit" value="Submit">


                    </form>

</body>
</html>

ユーザーがログインする必要がある他のすべてのページ

<?php 
session_start(); 

if(!isset($_SESSION['Email'])){
header("location:home.php");
}
?>

あなたのコード - あなたのサイトに合わせて上記のコードを編集し、登録ページでパスワードを暗号化することを忘れないでください.

于 2013-10-30T03:03:03.257 に答える
1

session_startを使用してセッションを開始できます (機能するには、すべてのページで呼び出す必要があります)。一般的なセッションの詳細については、PHP.netのセッション ページを参照してください。

于 2013-10-25T23:19:10.757 に答える