dongwen6743 2015-01-16 00:24
浏览 26
已采纳

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

How to post values to loginchk_coustomer.php given in below code, not through Url by any other way. Is there any other way to post these value to loginchk_coustomer.php becoz it is not secure.

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

?>

  • 写回答

1条回答 默认 最新

  • dongshanxiao7328 2015-01-16 01:00
    关注

    You need to create a session to store all that information.

    Here's what they are - from http://php.net/manual/en/features.sessions.php:

    Session support in PHP consists of a way to preserve certain data across subsequent accesses.

    To start a session write at the beginning of your code:

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

    and then after your assign the information this way:

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

    All the information will persist on those variables along the site until you do:

    session_destroy();
    

    I also recommend you not to redirect with javascript, but this way in PHP:

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

    Possibly after checking this answer you will think about to change the way you check the login information. But that's okay. It's the way of learning.

    More information about sessions: http://php.net/manual/en/book.session.php

    I hope this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题