Otóż w poniższym kodzie przy logowaniu ciągle wyskakuje mi
Kod
Warning: Cannot modify header information - headers already sent in /var/www/localhost/htdocs/gregads/core/cookie.inc on line 43
Już nie mam pomysłu gdzie mam błąd;/ Żadnych pustych wierszy na koncu pliku nie mam.
Sprawa związana jest z linijką
Kod
$cookie->set();
w pliku login php.Oto pliki:
login.php
<?php include "core/cookie.inc"; include_once "HTML/Template/Flexy.php"; include_once "PEAR.php"; include_once "DB.php"; require_once 'DB/DataObject.php'; $options = &PEAR::getStaticProperty('HTML_Template_Flexy','options'); $options = $config['HTML_Template_Flexy']; $options = &PEAR::getStaticProperty('DB_DataObject','options'); $options = $config['DB_DataObject']; $originating_uri = $_GET["originating_uri"]; class LoginPage{ public $originating_uri; function authentication(){ { cookie::logout(); } $usr = DB_DataObject::Factory('users'); $usr->whereAdd('login="'.$_POST['uid'].'" and password="'.$_POST['psw'].'"'); $i = $usr->find(); if ($i == 1){ $usr->fetch(); $cookie = new cookie($_POST['uid']); $cookie->set(); $_SESSION['user'] = $usr->forename.' '.$usr->surname; $_SESSION['admin'] = $usr->admin == 1 ? true : false; exit; } else { } } } } $flexy = new HTML_Template_Flexy(); $flexy->compile("login.html"); $outputObject = new LoginPage(); $outputObject->authentication(); $flexy->outputObject($outputObject); ?>
cookie.inc
<?php class AuthException extends Exception{} class cookie { private $created; public $userid; private $version; private $td; public function __construct($userid = false){ $this->td = mcrypt_module_open(cookie::$cypher, '', cookie::$mode, ''); if($userid){ $this->userid = $userid; return; } else{ $buffer = $this->_unpackage($_COOKIE[self::$cookiename]); } else{ throw new AuthException('brak pliku cookie'); } } } public function __destruct(){ mcrypt_module_close($this->td); } public function set(){ $cookie = $this->_package(); } public function validate(){ if(!$this->version || !$this->created || !$this->userid){ throw new AuthException('Zly format pliku cookie'); } if($this->version != self::$myversion){ throw new AuthException('Niezgodnosc wersji'); } throw new AuthException('Plik cookie jest nieważzny'); $this->set(); } } } public function _package(){ return $this->_encrypt($cookie); } private function _unpackage($cookie){ $buffer = $this->_decrypt($cookie); if($this->version != self::$myversion || !$this->created || !$this->userid){ throw new AuthException(); } } private function _encrypt ($plaintext) { $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($this->td), MCRYPT_RAND); mcrypt_generic_init($this->td, self::$key, $iv); $crypttext = mcrypt_generic($this->td, $plaintext); mcrypt_generic_deinit($this->td); return $iv.$crypttext; } private function _decrypt($crypttext) { $ivsize = mcrypt_enc_get_iv_size($this->td); mcrypt_generic_init($this->td, self::$key, $iv); $plaintext = mdecrypt_generic($this->td, $crypttext); mcrypt_generic_deinit($this->td); return $plaintext; } private function _reissue(){ } } ?>