[英]Get logged in user information from sql with php
I read many topics about this problem but i cant find the answer 我读了许多有关此问题的主题,但找不到答案
I want create a page for each user who he can see their info in that page. 我想为每个可以在该页面中看到其信息的用户创建一个页面。 Like profile page.
喜欢个人资料页面。
This is my table: 这是我的桌子:
My session file (db.php): 我的会话文件(db.php):
<?php
session_start();
header('Content-Type: text/html; charset=UTF-8');
require ("../functions.php");
mysql_connect($dbHOST, $dbUSER, $dbPASS);
mysql_select_db($dbNAME);
function user_login ($username, $password) {
$username = mysql_real_escape_string($username);
$password = md5($password);
$result = mysql_query("SELECT * FROM users WHERE username = '".$username."' AND password = '".$password."' AND usergroup = '1'");
$exists = (mysql_num_rows($result))?TRUE:FALSE;
if (!$exists){
echo "نام کاربری/رمز عبور اشتباه است و یا شما مجوز دسترسی به این بخش را ندارید!";
}
else {
$_SESSION['username'] = true;
echo "<script language=\"Javascript\">document.location.href='index.php' ;</script>";
}
}
?>
Login page (login.php): 登录页面(login.php):
<?php
header('Content-Type: text/html; charset=UTF-8');
require ("../functions.php");
include("db.php");
if(isset($_POST['username']) && isset($_POST['password'])){
user_login($_POST['username'], $_POST['password']);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" content="Alireza Behnamnik | T!G3R" />
<title> پنل مدیریت </title>
<link rel="stylesheet" type="text/css" href="../css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="../css/font-awesome.css">
<link rel="stylesheet" type="text/css" href="../css/style.css">
<script type="text/javascript" src="../js/jquery-3.1.1.js"></script>
<script type="text/javascript" src="../js/bootstrap.min.js"></script>
<!-- Other -->
<link rel="icon" href="<?php echo $favicon ?>" />
</head>
<body>
<style>
body {background:#e9e9e9;}
</style>
<div class="container-fluid">
<div class="row">
<div class="tnbar">
<a href="../index.html" target="_blank"><button class="btn pannel btn-default navbar-btn pull-left">صفحه اصلی</button></a>
<span class="pull-right"> پنل مدیریت وبسایت <?php echo $sitetitle ?> </span>
</div>
</div>
</div>
<div class="col-md-4 forms">
<p class="adtitle"> ورود به حساب مدیریت</p>
<form action="login.php" method="post">
<div class="col-md-12"><input class="form-control" name="username" type="text" placeholder="نام کاربری" required/></div></br></br>
<div class="col-md-12"><input class="form-control" name="password" type="password" placeholder="رمز عبور" required/></div></br></br>
<button style="color:#000;">ورود به حساب</button>
</form>
</div>
</body>
</html>
functions.php is used for database information. functions.php用于数据库信息。
Now for example i want to show the user information in user.php page 现在,例如,我想在user.php页面中显示用户信息
Put something like that at the end of your function (before the two }
at the end of the code) 在函数末尾放置类似的代码(在代码末尾的两个
}
之前)
$lId=mysql_result($result, 0, "id" );
$lusername=mysql_result($result, 0, "username" );
echo "User $li is $lusername";
but you are using deprecated mysql_*
functions and your mysql query can be attacked by sql injection threats. 但是您正在使用不
mysql_*
使用的mysql_*
函数,并且您的mysql查询可能会受到sql注入威胁的攻击。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.