使用单独的链接 php 文件获取当前会话信息
Get current session info using separate linked php file
这是文件中唯一出现的 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üruck <? echo $fgmembersite->UserFullName(); ?>! </br>
Willkommen UserPhone(); ?>!
Willkommen züruck UserEmail(); ?>!
里克,
我会在这里写,这样你会更好地理解。出于调试目的,请执行以下操作:
而不是 $_SESSION['phone_of_user'] = $row['phone'];
把这个:$_SESSION['phone_of_user'] = $row; //This will put an entire array in your variable
而不是:
<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'";
这是文件中唯一出现的 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üruck <? echo $fgmembersite->UserFullName(); ?>! </br>
Willkommen UserPhone(); ?>! Willkommen züruck UserEmail(); ?>!
里克, 我会在这里写,这样你会更好地理解。出于调试目的,请执行以下操作:
而不是
$_SESSION['phone_of_user'] = $row['phone'];
把这个:$_SESSION['phone_of_user'] = $row; //This will put an entire array in your variable
而不是:
<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'";