-2

mysql データベースからの非常に基本的な情報を表示するこの php メンバー ページがあります。

私が気づいた問題は、ログアウトしてメンバーページ、つまりhttp://www.mywebsite.co.uk/member.php?id=17にアクセスし、ブラウザーからページを更新すると、ログインすることです。ユーザーアカウント。そして、それがどこで誰であるかは問題ではありません。ID 17またはPAGE Refreshの他のIDで訪問者をそのアカウントにログインさせるだけです!!

これはmember.phpの私のコードです

 <?php 
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php
session_start(); // Must start session first thing
// See if they are a logged in member by checking Session data
$toplinks = "";
if (isset($_SESSION['id'])) {
    // Put stored session variables into local php variable
    $userid = $_SESSION['id'];
    $username = $_SESSION['username'];
    $toplinks = '<a href="member.php?id=' . $userid . '">' . $username . '</a> &bull; 
    <a href="member.php">Account</a> &bull; 
    <a href="logout.php">Log Out</a>';
} else {
    $toplinks = '<a href="join_form.php">Register</a> &bull; <a href="login.php">Login</a>';
}
?>
<?php
// Use the URL 'id' variable to set who we want to query info about
$id = preg_replace("[^0-9]", "", $_GET['id']); // filter everything but numbers for security
if ($id == "") {
    echo "Missing Data to Run";
    exit();
}
//Connect to the database through our include 
include_once "config/connect.php";
// Query member data from the database and ready it for display
$sql = "SELECT * FROM members WHERE id='$id' LIMIT 1";
$query = mysqli_query($db_conx, $sql);
$count = mysqli_num_rows($query);
if ($count > 1) {
    echo "There is no user with that id here.";
    exit(); 
}
while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){
$username = $row["username"];
$_SESSION['username'] = $username;
$userid = $row["id"];
$_SESSION['id'] = $userid;
// Convert the sign up date to be more readable by humans
$signupdate = strftime("%b %d, %Y", strtotime($row['signupdate']));
}
?>

誰でもこれが起こっている理由を見つけることができますか?

ありがとう

4

2 に答える 2

1

明らかにあなたは彼らをログインさせているからです。この行をチェックしてください。

$_SESSION['id'] = $userid;

この行の主な目的は何ですか?

于 2013-03-12T19:18:27.087 に答える
1
// Use the URL 'id' variable to set who we want to query info about
$_SESSION['id'] = $userid;

そこが本題です。アプリケーションを安全にしたい場合は、URL からデータを取り込まないでください。

ユーザー名とパスワードが正しいことを確認したら、ユーザー ID に等しい変数を設定し、その値を使用してログインします。

于 2013-03-12T19:18:46.810 に答える