使用单独的链接php文件获取当前会话信息

时间:2015-06-19 13:19:01

标签: php html mysql session echo

这是Select在文件中显示的唯一时间。 。 。 。

function GetUserFromEmail($email,&$user_rec)
{
    if(!$this->DBLogin())
    {
        $this->HandleError("Database login failed!");
        return false;
    }   
    $email = $this->SanitizeForSQL($email);

    $result = mysql_query("Select * from $this->tablename where email='$email'",$this->connection);  

    if(!$result || mysql_num_rows($result) <= 0)
    {
        $this->HandleError("There is no user with email: $email");
        return false;
    }
    $user_rec = mysql_fetch_assoc($result);


    return true;
}

和。 。

function CheckLoginInDB($username,$password)
{
    if(!$this->DBLogin())
    {
        $this->HandleError("Database login failed!");
        return false;
    }          
    $username = $this->SanitizeForSQL($username);

$nresult = mysql_query("SELECT * FROM $this->tablename WHERE username = '$username'", $this->connection) or die(mysql_error());
    // check for result 
    $no_of_rows = mysql_num_rows($nresult);
    if ($no_of_rows > 0) {
        $nresult = mysql_fetch_array($nresult);
        $salt = $nresult['salt'];
        $encrypted_password = $nresult['password'];
        $hash = $this->checkhashSSHA($salt, $password);


    }


    $qry = "Select name, email from $this->tablename where username='$username' and password='$hash' and confirmcode='y'";

    $result = mysql_query($qry,$this->connection);

    if(!$result || mysql_num_rows($result) <= 0)
    {
        $this->HandleError("Error logging in. The username or password does not match");
        return false;
    }

    $row = mysql_fetch_assoc($result);


    $_SESSION['name_of_user']  = $row['name'];
    $_SESSION['email_of_user'] = $row['email'];
    $_SESSION['phone_of_user'] = isset($row['phone'])?$row['phone']:'phone not set';


    return true;
}

此外,这是$ row唯一出现的时间。从其他php文件调用的函数如下。 。 。

<p id="mobilecheck" align="center"> Willkommen z&uuml;ruck <? echo $fgmembersite->UserFullName(); ?>! </br>

Willkommen UserPhone(); ?&GT;!  WillkommenzüruckUserEmail(); ?&GT;!

1 个答案:

答案 0 :(得分:0)

瑞克, 我会在这里试试,这样你就能更好地理解。出于调试目的,接下来要做的事情:

  1. 而不是$_SESSION['phone_of_user'] = $row['phone'];这个:$_SESSION['phone_of_user'] = $row; //This will put an entire array in your variable

  2. 代替:

  3. <p id="mobilechiiieckby" align="center"> Willkommen <? echo $fgmembersite->UserPhone(); ?>! </br>

    写下这个:

    <p id="mobilechiiieckby" align="center"><pre><?php print_r($_SESSION['phone_of_user']); ?>!</pre></p>
    

    这两个简单的修改将帮助您查看$ row变量中的内容。看到它的内容后,你可以玩它。让我们继续讨论,我将用新信息更新这个答案。

    稍后编辑: 更新此行:

    $qry = "Select name, email from $this->tablename where username='$username' and password='$hash' and confirmcode='y'";
    

    这一个:

    $qry = "Select name, email, phone from $this->tablename where username='$username' and password='$hash' and confirmcode='y'";