So I want to access a variable ($username
) from file quickprotect.login.php
and print it in file index.php
. File login.ini.php
contains username configuration and quickprotect.login.php
contains:
<?php
$root = dirname(__FILE__);
class quickprotect {
private $ini_file_location = "login.ini.php";
private static $tries;
public static $errormsg;
public $settings;
public function __construct() {
session_start();
$this->ini_file_location = $GLOBALS[root] . "/" . $this->ini_file_location;
$this->settings = @parse_ini_file($this->ini_file_location);
if (!$this->settings) {
die("Failed to load the INI file located at: $this->ini_file_location.");
}
}
public function login($username, $password) {
// Performs login by initializing $_SESSION vars
// Returns true or false, plus $_SESSION message on success/failiure
// Contains brute force protection
if (!isset($_SESSION['tries'])) $_SESSION['tries'] = 1;
if ($_SESSION['tries'] <= intval($this->settings[MAX_TRIES]) || $this->settings[ALLOW_UNLIMITED_TRIES] == true) {
//Try to prevent brute forcing
if (sha1(trim($password)) == trim($this->settings[ADMIN_PW]) && $username === $this->settings[USERNAME]) {
// other codes
}
}
}
}
And when I use:
include 'quickprotect.login.php';
echo "User: $username";
It gives:
User:
Can anyone advise? Thx in advance :)
Update: Solved it by:
include '../quickprotect.class.php'
$qp = new quickprotect();
$un= $qp->settings['USERNAME'];
mail("mail@domain.com","Report","=== Username: $un");
you can use php $_POST if you are using form on other page
Are you sure you wrote this ?
echo "User: $username";
Because it should be
echo "User: ".$username;
To get the actual value of the variable.