-4
Good night!
I am working on a PHP project, and I came across a barrier, right at the end of my system:
It’s pretty simple even, it works like this:
1- ADMIN registers user, password and assigns an expiration date of the plan; (completed)
2 - USER comes across a login screen and password for access to the VIP panel; (completed)
3 - SYSTEM checks, based on the date that the ADMIN put to expire, whether the expiration date of the USER is greater than today’s date; (grabbed here)
Everything is already practically ready, what I lack is a way for the system to check, along with login and password, if the user’s expiration date > today’s date, if it is, it does not allow the user to log in and displays a message telling the user to contact an ADMIN.
I have no PHP course, the knowledge I have is all coming from Youtube and so I could not find any function to help me do this.
My login code and password:
<?php
include('conexao.php'); // conecta com o banco de dados
session_start(); // starta a sessão
$usuario = mysqli_real_escape_string($conexao, $_POST['usuario']); // define a variável usuário como sendo aquilo que está dentro do post do formulário
$senha = mysqli_real_escape_string($conexao, $_POST['senha']); // define a váriavel senha como sendo aquilo que está dentro do post da senha
$query = "select * from usuarios where usuario = '{$usuario}' and senha = '{$senha}' "; // query para selecionar tudo do banco de dados dos usuarios e verificar se possui um usuário e senha de fato
$result = mysqli_query($conexao, $query); // faz a conexão da query com o banco de dados
$row = mysqli_num_rows($result); // verifica o número de linhas encontradas
if($row == 1) { // caso encontrada 1 linha, então o usuário está cadastrado
$_SESSION['usuario'] = $usuario; // se o usuário está cadastrado, inicia uma sessão com seu nome
header('Location: conteudo'); // manda o usuário para a página do conteúdo VIP
} else { // se não está cadastrado
$_SESSION['nao_autenticado'] = true; // abre uma sessão nao autenticado
header('Location: login.php'); // volta o usuário para a página de login
exit(); // finaliza
}
?>
Things I tried to:
I tried to insert an Else if (I don’t know what it’s for, but it seems it’s an extra condition) along with the "check if there is a line", but I did not succeed, the page returned all wrong and blank, so I think it’s not even worth posting the code here.
I made the following code inside the VIP panel:
<?php
include('conexao.php');
$sql="SELECT (data) from usuarios where usuario = '{$_SESSION['usuario']}'";
$result=mysqli_query($conexao,$sql);
while($mostrar=mysqli_fetch_array($result)){
?>
<?php
$dt_atual = date("Y-m-d"); // data atual
$timestamp_dt_atual = strtotime($dt_atual); // converte para timestamp Unix
$dt_expira = $mostrar['data']; // data de expiração do plano
$timestamp_dt_expira = strtotime($dt_expira); // converte para timestamp Unix
// data atual é maior que a data de expiração
if ($timestamp_dt_atual > $timestamp_dt_expira){ // true
echo "Plano Expirado!";
session_destroy();
header ('location: index.php');
session_start();
$_SESSION['expira'] = true;
}
else // false
echo "Seu Plano Está Ativo!";
?>
This one even works, but the user gets direct access to the VIP panel and the information contained in it, and only when he updates that the system returns to the login page, I think it doesn’t work so.
Any answer helps me enough, maybe a function or something. Just missing this check for my system to work 100%, I am very grateful to the attention of all!!
Additional information:
- I have no problem in mysql table that is saving users' data;
- The mysql table is called users;
- The mysql table contains: ID NAME CELLULAR PASSWORD EXPIRATION DATE of each user.
I forgot to mention that the problem in question is the fact that the user who has the expired plan, get access to the VIP panel in the same way as the user who paid on time.
An example:
John paid to use my system for 30 days, after these 30 days John can no longer have access to the VIP panel, so the system in question would check John’s date with today and only take John to the VIP panel if the ADMIN has renewed John’s plan for another 30 days.
– Duda Gervásio