Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] syntax error - klasa
hhg
post
Post #1





Grupa: Zarejestrowani
Postów: 316
Pomógł: 0
Dołączył: 5.07.2006

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


napisalem moja pierwsza w zyciu klase i od razu dostaje blad (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Cytat
Parse error: syntax error, unexpected T_VARIABLE in /home/bart/public_html/mailing/mail.class.php on line 5
gdzie 5 linia wskazuje na pierwszy przypisanie w klasie

nie pisze ze ta klasa jest juz gotowa ale prosze o wskazowki co moze jeszcze nie zadzialac, i czy te 'public' powinienem gdzies powinienem zmienic na inne?

z gory dzieki za pomoc
  1. <?php
  2.  
  3. class site
  4. {
  5. public $ip = $_SERVER['REMOTE_ADDR'];
  6. public $host = $gethostbyaddr($this->ip);
  7.  
  8. public $subject;
  9. public $firm;
  10. public $name;
  11. public $telephone;
  12. public $sender;
  13. public $receiver;
  14.  
  15. public function validate($attribute)
  16. {
  17. if (empty($attribute))
  18. return false;
  19. else
  20. return true;
  21. }
  22.  
  23. public $text = nl2br("
  24. Wiadomosc od: $this->sender
  25. Firma: $this->firm
  26. Telefon: $this->telephone
  27. Imie i nazwisko: $this->name
  28.  
  29. $this->text;
  30.  
  31. IP nadawcy: $this->ip
  32. HOST nadawcy: $this->host
  33. ");
  34.  
  35. public function $mailto()
  36. {
  37.  
  38. if (!(validate($this->subject) && validate($this->firm) && validate($this->name) && validate($this->telephone) && validate($this->sender) && validate($this->receiver)))
  39. {
  40. echo "Wszystkie pola sa wymagane. Popaw wprowadzone dane!";
  41. exit();
  42. }
  43.  
  44. $headers = "MIME-Version: 1.0 rn Content-type: text/html; charset=iso-8859-2 rn From: $this->sender rn";
  45.  
  46. if (mail($this->receiver;$this->subject;$this->text;$headers))
  47. echo "email zostal pomyslnie wyslany";
  48.  
  49. }
  50.  
  51. }
  52.  
  53.  
  54.  
  55.  
  56. ?>


Ten post edytował hhg 7.01.2007, 04:17:14
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 5)
altruista
post
Post #2





Grupa: Zarejestrowani
Postów: 40
Pomógł: 0
Dołączył: 13.09.2006

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


ja mialem tak jak pliki *.php byly parsowane przez stara wersje php.
Go to the top of the page
+Quote Post
koodlaty
post
Post #3





Grupa: Zarejestrowani
Postów: 118
Pomógł: 3
Dołączył: 6.07.2006
Skąd: Dublin

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


Cytat
  1. <?php
  2. public $ip = $_SERVER['REMOTE_ADDR'];
  3. public $host = $gethostbyaddr($this->ip);
  4. ?>

  1. <?php
  2. public $text = nl2br("
  3. Wiadomosc od: $this->sender
  4. Firma: $this->firm
  5. Telefon: $this->telephone
  6. Imie i nazwisko: $this->name
  7.  
  8. $this->text;
  9.  
  10. IP nadawcy: $this->ip
  11. HOST nadawcy: $this->host
  12. ");
  13. ?>

Pola klasy dekleruj na samym poczatku a ich warosci okreslaj w konstruktorze:

  1. <?php
  2. class site
  3. {
  4.  public $ip;
  5.  public $host;
  6.  public $text;
  7.  
  8.  function __construct()
  9.  {
  10. $this -> ip = $_SERVER['REMOTE_ADDR'];
  11. $this -> $host = $gethostbyaddr($this->ip);
  12. $this -> $text = nl2br("
  13.  Wiadomosc od: $this->sender
  14.  Firma: $this->firm
  15.  Telefon: $this->telephone
  16.  Imie i nazwisko: $this->name
  17.  
  18.  $this->text;
  19.  
  20.  IP nadawcy: $this->ip
  21.  HOST nadawcy: $this->host
  22. ");
  23.  }
  24.  
  25.  ...
  26.  
  27. }
  28. ?>


Cytat
  1. <?php
  2. public function $mailto()
  3. ?>

Przekombinowałeś. Nazwy metod nie moga rozpoczynać się od - '$'


W treść klasynie nie wnikam... (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Poczytaj jeszcze trochę i kombinuj dalej... (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Ten post edytował koodlaty 7.01.2007, 10:23:59
Go to the top of the page
+Quote Post
dr_bonzo
post
Post #4





Grupa: Przyjaciele php.pl
Postów: 5 724
Pomógł: 259
Dołączył: 13.04.2004
Skąd: N/A

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


Uruchamiasz kod pod php5 czy php4?
Go to the top of the page
+Quote Post
hhg
post
Post #5





Grupa: Zarejestrowani
Postów: 316
Pomógł: 0
Dołączył: 5.07.2006

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


wszystko pod php5


dobra dzieki wprowadzilem poprawki i maile sa wysylane (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) (IMG:http://forum.php.pl/style_emoticons/default/exclamation.gif) ! niestety nie widac od kogo sa te maile tylko apache sa wstawiane jakby za zmienna $this->sender, ale to juz wina serwera prawda?

jeszcze mam do Was pytanie ktore zmienna i funkcje bezpieczniej byloby poprzedzic 'protected' lub 'private'

oto obecny kod


  1. <?php
  2. class mailing
  3. {
  4.  
  5. public $ip;
  6. public $host;
  7. public $text;
  8.  
  9. public function __construct()
  10. {
  11. $this -> ip = $_SERVER['REMOTE_ADDR'];
  12. $this -> host = gethostbyaddr($this->ip);
  13. $this -> text = nl2br("
  14. Wiadomosc od: $this->sender
  15. Firma: $this->firm
  16. Telefon: $this->telephone
  17. Imie i nazwisko: $this->name
  18.  
  19. $this->text
  20.  
  21. IP nadawcy: $this->ip
  22. HOST nadawcy: $this->host
  23. ");
  24. }
  25.  
  26. public $subject;
  27. public $firm;
  28. public $name;
  29. public $telephone;
  30. public $sender;
  31. public $receiver;
  32.  
  33. public function validate($attribute)
  34. {
  35. if (empty($attribute))
  36. return false;
  37. else
  38. return true;
  39. }
  40.  
  41. public 
  42.  
  43. public function mailto()
  44. {
  45.  
  46. if (!($this->validate($this->subject) && $this->validate($this->firm) && $this->validate($this->name) && $this->validate($this->telephone) && $this->validate($this->sender) && $this->validate($this->receiver)))
  47. {
  48. echo "Wszystkie pola sa wymagane. Popaw wprowadzone dane!";
  49. exit();
  50. }
  51.  
  52. $headers = "MIME-Version: 1.0 rn Content-type: text/html; charset=iso-8859-2 rn From: $this->sender rn";
  53.  
  54. if (mail($this->receiver,$this->subject,$this->text,$headers))
  55. echo "email zostal pomyslnie wyslany";
  56.  
  57. }
  58.  
  59. }
  60.  
  61.  
  62. $mojmail = new mailing();
  63. $mojmail -> subject = 'temat wiadomosci';
  64. $mojmail -> firm = 'nazwa firmy qwrewrwer';
  65. $mojmail -> name = 'Jan Kowalski';
  66. $mojmail -> telephone = '666';
  67. $mojmail -> sender = 'james@bond.com';
  68. $mojmail -> receiver = 'MOJ@ADRES.PL';
  69. $mojmail -> mailto();
  70. ?>
Go to the top of the page
+Quote Post
Cysiaczek
post
Post #6





Grupa: Moderatorzy
Postów: 4 465
Pomógł: 137
Dołączył: 26.03.2004
Skąd: Gorzów Wlkp.




Skrypt raczej nie będzie przez to bezpieczniejszy. Zobacz do czego są te słowa kluczowe : http://www.php.net/manual/pl/language.oop5.visibility.php

Pozdrawiam.
Go to the top of the page
+Quote Post

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: 3.10.2025 - 01:05