Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> __construct i blad brakujacego argumentu
spandor
post
Post #1





Grupa: Zarejestrowani
Postów: 99
Pomógł: 0
Dołączył: 2.03.2004

Ostrzeżenie: (0%)
-----


witam,

mam taki konstruktor jak ponizej, dlaczego wyzuca mi blad:
Missing argument 1 for authentication::__construct(),
Missing argument 2 for authentication::__construct(),

  1. <?php
  2. class authentication {
  3.    var $mysql = 'dsadsad';
  4.    var $session;
  5.  
  6.    function __construct($mysql, $session) {
  7.       $this->mysql     = $mysql;
  8.       $this->session   = $session;
  9.    }
  10.  
  11.    function authentication() {
  12.    global $smarty, $l;
  13.        $session_var['authentication']  = $this->session->_read('authentication');
  14.        if (empty($session_var)) {
  15.            $smarty->display('inc_login.tpl');
  16.          
  17.            if (!empty($_POST) and empty($_POST['user_username'])) {
  18.                $smarty->assign('error', $l['username_field_left_empty']);
  19.            } else if (!empty($_POST) and empty($_POST['user_password'])) {
  20.                $smarty->assign('error', $l['password_field_left_empty']);
  21.            } else if (!empty($_POST)) {
  22.                $result = $this->mysql->query_one_result("SELECT COUNT(*) FROM `user`
  23.                                                          WHERE `login`='".$this->mysql->escape($_POST['AuthenticationLogin'])."'
  24.                                                          AND `password`='".$this->mysql->escape($this->secure($_POST['AuthenticationPassword']))."';");
  25.                if (empty($result)) {
  26.                    $smarty->assign('error', $l['username_or_password_is_incorrect']);
  27.                } else {
  28.                    $result = $this->mysql->query_one_result("SELECT `user_id` FROM `user`
  29.                                                              WHERE `login`='".$this->mysql->escape($_POST['AuthenticationLogin'])."'
  30.                                                              AND `password`='".$this->mysql->escape($this->secure($_POST['AuthenticationPassword']))."';");
  31.                  
  32.                    $this->session->_write('authentication', $result);
  33.                  
  34.                    header('Location: index.php');
  35.                }
  36.            }
  37.            exit;
  38.        } else if (!empty($session_var['authentication']) and isset($_GET['logout'])) {
  39.            $this->logout();          
  40.        }
  41.    }
  42.  
  43.    function check_authentication() {
  44.        $session_var['authentication']  = $this->session->_read('authentication');
  45.        return (!empty($session_var['authentication'])) ? $session_var['authentication'] : FALSE;
  46.    }
  47.  
  48.    function logout() {
  49.        $this->session->_destroy('authentication');
  50.        header('Location: '.BASE_URL);
  51.    }
  52.  
  53.    // Used so that it would be easier later to change encode method.
  54.    function secure($data) {
  55.        return md5($data);
  56.    }
  57. }
  58. ?>


Ten post edytował spandor 16.02.2009, 00:56:01
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
likemandrake
post
Post #2





Grupa: Zarejestrowani
Postów: 175
Pomógł: 17
Dołączył: 23.06.2006

Ostrzeżenie: (0%)
-----


Słyszałeś o tablicy $_SESSION? Chyba nie, no więc poczytaj sobie. I te Twoje "pseudo" funkcje(?), obiekty(?) typu $session->_read(), $session->_write(), no nie wiem z którego kosmosu to masz... Funkcja to funkcja, czyli session_read(), session_write(), po za tym nie używaj ich, bo całym rozwiązaniem jest tu stosowanie właśnie tablicy $_SESSION... W klasie musisz mieć tylko pewność, że sesja została wystartowana, a więc sprawdzasz to powiedzmy w konstruktorze, jak wiesz, że sesja nie została uruchomiona, wywalasz wyjątek. Do konstruktora przekazujesz tylko połączenie z bazą, po za tym wywal te Twoje var $session i pochodne.

php.net chyba Twoim wrogiem jest, wystarczy że poszukasz coś o session_start() i już masz z lewej liste wszystkich funkcji do obsługi sesji, po za tym jak zjedziesz troszkę na dół strony, masz też odwołania i m.in. na liście odwołań pojawiło się magiczne słowo $_SESSION.

Jeżeli jest tak jak piszesz, że skrypt masz z netu, to ja naprawdę nie wiem gdzie ja żyję (IMG:http://forum.php.pl/style_emoticons/default/biggrin.gif)

Ten post edytował likemandrake 17.02.2009, 10:51:03
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 10.10.2025 - 18:55