如何在 PHP 中将值从一个页面传递到另一个页面,而不是通过传递 URL


how to pass values from one page to another in php, not by passing through URL?

如何将值发布到下面的代码中给出的loginchk_coustomer.php,而不是通过任何其他方式通过 Url。有没有其他方法可以将这些值发布到loginchk_coustomer.php因为它不安全。

 <?php
include "include/connect.php";
$user_name       = $_REQUEST['user_name'];
$password        = $_REQUEST['password'];
//echo "select * from school_info where school_id='$user_name' and school_password='$password'";
$sql_query       = mysql_fetch_assoc(mysql_query("select * from school_info where school_id='$user_name' and school_password='$password'"));
$db_username     = $sql_query['db_username'];
$db_password     = $sql_query['db_password'];
$db_databasename = $sql_query['db_databasename'];
echo "<script>";
echo "self.location='member/loginchk_customer.php?db_username=$db_username&db_password=$db_password&db_databasename=$db_databasename&user_name=$user_name&password=$password'"; // Comment this line if you don't want to redirect
echo "</script>";

?>

您需要创建一个会话来存储所有这些信息。

以下是它们的内容 - 来自 http://php.net/manual/en/features.sessions.php:

PHP 中的会话支持包括一种在后续访问中保留某些数据的方法。

要启动会话,请在代码开头写入:

session_start(); // needed in all pages that will use the variables below

然后在您以这种方式分配信息后:

$_SESSION['username'] = $sql_query['db_username'];
$_SESSION['password'] = $sql_query['db_password'];
$_SESSION['databasename'] = $sql_query['db_databasename'];

所有信息将保留在站点上的这些变量上,直到您这样做:

session_destroy();

我还建议你不要使用 javascript 重定向,但在 PHP 中是这样:

header('Location: member/loginchk_customer.php');

可能在检查此答案后,您会考虑更改检查登录信息的方式。不过没关系。这是学习的方式。

有关会话的更多信息:http://php.net/manual/en/book.session.php

我希望这有所帮助。