Online PHP and Javascript Decoder decode hidden script to uncover its real functionality


Show other level

     
// Start session only if one isn't already active
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "m3lmcompanyxvrp";

// Create a connection to the database
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Fetch all jobs from the database
$sql = "SELECT id, job_name, job_active FROM job_listing";
$result = $conn->query($sql);

// Check if records were found
$jobs = [];
if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $jobs[] = $row;
    }
} else {
    $_SESSION['error'] = "No jobs found.";
    header("Location: jobs.php");
    
}

// Fetch the logged-in user's username from the session
$loggedInUsername = $_SESSION['username'] ?? '';

// If the user is not logged in, redirect them to the login page
if (empty($loggedInUsername)) {
    $_SESSION['error'] = "You need to log in to access this page.";
    header("Location: login.php");
    
}

// Fetch user permissions from the database
$sql_permissions = "SELECT * FROM user_permissions WHERE username = ?";
$stmt_permissions = $conn->prepare($sql_permissions);
if (!$stmt_permissions) {
    die("Error in permissions SQL: " . $conn->error);
}
$stmt_permissions->bind_param("s", $loggedInUsername); // Bind username as a string
$stmt_permissions->execute();
$result_permissions = $stmt_permissions->get_result();
if (!$result_permissions) {
    die("Error in permissions query execution: " . $stmt_permissions->error);
}

// Fetch and store permissions in session
$permissions = [];
while ($row = $result_permissions->fetch_assoc()) {
    $permissions[] = $row;
}
$_SESSION['permissions'] = $permissions;

$is_admin = false;
$is_delete = false;
$is_arakabeh = false;
foreach ($permissions as $permission) {
    if ($permission['permission_name'] === 'admin' && $permission['granted'] == 1) {
        $is_admin = true;
    }
    if ($permission['permission_name'] === 'rakabeh' && $permission['granted'] == 1) {
        $is_arakabeh = true;
    }
    if ($permission['permission_name'] === 'delete' && $permission['granted'] == 1) {
        $is_delete = true;
    }
    // If all permissions are found, exit the loop early
    if ($is_admin && $is_delete && $is_arakabeh) {
        break;
    }
}

// If the user doesn't have permission, set an error message and redirect
if (!$is_admin && !$is_arakabeh) {
    $_SESSION['error'] = "لايوجد اي صلاحيات للوصل لهذه الصفحة.";
    header("Location: dashboard.php"); // Redirect to an error page or another page
    
}

// Close the database connection
$conn->close();

     
// Start session only if one isn't already active
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}



$password = "";


// Create a connection to the database
$conn = new mysqli("localhost", "root", $password, "m3lmcompanyxvrp");

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Fetch all jobs from the database
$sql = "SELECT id, job_name, job_active FROM job_listing";
$result = $conn->query($sql);

// Check if records were found
$jobs = [];
if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $jobs[] = $row;
    }
} else {
    $_SESSION['error'] = "No jobs found.";
    header("Location: jobs.php");
    
}

// Fetch the logged-in user's username from the session
$loggedInUsername = $_SESSION['username'] ?? '';

// If the user is not logged in, redirect them to the login page
if (empty($loggedInUsername)) {
    $_SESSION['error'] = "You need to log in to access this page.";
    header("Location: login.php");
    
}

// Fetch user permissions from the database
$sql_permissions = "SELECT * FROM user_permissions WHERE username = ?";
$stmt_permissions = $conn->prepare($sql_permissions);
if (!$stmt_permissions) {
    die("Error in permissions SQL: " . $conn->error);
}
$stmt_permissions->bind_param("s", $loggedInUsername); // Bind username as a string
$stmt_permissions->execute();
$result_permissions = $stmt_permissions->get_result();
if (!$result_permissions) {
    die("Error in permissions query execution: " . $stmt_permissions->error);
}

// Fetch and store permissions in session
$permissions = [];
while ($row = $result_permissions->fetch_assoc()) {
    $permissions[] = $row;
}
$_SESSION['permissions'] = $permissions;

$is_admin = false;
$is_delete = false;
$is_arakabeh = false;
foreach ($permissions as $permission) {
    if ($permission['permission_name'] === 'admin' && $permission['granted'] == 1) {
        $is_admin = true;
    }
    if ($permission['permission_name'] === 'rakabeh' && $permission['granted'] == 1) {
        $is_arakabeh = true;
    }
    if ($permission['permission_name'] === 'delete' && $permission['granted'] == 1) {
        $is_delete = true;
    }
    // If all permissions are found, exit the loop early
    if ($is_admin && $is_delete && $is_arakabeh) {
        break;
    }
}

// If the user doesn't have permission, set an error message and redirect
if (!$is_admin && !$is_arakabeh) {
    $_SESSION['error'] = "لايوجد اي صلاحيات للوصل لهذه الصفحة.";
    header("Location: dashboard.php"); // Redirect to an error page or another page
    
}

// Close the database connection
$conn->close();



© 2023 Quttera Ltd. All rights reserved.