Website: http://valorantlfg.ga/
when u tried to go in signup page or signin page it will land you into this
Sources:
Signup PHP:
<?php
session_start();
include("connection.php");
include("functions.php");
if($_SERVER['REQUEST_METHOD'] == "POST")
{
//something was posted
$user_name = $_POST['user_name'];
$password = $_POST['password'];
if(!empty($user_name) && !empty($password) && !is_numeric($user_name))
{
//save to database
$user_id = random_num(20);
$query = "insert into users (user_id,user_name,password) values ('$user_id','$user_name','$password')";
mysqli_query($con, $query);
header("Location: login.php");
die;
}else
{
echo "Please enter some valid information!";
}
}
?>
Login Php:
<?php
session_start();
include("connection.php");
include("functions.php");
if($_SERVER['REQUEST_METHOD'] == "POST")
{
//something was posted
$user_name = $_POST['user_name'];
$password = $_POST['password'];
if(!empty($user_name) && !empty($password) && !is_numeric($user_name))
{
//read from database
$query = "select * from users where user_name = '$user_name' limit 1";
$result = mysqli_query($con, $query);
if($result)
{
if($result && mysqli_num_rows($result) > 0)
{
$user_data = mysqli_fetch_assoc($result);
if($user_data['password'] === $password)
{
$_SESSION['user_id'] = $user_data['user_id'];
header("Location: pages/Home");
die;
}
}
}
echo "<h3>wrong username or password!</h3>";
}else
{
echo "<h3>wrong username or password!</h3>";
}
}
?>
functions php:
<?php
function check_login($con)
{
if(isset($_SESSION['user_id']))
{
$id = $_SESSION['user_id'];
$query = "select * from users where user_id = '$id' limit 1";
$result = mysqli_query($con,$query);
if($result && mysqli_num_rows($result) > 0)
{
$user_data = mysqli_fetch_assoc($result);
return $user_data;
}
}
//redirect to login
header("Location: login.php");
die;
}
function random_num($length)
{
$text = "";
if($length < 5)
{
$length = 5;
}
$len = rand(4,$length);
for ($i=0; $i < $len; $i++) {
# code...
$text .= rand(0,9);
}
return $text;
}
connection php:
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "login_sample_db";
if(!$con = mysqli_connect($dbhost,$dbuser,$dbpass,$dbname))
{
die("failed to connect!");
}
Logout php:
<?php
session_start();
if(isset($_SESSION['user_id']))
{
unset($_SESSION['user_id']);
}
header("Location: /");
die;
For Logined page:
<?php
session_start();
include("connection.php");
include("functions.php");
$user_data = check_login($con);
```
connections php:
```
<?php $dbhost = "localhost"; $dbuser = "root"; $dbpass = ""; $dbname = "login_sample_db"; if(!$con = mysqli_connect($dbhost,$dbuser,$dbpass,$dbname)) { die("failed to connect!"); } Logout: <?php session_start(); if(isset($_SESSION['user_id'])) { unset($_SESSION['user_id']); } header("Location: /"); die; For Logined page: <?php session_start(); include("connection.php"); include("functions.php"); $user_data = check_login($con); ?>
```
Logout php:
```
<?php session_start(); if(isset($_SESSION['user_id'])) { unset($_SESSION['user_id']); } header("Location: /"); die; For Any Logined page: <?php session_start(); include("connection.php"); include("functions.php"); $user_data = check_login($con); ?>
```
For Any Logined Page:
```
<?php session_start(); include("connection.php"); include("functions.php"); $user_data = check_login($con); ?>
```
I used XAMPP Because its working but if i used Infinityfree database it will stop working now