Apply fixes from StyleCI
							parent
							
								
									b2f0fedce4
								
							
						
					
					
						commit
						edfec973b8
					
				@ -1,40 +1,40 @@
 | 
			
		||||
<?php
 | 
			
		||||
session_start();
 | 
			
		||||
// Generate random 6 character string
 | 
			
		||||
$captcha_code = substr(str_shuffle('01234567890123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'), 0, 6);
 | 
			
		||||
// Update the session variable
 | 
			
		||||
$_SESSION['captcha'] = $captcha_code;
 | 
			
		||||
// Create the image canvas - width: 150px; height: 50px;
 | 
			
		||||
$final_image = imagecreate(150, 50);
 | 
			
		||||
// Background color (RGBA)
 | 
			
		||||
$rgba = [241, 245, 248, 0];
 | 
			
		||||
// Set the background color
 | 
			
		||||
$image_bg_color = imagecolorallocatealpha($final_image, 241, 245, 248, 0);
 | 
			
		||||
// Convert the captcha text to an array
 | 
			
		||||
$captcha_code_chars = str_split($captcha_code);
 | 
			
		||||
// Iterate the above array
 | 
			
		||||
for($i = 0; $i < count($captcha_code_chars); $i++) {
 | 
			
		||||
    // Create the character image canvas
 | 
			
		||||
    $char_small = imagecreate(130, 16);
 | 
			
		||||
    $char_large = imagecreate(130, 16);
 | 
			
		||||
    // Character background color
 | 
			
		||||
    $char_bg_color = imagecolorallocate($char_small, 241, 245, 248);
 | 
			
		||||
    // Character color
 | 
			
		||||
    $char_color = imagecolorallocate($char_small, rand(80,180), rand(80,180), rand(80, 180));
 | 
			
		||||
    // Draw the character on the canvas
 | 
			
		||||
    imagestring($char_small, 1, 1, 0, $captcha_code_chars[$i], $char_color);
 | 
			
		||||
    // Copy the image and enlarge it
 | 
			
		||||
    imagecopyresampled($char_large, $char_small, 0, 0, 0, 0, rand(250, 400), 16, 84, 8);
 | 
			
		||||
    // Rotate the character image
 | 
			
		||||
    $char_large = imagerotate($char_large, rand(-6,6), 0);
 | 
			
		||||
    // Add the character image to the main canvas
 | 
			
		||||
    imagecopymerge($final_image, $char_large, 20 + (20 * $i), 15, 0, 0, imagesx($char_large), imagesy($char_large), 70);
 | 
			
		||||
    // Destroy temporary canvases
 | 
			
		||||
    imagedestroy($char_small);
 | 
			
		||||
    imagedestroy($char_large);
 | 
			
		||||
}
 | 
			
		||||
// Output the created image
 | 
			
		||||
header('Content-type: image/png');
 | 
			
		||||
imagepng($final_image);
 | 
			
		||||
imagedestroy($final_image);
 | 
			
		||||
?>
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
session_start();
 | 
			
		||||
// Generate random 6 character string
 | 
			
		||||
$captcha_code = substr(str_shuffle('01234567890123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'), 0, 6);
 | 
			
		||||
// Update the session variable
 | 
			
		||||
$_SESSION['captcha'] = $captcha_code;
 | 
			
		||||
// Create the image canvas - width: 150px; height: 50px;
 | 
			
		||||
$final_image = imagecreate(150, 50);
 | 
			
		||||
// Background color (RGBA)
 | 
			
		||||
$rgba = [241, 245, 248, 0];
 | 
			
		||||
// Set the background color
 | 
			
		||||
$image_bg_color = imagecolorallocatealpha($final_image, 241, 245, 248, 0);
 | 
			
		||||
// Convert the captcha text to an array
 | 
			
		||||
$captcha_code_chars = str_split($captcha_code);
 | 
			
		||||
// Iterate the above array
 | 
			
		||||
for ($i = 0; $i < count($captcha_code_chars); $i++) {
 | 
			
		||||
    // Create the character image canvas
 | 
			
		||||
    $char_small = imagecreate(130, 16);
 | 
			
		||||
    $char_large = imagecreate(130, 16);
 | 
			
		||||
    // Character background color
 | 
			
		||||
    $char_bg_color = imagecolorallocate($char_small, 241, 245, 248);
 | 
			
		||||
    // Character color
 | 
			
		||||
    $char_color = imagecolorallocate($char_small, rand(80, 180), rand(80, 180), rand(80, 180));
 | 
			
		||||
    // Draw the character on the canvas
 | 
			
		||||
    imagestring($char_small, 1, 1, 0, $captcha_code_chars[$i], $char_color);
 | 
			
		||||
    // Copy the image and enlarge it
 | 
			
		||||
    imagecopyresampled($char_large, $char_small, 0, 0, 0, 0, rand(250, 400), 16, 84, 8);
 | 
			
		||||
    // Rotate the character image
 | 
			
		||||
    $char_large = imagerotate($char_large, rand(-6, 6), 0);
 | 
			
		||||
    // Add the character image to the main canvas
 | 
			
		||||
    imagecopymerge($final_image, $char_large, 20 + (20 * $i), 15, 0, 0, imagesx($char_large), imagesy($char_large), 70);
 | 
			
		||||
    // Destroy temporary canvases
 | 
			
		||||
    imagedestroy($char_small);
 | 
			
		||||
    imagedestroy($char_large);
 | 
			
		||||
}
 | 
			
		||||
// Output the created image
 | 
			
		||||
header('Content-type: image/png');
 | 
			
		||||
imagepng($final_image);
 | 
			
		||||
imagedestroy($final_image);
 | 
			
		||||
 | 
			
		||||
@ -1,37 +1,40 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
// Get Configuration
 | 
			
		||||
require '../system/config.php';
 | 
			
		||||
// Get Dashboard URL
 | 
			
		||||
$url = $file_url_destination."/admin/dashboard";
 | 
			
		||||
// (A) START SESSION 
 | 
			
		||||
$url = $file_url_destination.'/admin/dashboard';
 | 
			
		||||
// (A) START SESSION
 | 
			
		||||
session_start();
 | 
			
		||||
 
 | 
			
		||||
 | 
			
		||||
// (B) HANDLE LOGIN
 | 
			
		||||
if (isset($_POST["user"]) && !isset($_SESSION["user"])) {
 | 
			
		||||
  // (B1) USERS & PASSWORDS - SET YOUR OWN !
 | 
			
		||||
   $users = [
 | 
			
		||||
    email => password //  USER AND PASSWORD PULLED FROM CONFIGURATION FILE
 | 
			
		||||
  ];
 | 
			
		||||
 
 | 
			
		||||
  // (B2) CHECK & VERIFY
 | 
			
		||||
  if (isset($users[$_POST["user"]])) {
 | 
			
		||||
  // check captcha
 | 
			
		||||
  if ($_SESSION['captcha'] !== $_POST['captcha']) {
 | 
			
		||||
	header("Location: ?capfail");
 | 
			
		||||
	exit(0);
 | 
			
		||||
}
 | 
			
		||||
      // end captcha
 | 
			
		||||
    if ($users[$_POST["user"]] == $_POST["password"]) {
 | 
			
		||||
      $_SESSION["user"] = $_POST["user"];
 | 
			
		||||
if (isset($_POST['user']) && !isset($_SESSION['user'])) {
 | 
			
		||||
    // (B1) USERS & PASSWORDS - SET YOUR OWN !
 | 
			
		||||
    $users = [
 | 
			
		||||
        email => password, //  USER AND PASSWORD PULLED FROM CONFIGURATION FILE
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    // (B2) CHECK & VERIFY
 | 
			
		||||
    if (isset($users[$_POST['user']])) {
 | 
			
		||||
        // check captcha
 | 
			
		||||
        if ($_SESSION['captcha'] !== $_POST['captcha']) {
 | 
			
		||||
            header('Location: ?capfail');
 | 
			
		||||
            exit(0);
 | 
			
		||||
        }
 | 
			
		||||
        // end captcha
 | 
			
		||||
        if ($users[$_POST['user']] == $_POST['password']) {
 | 
			
		||||
            $_SESSION['user'] = $_POST['user'];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // (B3) FAILED LOGIN FLAG
 | 
			
		||||
    if (!isset($_SESSION['user'])) {
 | 
			
		||||
        $failed = true;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
  // (B3) FAILED LOGIN FLAG
 | 
			
		||||
  if (!isset($_SESSION["user"])) { $failed = true; }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
 | 
			
		||||
// (C) REDIRECT USER TO DASHBOARD IF SIGNED IN
 | 
			
		||||
if (isset($_SESSION["user"])) {
 | 
			
		||||
  header("Location: dashboard"); // REDIRECT TO DASHBOARD
 | 
			
		||||
  exit();
 | 
			
		||||
}
 | 
			
		||||
if (isset($_SESSION['user'])) {
 | 
			
		||||
    header('Location: dashboard'); // REDIRECT TO DASHBOARD
 | 
			
		||||
    exit();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,12 +1,15 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
// (A) START SESSION
 | 
			
		||||
session_start();
 | 
			
		||||
 
 | 
			
		||||
 | 
			
		||||
// (B) LOGOUT REQUEST
 | 
			
		||||
if (isset($_POST["logout"])) { unset($_SESSION["user"]); }
 | 
			
		||||
 
 | 
			
		||||
if (isset($_POST['logout'])) {
 | 
			
		||||
    unset($_SESSION['user']);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// (C) REDIRECT TO LOGIN PAGE IF NOT LOGGED IN
 | 
			
		||||
if (!isset($_SESSION["user"])) {
 | 
			
		||||
  header("Location: ../");
 | 
			
		||||
  exit();
 | 
			
		||||
}
 | 
			
		||||
if (!isset($_SESSION['user'])) {
 | 
			
		||||
    header('Location: ../');
 | 
			
		||||
    exit();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,14 +1,14 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
    $code = $_SERVER['REDIRECT_STATUS'];
 | 
			
		||||
    $codes = array(
 | 
			
		||||
    $codes = [
 | 
			
		||||
        403 => 'Forbidden',
 | 
			
		||||
        404 => '404 Not Found',
 | 
			
		||||
        500 => 'Internal Server Error'
 | 
			
		||||
    );
 | 
			
		||||
        500 => 'Internal Server Error',
 | 
			
		||||
    ];
 | 
			
		||||
    $source_url = 'http'.((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ? 's' : '').'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
 | 
			
		||||
    if (array_key_exists($code, $codes) && is_numeric($code)) {
 | 
			
		||||
        die("Error $code: {$codes[$code]}");
 | 
			
		||||
        exit("Error $code: {$codes[$code]}");
 | 
			
		||||
    } else {
 | 
			
		||||
        die('Unknown error');
 | 
			
		||||
        exit('Unknown error');
 | 
			
		||||
    }
 | 
			
		||||
?>
 | 
			
		||||
					Loading…
					
					
				
		Reference in New Issue