[OOP] call to private from invalid context
ik krijg de volgende error:
Fatal error: Call to private login::login() from invalid context in /home/waranderock.be/www/Chiro/login2.php on line 34
mijn class script is:
Code (php)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?PHP
class login
{
protected $username;
protected $password;
public function getUsername()
{
return $this->username;
}
public function getPassword()
{
return $this->password;
}
public function setUsername($username)
{
$this->username = $username;
}
public function setPassword($password)
{
$this->password = SHA1($password);
}
private function login()
{
$sql = "SELECT username FROM users WHERE username='".$this->username."' AND password='".$this->password."'";
$query = mysql_query($sql);
$object = mysql_num_rows($query);
if($object > 0)
{
//Making the session and redirecting the user to the announcements
$_SESSION['ChiroAdmin'] = $this->username;
echo "You were succesfully logged into the admin panel...'".$_SESSION['ChiroAdmin']."'<br />";
echo "Please wait, you will be redirected...";
echo "<META HTTP-EQUIV='refresh' content='3; URL=AdminAnnouncements.php' />";
}
else
{
echo "Your details were not correct...";
include "Footer.php";
exit;
}
}
}
?>
class login
{
protected $username;
protected $password;
public function getUsername()
{
return $this->username;
}
public function getPassword()
{
return $this->password;
}
public function setUsername($username)
{
$this->username = $username;
}
public function setPassword($password)
{
$this->password = SHA1($password);
}
private function login()
{
$sql = "SELECT username FROM users WHERE username='".$this->username."' AND password='".$this->password."'";
$query = mysql_query($sql);
$object = mysql_num_rows($query);
if($object > 0)
{
//Making the session and redirecting the user to the announcements
$_SESSION['ChiroAdmin'] = $this->username;
echo "You were succesfully logged into the admin panel...'".$_SESSION['ChiroAdmin']."'<br />";
echo "Please wait, you will be redirected...";
echo "<META HTTP-EQUIV='refresh' content='3; URL=AdminAnnouncements.php' />";
}
else
{
echo "Your details were not correct...";
include "Footer.php";
exit;
}
}
}
?>
login2.PHP
Code (php)
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
41
42
43
44
45
46
47
48
49
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
41
42
43
44
45
46
47
48
49
<?PHP
session_start();
/**
* Chiro Adminpanel Version 2.0
**
* A StupiSoft Production
* Autor: Tim Cluyts
**
* Copyright 2009
**/
ERROR_REPORTING(E_ALL);
ini_set(1, "display_errors");
require "functions.php";
connectToDb();
require "Classes.php";
?>
<html>
<head>
<title>Chiro Adminpanel V2.0 - A StupiSoft production</title>
<style type="text/stylesheet" src="ChiroStyle.css"></style>
<script type="text/javascript" src="ChiroJavascript.js"></script>
</head>
<body>
<div id="LoginForm">
<?PHP
//Login form submition
if(IsSet($_POST['LoginName']) && IsSet($_POST['LoginPass']) && IsSet($_POST['LoginSubmit']))
{
$userLogin = new login;
$userLogin->setUsername($_POST['LoginName']);
$userLogin->setPassword($_POST['LoginPass']);
$userLogin->login();
}
?>
<form method="post">
<input type="text" name="LoginName" value="Username" />
<input type="password" name="LoginPass" value="Pass" />
<input type="submit" name="LoginSubmit" value="Login" />
</form>
</div>
</body>
</html>
session_start();
/**
* Chiro Adminpanel Version 2.0
**
* A StupiSoft Production
* Autor: Tim Cluyts
**
* Copyright 2009
**/
ERROR_REPORTING(E_ALL);
ini_set(1, "display_errors");
require "functions.php";
connectToDb();
require "Classes.php";
?>
<html>
<head>
<title>Chiro Adminpanel V2.0 - A StupiSoft production</title>
<style type="text/stylesheet" src="ChiroStyle.css"></style>
<script type="text/javascript" src="ChiroJavascript.js"></script>
</head>
<body>
<div id="LoginForm">
<?PHP
//Login form submition
if(IsSet($_POST['LoginName']) && IsSet($_POST['LoginPass']) && IsSet($_POST['LoginSubmit']))
{
$userLogin = new login;
$userLogin->setUsername($_POST['LoginName']);
$userLogin->setPassword($_POST['LoginPass']);
$userLogin->login();
}
?>
<form method="post">
<input type="text" name="LoginName" value="Username" />
<input type="password" name="LoginPass" value="Pass" />
<input type="submit" name="LoginSubmit" value="Login" />
</form>
</div>
</body>
</html>
bedankt :D
Ik ben geen OO-expert, maar het heeft een bepaalde functie als een method dezelfde naam heeft als de class.
Gebruik eens een andere functie naam.
En daarnaast zou je die login method niet kunnen aanroepen aangezien het een private is. Maak deze dan public.
Oplossing: vervang private door public, en tada!
THANKS :D dat was het inderdaad :D