-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
40 lines (33 loc) · 907 Bytes
/
functions.php
File metadata and controls
40 lines (33 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
// Start the session at the top of every PHP file that uses sessions
session_start();
function check_login($conn)
{
if(isset($_SESSION['user_id'])){
$id = $_SESSION['user_id'];
$query = "SELECT * FROM website WHERE user_id = '$id' LIMIT 1";
$result = mysqli_query($conn, $query);
if($result && mysqli_num_rows($result) > 0){
$user_data = mysqli_fetch_assoc($result);
return $user_data;
}
}
// Debugging statement
echo "User not logged in, redirecting to membership page.";
// Redirect to membership if not logged in
header("Location: membership.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;
}