将MySQL表中的json日期格式加载到PHP中

时间:2018-02-12 21:40:36

标签: php mysql json datetime

在University,我们有一些mysql表结构,由前一个编码器/人创建。结构本身干净而完美。我们使用MySQL的数据登录系统。 PHP中的登录系统可以正常使用$ username和$ password进行会话。

问题:

我们每个人(用户)都有一个过期日期表。每次我们需要的日期交换我们的安全卡。但是,我想获取/回显此过期日期表,并在登录后尽快插入每个人的profile.php。 这里的问题是它看起来像以前的编码器使用过json。

示例:

表结构:用户名,密码,expdate

只有表expdate在json中编码(我认为),因为它有类似于:1544301180或NULL - > NULL表示UNLIMITED,1544301180表示某种日期。这个日期目前是非人类可读的。

我该如何实施?

我将向您展示完整的PHP内容:

INDEX.PHP(人们登录的地方)

<?php
include('login.php'); // Includes Login Script

if(isset($_SESSION['login_user'])){
header("location: profile.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Login Form in PHP with Session</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="main">
<h1>PHP Login Session Example</h1>
<div id="login">
<h2>Login Form</h2>
<form action="" method="post">
<label>UserName :</label>
<input id="name" name="username" placeholder="username" type="text">
<label>Password :</label>
<input id="password" name="password" placeholder="**********" type="password">
<input name="submit" type="submit" value=" Login ">
<span><?php echo $error; ?></span>
</form>
</div>
</div>
</body>
</html>

LOGIN.PHP(配置和连接mysql db)

<?php
session_start(); // Starting Session
$error=''; // Variable To Store Error Message
if (isset($_POST['submit'])) {
if (empty($_POST['username']) || empty($_POST['password'])) {
$error = "Username or Password is invalid";
}
else
{
// Define $username and $password
$username=$_POST['username'];
$password=$_POST['password'];
// Establishing Connection with Server by passing server_name, user_id and password as a parameter
$connection = mysql_connect("localhost", "changed", "changed");
// To protect MySQL injection for Security purpose
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
// Selecting Database
$db = mysql_select_db("unibebio", $connection);
// SQL query to fetch information of registerd users and finds user match.
$query = mysql_query("select * from users where password='$password' AND username='$username'", $connection);
$rows = mysql_num_rows($query);
if ($rows == 1) {
$_SESSION['login_user']=$username; // Initializing Session
header("location: profile.php"); // Redirecting To Other Page
} else {
$error = "Username or Password is invalid";
}
mysql_close($connection); // Closing Connection
}
}
?>

SESSION.PHP(用户会话检查程序)

<?php
// Establishing Connection with Server by passing server_name, user_id and password as a parameter
$connection = mysql_connect("localhost", "changed", "changed");
// Selecting Database
$db = mysql_select_db("unibebio", $connection);
session_start();// Starting Session
// Storing Session
$user_check=$_SESSION['login_user'];

// SQL Query To Fetch Complete Information Of User
$ses_sql=mysql_query("select username from users where username='$user_check'", $connection);
$row = mysql_fetch_assoc($ses_sql);
$login_session =$row['username'];

if(!isset($login_session)){
mysql_close($connection); // Closing Connection
header('Location: index.php'); // Redirecting To Home Page
}
?>

所有这一切都运行良好,直到我们登陆PROFILE.PHP,我们需要显示人类可读的到期日期格式。但我不知道如何做到或实现它:

<?php
include('session.php');
?>
<!DOCTYPE html>
<html>
<head>
<title>UNIBE BIOCHEMIE</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="profile">
<b id="welcome">Welcome : <i><?php echo $login_session; ?></i></b>
<b id="logout"><a href="logout.php">Log Out</a></b>
</div>
</body>
</html>

正如您所看到的,它可以工作,并且它回显了该特定用户表中的用户名。

但是我怎么能在(我认为)json编码的到期日期做同样的事情?

正如我所说,表结构是:username,password,expdate

0 个答案:

没有答案