PHP使用会话在项目文件中保存两个变量


PHP Using sessions to save two variables across project files

我对PHP有点生疏了。我想做的是保存2个变量在我的项目中使用。我想保存我的登录页面的电子邮件和密码,以便以后在Parse.com上分析我的数据库。

使用参考链接:[http://php.net/manual/en/book.session.php]


解决了,谢谢你@Fred -ii-的帮助和解释!

登录文件:

try{
$query = new ParseQuery("Clients");
$query->equalTo("email", "$email");
$query->equalTo("password","$password");
$results = $query->find();
} catch(Exception $e){
echo $e->getMessage();
}
if(count($results)==1){
session_start();
$_SESSION['email'] = $email;
$_SESSION['password'] = $password;
 header("Location: http://localhost/ClientPortal/mainMenu.php");
}

mainMenu文件:

   session_start();
   $email = $_SESSION['email'];
   $password = $_SESSION['password']; //* fixed spelling error (used to be 'passowrd')
   session_commit();
try{
   $query = new ParseQuery("Clients");
   $query->equalTo("email", "$email");
   $query->equalTo("password","$password");
   $results = $query->find();
   } catch(Exception $e){
  echo $e->getMessage();
   }
if(count($results)==1){
echo "<p align=center>1 correct row</p>";
}
else{
 echo "<p align=center>NO correct rows</p>";
}

谢谢你@Fred -ii-帮我解决这个问题!!

登录文件:

try{
$query = new ParseQuery("Clients");
$query->equalTo("email", "$email");
$query->equalTo("password","$password");
$results = $query->find();
} catch(Exception $e){
echo $e->getMessage();
}
if(count($results)==1){
session_start();
$_SESSION['email'] = $email;
$_SESSION['password'] = $password;
 header("Location: http://localhost/ClientPortal/mainMenu.php");
}

mainMenu文件:

session_start();
$email = $_SESSION['email'];
$password = $_SESSION['password']; //* fixed spelling error (used to be 'passowrd')
session_commit();
try{
  $query = new ParseQuery("Clients");
  $query->equalTo("email", "$email");
 $query->equalTo("password","$password");
 $results = $query->find();
 } catch(Exception $e){
 echo $e->getMessage();
 }
if(count($results)==1){
echo "<p align=center>1 correct row</p>";
 }
 else{
 echo "<p align=center>NO correct rows</p>";
}