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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵