doumu6941 2017-03-03 20:41
浏览 256

如何在php中显示用户信息?

I am trying to figure out how to display user information after they've logged in. I am not sure whether I should create a single php file which would display user information depending on the session or should I create different files for different users. I am also having trouble grabbing the header.

here's my code for login.php

<?php
session_start();

require 'dbh.php';


$username = $_POST['uname'];

$password = $_POST['pwd'];


$sql = "SELECT * FROM  registeredusers WHERE UserName = '$username'";

$result = mysqli_query($connection,$sql);

$row = mysqli_fetch_assoc($result);


$hashed_Password = $row['Password'];

$Dehash = password_verify($password,$hashed_Password);



if($Dehash == 0){

echo "username or password is incorrect";

exit();


} else{




$sql = "SELECT * FROM  registeredusers WHERE  UserName='$username' AND Password='$hashed_Password'";

$result = mysqli_query($connection,$sql);



if (!$row=mysqli_fetch_assoc($result)){


echo "Your User Name or Password is incorrect";

}

else {

$userid = $row['id'];

$_SESSION['UserName'] = $row['UserName'];


header("Location: userhomepage.php?user_id=".$userid);

}


}

?>

The following code redirects to userhomepage.php and the user ID is in the url can someone also tell me how do I grab the user ID from the url? I only started coding in PHP a week ago I am fairly new so if guys have any pointers for me that would be great.

  • 写回答

1条回答 默认 最新

  • dongxi8297 2017-03-03 20:53
    关注

    I am not sure whether I should create a single php file which would display user information depending on the session or should I create different files for different users.

    You should create a single page that displays user information based on session... you don't want to have to hand-make a new page every time a user signs up!

    how do I grab the user ID from the url

    echo $_GET["user_id"];

    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能