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

标签 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(); ?>! Willkommen züruck UserEmail(); ?>!

最佳答案

瑞克, 我会写在这里,以便您更好地理解。为了调试目的,请执行以下操作:

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

  2. 而不是:

<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'";

关于php - 使用单独的链接 php 文件获取当前 session 信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30939214/

相关文章:

php - 使用 View 或不使用 View

php - 为什么 DateTime::diff 在这些日期之间返回 0 天?

php项目在windows上工作但在linux上不工作

javascript - react : how to force state changes to take place after setState

javascript - Webkit 浏览器 <535 (Android native/ios5 safari) HTML5 Canvas 点击错误

php - $row 在哪里定义的?

PHP Web 套接字 - 无法绑定(bind)到主机

javascript - Angular 2 组件可以与 index.html 上的元素交互吗?

mysql - 两个表的 SQL 对最新更新

php - 不使用Ajax从MySQL表中获取DROPDOWN中的值