我要求的是用户如何访问其他用户个人资料。
过去一周,我一直在编写一个我正在编写的社交网络脚本,现在我有点卡住了。
我不知道从哪里开始阅读或其他什么。
所以我要求你们帮助我=)
我想到的网址就像user.php?id=123
一样,让你正在访问的用户出现而不是“你”在user.php
!
现场演示:http://social.swipper.org
编辑#2:
这是我在user.php中的当前代码:
<?php
session_start();
if($_SESSION['username']) {
include "config.php";
$username = $_SESSION['username'];
$fetcher = mysql_query("SELECT * FROM userinfo WHERE username='$username'");
while ($data = mysql_fetch_assoc($fetcher)){
$firstname = $data['firstname'];
$lastname = $data['lastname'];
$gender = $data['gender'];
}
// get user's profile image
if (file_exists("users/$username/profile.jpg")) {
$userPhoto = "<img class='pic' src='users/$username/profile.jpg' width='90%' height='30%' />";
}
elseif (!file_exists("users/$username/profile.jpg")) {
$userPhoto = "<img class='pic' src='http://www.uavmedia.com/portal/images/no-user.jpg' width='90%' height='30%' />";
}
// the user's profile image is fetched
// henter profil text
$file = "users/$username/bio.txt";
$contents = file($file);
$profile_text = implode($contents);
// ferdig å hente profil text, vil nå echo ut profil siden.
// henter profil stilsett
$file2 = "users/$username/style.css";
$contents2 = file($file2);
$profile_style = implode($contents2);
// ferdig å hente profil stilsett.
echo
"
<!doctype html>
<html lang='en'>
<head>
<title>Social FW</title>
<meta name='Description' content='A Social network for everyone. Come join us!' />
<meta name='Keywords' content='Social, Network, Framewerk, Framework, FW, Open-Source, Free' />
<link rel='stylesheet' type='text/css' href='user_files/style.css' media='screen' />
<link rel='stylesheet' type='text/css' href='SFW_files/style2.css' media='screen' />
<style type='text/css'>
$profile_style
</style>
<link rel='icon' href='SFW_files/favicon.ico' media='screen' />
<script type='text/javascript' src='http://code.jquery.com/jquery-latest.js'></script>
<script type='text/javascript' src='SFW_files/scripts/login.js'></script>
</head>
<body>
<div id='top'>
<h1>Swipper.org</h1>
</div>
<div id='side-menu'>
<ul>
<li><a href='user.php'><b>".$username."</b></a></li><br/>
<li><a href=''>Inbox</a></li>
<li><a href=''>Guestbook</a></li>
<li><a href=''>Friends</a></li>
<li><a href=''>Pictures</a></li><br />
<div id='showOptions'><li><a href='#'>Edit Profile</a></li></div>
<div id='editOptions' style='display:none;'>
<pre class='user_info'><b>></b><a href='changeText.php'>Edit Profile Text</a>
<b>></b><a href='changeCss.php'>Edit Stylesheet(CSS)</a>
<b>></b><a href='changeProfilePic.php'>Change Profile Image</a></pre>
</div><br />
<a href='logout.php'><b>Logout</b></a>
</ul>
</div>
<div id='side-left'>
<!-- START USER PIC --!>
<center>
$userPhoto<br />
</center>
<!-- END USER PIC --!>
<!-- START USER INFO --!>
<br />
<h3><pre class='user_info'>User Info</pre></h3>
<pre class='user_info'>Name: ".$firstname." ".$lastname."<br />Sex : $gender</pre>
<!-- END USER INFO --!>
</div>
<div id='box_center'>
<h2 style='font-size:30px;' align='center'>$username</h2>
<hr />
<br />
$profile_text
</div>
<div id='footer'>
<p align='center'>Swipper.org © All rights reserved. 2010-2012</p>
</div>
</body>
</html>
";
}
else {
die("You need to login first or register. You can register/login <a href='index.php'>here</a>!");
}
?>
当网址如下:user.php?id = 3我想让用户显示用户ID 3,并获取用户#3的信息,而不是想要访问其他人的“用户”。< / p>
答案 0 :(得分:1)
您是否列出了所有用户的位置?如果你是href需要像
那样<?php
$sql = mysql_query("SLECET * FROM userinfo");
while ($row = mysql_fetch_assoc($sql)){
echo "<a href='users.php?id=" . $row['id'] . "'>"
}
然后在users.php
<?php
if(isset($_REQUEST['id'])) {
if(is_numeric($_REQUEST['id'])){
$uid = $_REQUEST['id'];
$sql = mysql_query("SELECT * FROM userinfo WHERE id='" . $uid . "' LIMIT 1");
}
} else {
$sql = mysql_query("SELECT * FROM userinfo WHERE username='" . $_SESSION['username'] . "' LIMIT 1");
}
然后你的html可以使用fetch_assoc($ sql)
<table>
<tr>
<td><?php echo $row['username'] ?>'s Profile</td>
</tr>
</table>
简单的例子。但是我觉得你得到了这张照片,在FB上给我留言了解更多关于这个Stian的信息
答案 1 :(得分:0)
像
一样进行查询$userID = $_GET['id'];
$fetcher = mysql_query("SELECT * FROM userinfo WHERE userID='$userID'");
并且您可以相应地显示具有url中给出的有效用户ID的任何用户的数据。
如果可以在没有登录的情况下查看个人资料,那么就不需要会话,如果强制只检查是否存在。如果您在URL中传递用户名
user.php?user=test1
然后你的查询就像
$username = $_GET['user'];
$fetcher = mysql_query("SELECT * FROM userinfo WHERE username='$username'");
希望现在对你更清楚了。
答案 2 :(得分:0)
这应该是你的答案:
if (isset($_GET['username']){
$username = mysql_escape_string($_GET['username']);
}else{
$username = $_SESSION['username'];
}
$fetcher = mysql_query("SELECT * FROM userinfo WHERE username='$username'");
if (mysql_num_rows() == 0){
$username = '';
echo 'Username not found'; die();
}