duanhan3067 2015-02-01 06:52
浏览 15

将数据保存到服务器后如何登录?

I'm learning php and mysql and i'm making fake login site. -for learning purpose-

    <?php
$id = $_POST[mb_id];
$password = $_POST[mb_password];
// Create connection
 $conn = mysqli_connect(localhost, u982680175_root, temp, u982680175_test);
 // Check connection
 if (!$conn) {
     die("Connection failed: " . mysqli_connect_error());
}

$sql = "INSERT INTO student (id, password)
 values ('$id', '$password')";

if (mysqli_query($conn, $sql)) {
    header("Location: http://www.dtg.hs.kr/");
exit();

} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

mysqli_close($conn);
?> 

i sucess saving data in to my server and redirected to realhomepage. but i want to redirect to logined real site after saving database. how can i call real php and give data? this is the real login page: http://www.dtg.hs.kr/sys/bbs/login.php

  • 写回答

1条回答 默认 最新

  • douyi1779 2015-02-01 07:10
    关注

    Short answer...

    After the data from the user being created is inserted into the database you will need to have the script create some sort of $_SESSION[] variable that uniquely identifies the user.

    Here is the PHP documentation related to SESSIONs http://php.net/manual/en/book.session.php

    When the redirect occurs there will be a check to see if the $_SESSION variable is set or not. If the $_SESSION variable is set, then do a check to see if the $_SESSION variable is valid.

    In then you will be able to show different data based on the validated $_SESSION or if no $_SESSION is set.

    Hope this helps!

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起