我正在创建一个社交网络网站,每个用户都有自己的个人资料,但是当我登录时出现问题,个人资料页面没有出现。我使用了 cookie 和会话,我对这个问题做了很多研究,但没有任何成功,所以我认为问题出在 cookie 上。我不知道如何解决它;如果有人可以帮助我,我将不胜感激。
配置文件.php
<?php
ob_start();
require_once('for members/scripts/global.php');
if($logged == 1){
echo("you need to be loged in to view profiles");
exit();
}
if(isset($_GET['id'])){
$id=$_GET['id'];
$id= preg_replace("#[^0-9]#","",$id);
}else{
$id=$_SESSION['id'];
}
//collect member information
$query = mysql_query("SELECT * FROM members WHERE id='$id'LIMIT 1") or die("could not collect user information ");
$count_mem = mysql_num_rows($query);
if($count_mem == 0){
echo("the user does not exit");
exit();
}
while($row = mysql_fetch_array($query)){
$username = $row['username'];
$fname = $row['firstname'];
$lname = $row['lastname'];
$profile_id= $row['id'];
if($session_id == $profile_id){
$owner = true;
}else{
$owner = false;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php print("$fname"); ?> <?php print("$lname"); ?>'s profile</title>
<link href="style/stylesheet.css" type="text/css"/>
</head>
<body>
<div class="container center">
<h1><?php print("$username"); ?></h1>
<?php
if($owner == true ){
header("Location: profile.php");
?>
<!--
<a href="#">edit profile</a><br />
<a href="#">account settings</a><br />
-->
<?php
}else{
header("Location: index.php");
?>
<!--
<a href="#">private message</a><br />
<a href="#">add as friend</a><br />
-->
<?php
}
?>
</div>
</body>
</html>
<?php flush(); ?>
如果您需要其他相关代码,请告诉我。谢谢你。