Class wordt 2 maal afgelopen
ik heb hetvolgende script gemaakt:
OOPclasses.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
50
51
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
<?PHP
//The login class
class login {
public $username; //first variable username, public
private $password; //second variable password, private
function getUsername() //retrieve username if set
{
return $this->username;
}
function getPassword()
{
return $this->password;
}
function setUsername($username) //set username
{
$this->username = $username;
}
function setPassword($password) //set password (no getPassword is used because this is nog neccesary, the password is secret)
{
$this->password = SHA1($password); //password will be encoded in a SHA1 right away
}
function Login()
{
// retrieving intel from database //
$sql = "SELECT username FROM users WHERE username='".$this->username."' AND password='".$this->password."'";
$query = mysql_query($sql) or die(mysql_error());
$nums = mysql_num_rows($query);
if($nums < 1)
{
//no match with database error.
echo "Your details were not correct, please try again...";
}
else
{
//make cookie to get the user logged in.
setcookie("ChiroAdminPanelUser", $this->username, time()+(60*60*24), "Http://www.chiroschaffen.be");
echo "You were succesfully logged in, please wait while you are being redirected...";
}
}
}
?>
//The login class
class login {
public $username; //first variable username, public
private $password; //second variable password, private
function getUsername() //retrieve username if set
{
return $this->username;
}
function getPassword()
{
return $this->password;
}
function setUsername($username) //set username
{
$this->username = $username;
}
function setPassword($password) //set password (no getPassword is used because this is nog neccesary, the password is secret)
{
$this->password = SHA1($password); //password will be encoded in a SHA1 right away
}
function Login()
{
// retrieving intel from database //
$sql = "SELECT username FROM users WHERE username='".$this->username."' AND password='".$this->password."'";
$query = mysql_query($sql) or die(mysql_error());
$nums = mysql_num_rows($query);
if($nums < 1)
{
//no match with database error.
echo "Your details were not correct, please try again...";
}
else
{
//make cookie to get the user logged in.
setcookie("ChiroAdminPanelUser", $this->username, time()+(60*60*24), "Http://www.chiroschaffen.be");
echo "You were succesfully logged in, please wait while you are being redirected...";
}
}
}
?>
login.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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?PHP
require("headerbf.php");
if(IsSet($_POST['submitLogin']) && IsSet($_POST['name']) && IsSet($_POST['password'])) //Login
{
//Using OOP to login
require("OOPclasses.php");
$login = new login; //creating class
$login->setUsername($_POST['name']); //registering name
$login->setPassword($_POST['password']); //registering password
$login->Login(); //logging in
}
?>
<!---- The login form --->
<form method="post">
<input type="text" name="name" value="username" /><br />
<input type="password" name="password" value="password" /><br />
<input type="submit" name="submitLogin" value="Log in" /><br />
</form>
<?PHP
require("footer.php");
?>
require("headerbf.php");
if(IsSet($_POST['submitLogin']) && IsSet($_POST['name']) && IsSet($_POST['password'])) //Login
{
//Using OOP to login
require("OOPclasses.php");
$login = new login; //creating class
$login->setUsername($_POST['name']); //registering name
$login->setPassword($_POST['password']); //registering password
$login->Login(); //logging in
}
?>
<!---- The login form --->
<form method="post">
<input type="text" name="name" value="username" /><br />
<input type="password" name="password" value="password" /><br />
<input type="submit" name="submitLogin" value="Log in" /><br />
</form>
<?PHP
require("footer.php");
?>
headerbf.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
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
<!---
- -------------------------------------- -
- Autor: Tim Cluyts
- Brand: StupiSoft productions
- -------------------------------------- -
- Chiro administration panel version 2.0
- Copyright StupiSoft productions 2009
- All rights reserved
- -------------------------------------- -
- This file is property of StupiSoft productions and is not be copied in any form possible,
- to recieve this file you can contact the author of this site ([email protected]).
- -------------------------------------- -
--->
<?PHP
require ("functions.php");
connect();
?>
<html>
<head>
<title>Chiroschaffen - Admin panel V2.0 - StupiSoft productions</title>
<link rel="stylesheet" href="ChiroStyleSheet.css" type="text/css" media="all">
<script type="text/javascript" src="ChiroJavaScript.js"></script>
</head>
<body>
<div class="headbanner">
<!---- This divider is used as a menu and contains links and dropdown contents built in javascript. ---->
<!---- getDropDown (theIdOfTheRelatedDivider) ---->
| File | Edit | Groups | Members | Mail | Help | <small>*Links are disabled</small>
</div>
<div class="myContent">
<!---- content window - Before login ---->
- -------------------------------------- -
- Autor: Tim Cluyts
- Brand: StupiSoft productions
- -------------------------------------- -
- Chiro administration panel version 2.0
- Copyright StupiSoft productions 2009
- All rights reserved
- -------------------------------------- -
- This file is property of StupiSoft productions and is not be copied in any form possible,
- to recieve this file you can contact the author of this site ([email protected]).
- -------------------------------------- -
--->
<?PHP
require ("functions.php");
connect();
?>
<html>
<head>
<title>Chiroschaffen - Admin panel V2.0 - StupiSoft productions</title>
<link rel="stylesheet" href="ChiroStyleSheet.css" type="text/css" media="all">
<script type="text/javascript" src="ChiroJavaScript.js"></script>
</head>
<body>
<div class="headbanner">
<!---- This divider is used as a menu and contains links and dropdown contents built in javascript. ---->
<!---- getDropDown (theIdOfTheRelatedDivider) ---->
| File | Edit | Groups | Members | Mail | Help | <small>*Links are disabled</small>
</div>
<div class="myContent">
<!---- content window - Before login ---->
nu is het probleem dat als ik wil inloggen hij beide meldingen geeft...
1 dat mijn gegevens fout zijn
en 2 dat ik wel ben ingelogd...
hij zegt ook (door de cookie denk ik) dat de header al verzonder is maak ik zou bijgod niet weten waar...
heeft iemand een idee of ziet iemand mijn fout?
heel erg bedankt bij voorbaat.
**EDIT**
de error:
Your details were not correct, please try again...
Warning: Cannot modify header information - headers already sent by (output started at /home/waranderock.be/www/Chiro/headerbf.php:11) in /home/waranderock.be/www/Chiro/OOPclasses.php on line 38
You were succesfully logged in, please wait while you are being redirected...
Gewijzigd op 01/01/1970 01:00:00 door Tikkes C
Je gebruikt ergens een header(), maar er is dan al output (een echo of html) naar de browser verzonden... en dat mag niet.
Je gebruikt ergens een header(), maar er is dan al output (een echo of html) naar de browser verzonden... en dat mag niet.
dat is het net...de bovenstaande bestanden is alles wat ik op dat moment gebruik...
je cookie aanroep is ook een header. Daarop loopt die waarschijnlijk vast (tenminste ik gok dat de regel nummers hier niet overeen komen met de regel nummers in je eigen bestanden.
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
<!---
- -------------------------------------- -
- Autor: Tim Cluyts
- Brand: StupiSoft productions
- -------------------------------------- -
- Chiro administration panel version 2.0
- Copyright StupiSoft productions 2009
- All rights reserved
- -------------------------------------- -
- This file is property of StupiSoft productions and is not be copied in any form possible,
- to recieve this file you can contact the author of this site ([email protected]).
- -------------------------------------- -
--->
- -------------------------------------- -
- Autor: Tim Cluyts
- Brand: StupiSoft productions
- -------------------------------------- -
- Chiro administration panel version 2.0
- Copyright StupiSoft productions 2009
- All rights reserved
- -------------------------------------- -
- This file is property of StupiSoft productions and is not be copied in any form possible,
- to recieve this file you can contact the author of this site ([email protected]).
- -------------------------------------- -
--->
Cookies zijn headers, en setcookie moet dus een header wegschrijven. En headers moeten voor content gaan, want dat zijn de regeltjes van het HTTP protocol.
Dus de simpele oplossing is: Zet het stukje PHP code voor de comment, of beter, verplaats de comment naar de PHP code zodat hij niet naar de gebruiker opgestuurd wordt (en daar boven doctype en de root-tag staat, en daardoor geen roet in het eten gooit voor de geldigheid van je HTML :) )
hoe kan dit? wat doe ik dan fout?
(indien ik het met PP oplos werkt het wel goed maar ik wil het in OOP in orde krijgen...iemand?)