php - 从登录 session 中获取 ID 并填充到主页 : php and mysql

标签 php mysql authentication session-variables

我有一个“用户”表,其中包含用户名和密码详细信息以及作为主键的 user_id。

user( user_id(pk) , username , password , address, email)

当我登录网站时,我需要根据用户名的 user_id 从“user”表中获取地址和电子邮件 ID,并将其填充到主页上。

请有人帮助我如何做到这一点?

谢谢。

最佳答案

当您使用您的user_id密码验证数据库时,然后设置:

##index.php
$username=$_Post['valuefromform'];
$password=$_Post['valuefromform'];
$result_set="SELECT * FROM user";
$num_rows=mysql_num_rows($result_set);
if($num_rows!=0)
{
   $result=mysql_fetch_array($result_set);
   if($username==$result['username'] && $password=$result['password'])
   {
       $id=$result['user_id'];
       $_SESSION['id']=$id;
       header("location:index.php?uid=$id");
    }
}

您可以使用get方法获取userid的值。

##home.php

$getid=$_GET['uid'];
echo $getid;

关于php - 从登录 session 中获取 ID 并填充到主页 : php and mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31358922/

相关文章:

php比较数组键,而不是值

authentication - 适用于 Web 应用程序和移动应用程序的 REST API 身份验证

node.js - Mongodb 已更新,但呈现旧信息

php - MySQL 是否在我的查询中转换 UTF-8 字符(而不是结果),并去除重音符号?

javascript - 使用 php 后端和 redux 在 React js 中实现动态元标记

php - Laravel 查询和过滤

mysql 向不工作的用户授予 sql 脚本

php session 和 while 循环 : undefined index

php - 不要重复字符串多次

authentication - 我可以在 ASP.NET Core 3 中组合来自两种身份验证方案的身份吗?