Jump to content

Member object: error!


rofl90

Recommended Posts

 

Fatal error: Call to a member function begin_login() on a non-object in /home/charliek/public_html/login.php on line 15

 

I was getting the basic stuff done when this! happened.. heres the code

 

login:

<?php
include "config.php";
include "classes/settings.php";
include "classes/user.php";
include "classes/core.php";
?>
<?php
if($action == "login") {
$username = $_POST['username'];
$password = $_POST['password'];
require_once("classes/login.php");
if($login->begin_login($username, $password) == '1') {
	header("Location: index.php");
	exit();
	}
else {
	echo $login->begin_login($username, $password);
}
}
?>
<form action="login.php?action=login" name="login" method="post">
<input type="text" name="username" class="inputtext" id="username" />
<input type="password" name="password" class="inputtext" id="password" />
<input type="submit" name="login" id="login" class="submit" value="Login" />
</form>

 

login.php

 

<?php
session_start();
class login extends database {
public $email;
public $password;
public $ip;
public $level;
public $time;
/**
 * Construct
 */
function __construct() {
	parent::__construct ();

}

public function begin_login($email, $password) {
	$email = mysql_real_escape_string($email);
	if ($email == "" || $password == "") {
		return "<div class=\"error\">You have left a <strong>required</strong> field <strong>blank!</strong><br /><br /><a onclick=\"dform();\" href=\"#\"><font color=\"white\">Go back</font></a></div>";
		exit ();
	} else {
		$this->username = $email;
		$this->password = $password;
		$this->ip = $_SERVER ["REMOTE_ADDR"];
		$this->time = time ();
		$this->check_username ();
	}
}

public function check_username() {
	$get_user = $this->query ( "SELECT email FROM users WHERE email='$this->username'" );
	$get_user_n = $this->num_rows ( $get_user );
	if ($get_user_n == "0") {
		$data = "Username: $this->username \n";
		$data .= "Password: $this->password \n";
		$data .= "Time: $this->time \n";
		$data .= "IP: $this->ip \n";
		$data .= "Type: BAD USERNAME";
		$this->query ( "INSERT INTO logins (data) VALUES('$data')" );
		return "<div class=\"error\">You have entered an <strong>incorrect</strong> password!<br /><br /><a onclick=\"dform();\" href=\"#\"><font color=\"white\">Go back</font></a></div>";
		exit ();
	} else {
		$this->check_password ();
	}
}

public function check_password() {
	global $password;
	$password_a = md5($password);
	$get_user_p = $this->query ( "SELECT email, password FROM users WHERE email='$this->username' AND password='$password_a'" );
	$get_user_p_n = $this->num_rows ( $get_user_p );
	if ($get_user_p_n == "0") {
		$data = "Username: $this->username \n";
		$data .= "Password: $this->password \n";
		$data .= "Time: $this->time \n";
		$data .= "IP: $this->ip \n";
		$data .= "Type: BAD PASSWORD";
		$this->query ( "INSERT INTO logins (data) VALUES('$data')" );
		return "<div class=\"error\">You have entered an <strong>incorrect</strong> password<br /><br /><a onclick=\"dform();\" href=\"#\"><font color=\"white\">Go back</font></a></div>";
		exit ();
	} else {
		$this->check_banned();
	}
}

public function check_banned() {
	$get_user_b = $this->query ( "SELECT banned FROM users WHERE user='$this->username'" );
	$get_user_b_a = $this->fetch_array ( $get_user_b );
	if ($get_user_b_a ["banned"] == "1") {
		return "<div class=\"error\">You are <strong>banned</strong>.<br /><br /><a onclick=\"dform();\" href=\"#\"><font color=\"white\">Go back</font></a></div>";
		exit ();
	} else {
		$this->check_confirmed();
	}
}

public function check_confirmed() {
	$get_user_b = $this->query ( "SELECT email_confirmed FROM users WHERE email='$this->username'" );
	$get_user_b_a = $this->fetch_array ( $get_user_b );
	if ($get_user_b_a ["email_confirmed"] == "0") {
		return "<div class=\"error\">Your email is not confirmed, please check your inbox and activate your account by clicking the link, thanks!.<br /><br /><a onclick=\"dform();\" href=\"#\"><font color=\"white\">Go back</font></a></div>";
		exit ();
	} else {
		$this->set_session();
	}
}

public function set_session() {
	$myuid_query = $this->query("SELECT id FROM users WHERE user='$this->username'");
	$myuid_arr = $this->fetch_array($myuid_query);
	$uid = $myuid_arr['id'];
	$this->ip = $_SERVER['REMOTE_ADDR'];
	$this->time = time();
	$session_id = session_id();
        $this->query("DELETE FROM session WHERE session_id='$session_id'");
        $this->query("DELETE FROM session WHERE userid='$uid'");
        $this->query("INSERT INTO session (session_id, ip, date, userid) VALUES('$session_id', '$this->ip', '$this->time', '$uid')");
	return "1";
}

/**
 * Destruct
 */
function __destruct() {

}
}

if (! isset ( $login )) {
$login = new login ( );
}

?>

Link to comment
Share on other sites

Terrible code. For starters, why does the login class extend database? It really doesn't. Secondly, automatically instantiating an object like that simply by including the file is rediculous. It should always be up to client code to decide what is instantiated and where.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.