我是 php 新手,所以我需要以下代码的一些建议:
<?php
// Start the session (pretty important!)
session_start();
// Establish a link to the database
$dbLink = mysql_connect('', '', '');
if (!$dbLink) die('Can\'t establish a connection to the database: ' . mysql_error());
$dbSelected = mysql_select_db('', $dbLink);
if (!$dbSelected) die ('We\'re connected, but can\'t use the table: ' . mysql_error());
$isUserLoggedIn = false;
$query = 'SELECT * FROM users WHERE session_id = "' . session_id() . '" LIMIT 1';
$userResult = mysql_query($query);
if(mysql_num_rows($userResult) == 1) {
$_SESSION['user'] = mysql_fetch_assoc($userResult);
$isUserLoggedIn = true;
} else {
if(basename($_SERVER['PHP_SELF']) != 'conectare.php') {
header('Location: conectare.php');
exit;
}
}
?>
上层代码验证用户是否登录..
我需要创建一个配置文件链接,如下所示:
<强> http://site.com/profile.php?name=NAME-OF-USER
有人可以给我一个想法吗?
我是 php 新手,所以请理解我..
PS:请不要告诉我使用 mysql、pdo 等,我已经知道它们的好处,我只需要我的代码的答案..
谢谢!
最佳答案
你只需要使用 get 变量
创建将像这样被点击的链接
将在主页或任何其他页面上单击的链接
<?php
$username='test';//the variable containing the username
echo'<a href="mysite.com/profile.php?user='.$username.'">
The link redirecting to profile page
</a>';
?>
地址栏将变成这样的内容 www.mysite.com/profile.php?user=test
然后在个人资料页面上
<?php
$username_selector=$_GET['user']//in this case the value got from the link clicked is test
//then just select the necessary data using the variable storing the value got from th link clicked
?>
关于PHP 链接到个人资料页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18579295/