会话显示当前登录用户

时间:2015-01-11 21:22:39

标签: php session

我的代码有问题。我想创建一个显示当前登录用户的会话谢谢!

$link = mysql_connect($DB_server, $DB_user, $DB_password,$DB_name);
mysql_select_db('linux', $link) or die(mysql_error());

$uid = 0;
if(isset($_GET["id"]))
{
    $uid = $_GET["id"];
}


$profilname = mysql_query("SELECT U_Benutzername ,U_ID FROM u_user WHERE U_ID = '$uid'");
$emailadresse =mysql_query("SELECT U_login ,U_ID FROM u_user WHERE U_ID = '$uid'");
$_SESSION['profilname'] = $profilname;
$_SESSION['email'] =$emailadresse;

echo "Benutzername: $profilname";
echo "<br/>";
echo "Email: $profilname";

2 个答案:

答案 0 :(得分:1)

你有一个错字......

$lid = $_GET["id"];

应该是

$uid = $_GET["id"];

将您的mysql查询更改为:

if($uid!=0) {
    $ref = mysql_query("SELECT * FROM u_user WHERE U_ID = '$uid'");
    $row = mysql_fetch_array($ref);
    $profilname = $row["U_Benutzername"];
    $emailadresse= $row["U_login"];
    $_SESSION['profilname'] = $profilname;
    $_SESSION['email'] =$emailadresse;
}

显示它:

echo $_SESSION['profilname'];

BUT: 你不会对此有所了解,这是mysql_-code并且已弃用。 您 在较新的PHP版本中使用mysqli。 http://php.net/manual/de/book.mysqli.php

答案 1 :(得分:0)

$lid = $_GET["id"];更改为$uid = $_GET["id"];,从$_GET清除数据也是一个好主意,