我有我的 php 设置,因此只有登录用户,查看他们自己的个人资料才能通过我提供的表单共享某些内容。如果您正在查看其他用户的个人资料页面,您不应该看到它,但由于某种原因它仍然显示。我可能做错了什么?
<?php
if (isset($_COOKIE['user_id'])) {
if(isset($_GET['id'])) {
$user_id= $_GET['id'];
}
else {
$user_id= $_COOKIE['user_id'];
}
$dbc= mysqli_connect('localhost', 'root', '', 'beta');
$query= "SELECT * FROM users WHERE user_id= '$user_id'";
$result= mysqli_query($dbc, $query);
$data= mysqli_fetch_array($result);
if (!isset($_GET['user_id']) || ($_GET['user_id'] == $_COOKIE['user_id']))
{
echo "Share Something:";
?>
<form method="post" action="share.php">
<input type="text" name="story"/>
<input type="submit" name="submit" value="share"/>
</form>
<?php
}
echo '<a href="logout.php"> Logout </a></br><hr>';
echo $data['fname'] . " " . $data['lname'] . "</br><hr>";
$query2= "SELECT * FROM posts WHERE user_id= '$user_id'";
$result= mysqli_query($dbc, $query2);
while ($row= mysqli_fetch_array($result)) {
echo $row['story'] . "</br>";
}
}
else {
echo 'please <a href="login.html"> Login </a>!';
}
?>