我正在创建一个朋友系统,但它有一个名为profile.php的页面。此页面用于系统的每个成员。它看起来像
<!DOCTYPE html>
<html>
<head>
<title>Profile</title>
<link rel='stylesheet' href='style.css' />
</head>
<body>
<?php include 'connect.php'; ?>
<?php include 'functions.php'; ?>
<?php include 'header.php'; ?>
<center><div class = 'user'>
<?php
if(isset($_GET['user']) && !empty($_GET['user'])) {
$user = $_GET['user'];
} else {
$user = $_SESSION['user_id'];
}
$my_id = $_SESSION['user_id'];
$username = getuser($user, 'username');
?>
<h3><?php echo $username; ?></h3>
<?php
if($user != $my_id) {
$check_frnd_query = mysql_query("SELECT id FROM frnds WHERE (user_one='$my_id' AND user_two='$user') OR (user_one = '$user' AND user_two='$my_id')");
if(mysql_num_rows($check_frnd_query) == 1) {
echo "<a href = '#' class = 'box'>Already Friends</a> | <a href = 'actions.php?action=unfrnd&user=$user' class = 'box'>Unfriend $username</a>"; //This is where the profile page design will go.
} else {
$from_query = mysql_query("SELECT `id` FROM `frnd_req` WHERE `from`='$user' AND `to` = '$my_id'");
$to_query = mysql_query("SELECT `id` FROM `frnd_req` WHERE `from`='$my_id' AND `to`='$user'");
if(mysql_num_rows($from_query) == 1){
echo "<a href = '#' class = 'box'>Ignore</a> | <a href = 'actions.php?action=accept&user=$user' class = 'box'>Accept</a>";
} else if (mysql_num_rows($to_query) == 1) {
echo "<a href = 'actions.php?action=cancel&user=$user' class = 'box'>Cancel Request</a>";
} else {
echo "<a href = 'actions.php?action=send&user=$user' class = 'box'>Send Friend Request</a>";
}
}
?>
</div></center>
<div id = 'sidebar'>
<ul>
<?php
$my_id = $_SESSION['user_id'];
$frnd_query = mysql_query("SELECT user_one, user_two FROM frnds WHERE user_one = '$my_id' OR user_two = '$my_id'");
while($run_frnd = mysql_fetch_array($frnd_query)) {
$user_one = $run_frnd['user_one'];
$user_two = $run_frnd['user_two'];
if($user_one == $my_id) {
$user = $user_two;
} else {
$user = $user_one;
}
$username = getuser($user, 'username');
echo "<li><a href = 'my_ideas.php?user=$user' style=display:block;>Ideas</a> </li>";
?>
<li><a href = '#my_links'>Linked Ideas</a></li>
<li><a href = 'settings.php'>Profile Settings</a></li>
</ul>
</div>
<?php
}
} else {
?>
<div id = 'sidebar'>
<ul>
<li><a href = 'my_ideas.php'>My Ideas</a></li>
<li><a href = '#my_links'>Linked Ideas</a></li>
<li><a href = 'settings.php'>Profile Settings</a></li>
</ul>
</div>
<?php } ?>
<div id = 'user_content'>
<p>This is where the user_content should go.</p>
</div>
</body>
</html>
// That is where it ends the site formatted it weird. Also, the function get user is
function getuser($id, $field) {
$query = mysql_query("SELECT $field FROM users WHERE id='$id'");
$run = mysql_fetch_array($query);
return $run[$field];
}
这个问题是,每次我访问不是我登录用户的用户页面时,网站会将我退出并以另一个用户身份重新登录。我能做些什么来解决这个问题吗?
答案 0 :(得分:1)
你需要session_start();.开始会议。