Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Błąd w małym kodzie.
-Gość-
post
Post #1





Goście







Witam mam błąd w kodzie mcInfo.php, proszę o poprawę tego, nie rozumiem co jest źle.


index.php
  1. <?php
  2.  
  3. include('mcinfo.php');
  4.  
  5. $info = fetch_server_info($config['server']['ip'], $config['server']['posrt']);
  6.  
  7. ?>
  8. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  9. <html xmlns="http://w3.org/1999/xhtml">
  10. <head>
  11. <meta http-equiv="Content-Type" content="text/html; charset=utf-8 /"
  12. <title><?php echo $config['server']['ip']; ?> Status</title>
  13. </head>
  14. <body>
  15. <div>
  16. <hl><?php echo $config['server']['ip']; ?></hl>
  17. <?php
  18.  
  19. if ($info === false){
  20. ?>
  21. <p>
  22. Status: Wyłaczony
  23. </p>
  24. <?php
  25. }else{
  26. ?>
  27. <p>
  28. Status: Włączony
  29. </p>
  30. <p>
  31. Sloty <?php echo $info['playerCount']; ?> / <?php echo $info['maxplayers']; ?>
  32. </p>
  33. <p>
  34. Gracze: <?php echo implode(', ', $info['playerList']); ?>
  35. </p>
  36. <?php
  37.  
  38. }
  39.  
  40. ?>
  41. </div>
  42. </body>
  43. </html>


mcInfo.php
  1. <?php
  2.  
  3. function fetch_server_info($ip, $port){
  4. $socket = fsockopen($ip, $port, $errno, $errstr, 0.5);
  5.  
  6. if ($socket === false){
  7. return false;
  8. }
  9. fwrite($socket, "QUERY_JSON\n");
  10.  
  11. $responce = stream_get_contents($socket);
  12.  
  13. return json_decode($responce, true);
  14. }
  15.  
  16. ?>


mcconfig.php
  1. <?php
  2.  
  3. $config['server']['ip'] = 'localhost';
  4. $config['server']['port'] = '25565';
  5.  
  6. ?>



Notice: Undefined variable: config in C:\Program Files\xampp\htdocs\Index.php on line 5

Notice: Undefined variable: config in C:\Program Files\xampp\htdocs\Index.php on line 5

Warning: fsockopen() [function.fsockopen]: unable to connect to :0 (Failed to parse address "") in C:\Program Files\xampp\htdocs\mcInfo.php on line 4

Notice: Undefined variable: config in C:\Program Files\xampp\htdocs\Index.php on line 12
Status

Notice: Undefined variable: config in C:\Program Files\xampp\htdocs\Index.php on line 16
Status: Wy�aczony

Ten post edytował mikoz55 15.05.2012, 16:50:54
Go to the top of the page
+Quote Post
2 Stron V   1 2 >  
Start new topic
Odpowiedzi (1 - 19)
markonix
post
Post #2





Grupa: Zarejestrowani
Postów: 2 707
Pomógł: 290
Dołączył: 16.12.2008
Skąd: Śląsk

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


Nie ma zadeklarowanej zmiennej $config (dokładniej to tablicy).
Przecież wystarczy .. przeczytać te błędy.

Ten post edytował markonix 15.05.2012, 17:00:55


--------------------
Go to the top of the page
+Quote Post
-Gość-
post
Post #3





Goście







W tym rzecz że ja się kompletnie na tym nie znam, prosił bym żeby dał mi pan to wklejone sad.gif

Poda mi ktoś prawidłowy kod?
Go to the top of the page
+Quote Post
Tajgeer
post
Post #4





Grupa: Zarejestrowani
Postów: 290
Pomógł: 48
Dołączył: 11.05.2008
Skąd: Kielce

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


Dołącz mcconfig.php do pliku index.php.
Go to the top of the page
+Quote Post
binprogrammer
post
Post #5





Grupa: Zarejestrowani
Postów: 249
Pomógł: 8
Dołączył: 10.08.2011
Skąd: Bełchatów

Ostrzeżenie: (10%)
X----


wystarczy czytać po angielsku ;p zaincluduj mcconfig w index jak mówił poprzednik
Go to the top of the page
+Quote Post
-Gość-
post
Post #6





Goście







index.php
  1. <?php
  2.  
  3. $config['server']['ip'] = 'localhost';
  4. $config['server']['port'] = '25565';
  5.  
  6. $info = fetch_server_info($config['server']['ip'], $config['server']['posrt']);
  7.  
  8. ?>
  9. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  10. <html xmlns="http://w3.org/1999/xhtml">
  11. <head>
  12. <meta http-equiv="Content-Type" content="text/html; charset=utf-8 /"
  13. <title><?php echo $config['server']['ip']; ?> Status</title>
  14. </head>
  15. <body>
  16. <div>
  17. <hl><?php echo $config['server']['ip']; ?></hl>
  18. <?php
  19.  
  20. if ($info === false){
  21. ?>
  22. <p>
  23. Status: Wyłaczony
  24. </p>
  25. <?php
  26. }else{
  27. ?>
  28. <p>
  29. Status: Włączony
  30. </p>
  31. <p>
  32. Sloty <?php echo $info['playerCount']; ?> / <?php echo $info['maxplayers']; ?>
  33. </p>
  34. <p>
  35. Gracze: <?php echo implode(', ', $info['playerList']); ?>
  36. </p>
  37. <?php
  38.  
  39. }
  40.  
  41. ?>
  42. </div>
  43. </body>
  44. </html>


i tam taki błąd co zrobić ? Fatal error: Call to undefined function fetch_server_info() in C:\Program Files\xampp\htdocs\Index.php on line 6
Go to the top of the page
+Quote Post
Tajgeer
post
Post #7





Grupa: Zarejestrowani
Postów: 290
Pomógł: 48
Dołączył: 11.05.2008
Skąd: Kielce

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


Czy którykolwiek z nas napisał, że masz usunąć dołączanie pliku mcInfo.php?

Ten post edytował Tajgeer 15.05.2012, 18:44:07
Go to the top of the page
+Quote Post
-Gość-
post
Post #8





Goście







Zrobiłem tak i jest

  1. <?php
  2.  
  3. include('mcinfo.php');
  4.  
  5. $info = fetch_server_info($config['server']['ip'], $config['server']['posrt']);
  6.  
  7. $config['server']['ip'] = 'localhost';
  8. $config['server']['port'] = '25565';
  9.  
  10. ?>
  11. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  12. <html xmlns="http://w3.org/1999/xhtml">
  13. <head>
  14. <meta http-equiv="Content-Type" content="text/html; charset=utf-8 /"
  15. <title><?php echo $config['server']['ip']; ?> Status</title>
  16. </head>
  17. <body>
  18. <div>
  19. <hl><?php echo $config['server']['ip']; ?></hl>
  20. <?php
  21.  
  22. if ($info === false){
  23. ?>
  24. <p>
  25. Status: Wyłaczony
  26. </p>
  27. <?php
  28. }else{
  29. ?>
  30. <p>
  31. Status: Włączony
  32. </p>
  33. <p>
  34. Sloty <?php echo $info['playerCount']; ?> / <?php echo $info['maxplayers']; ?>
  35. </p>
  36. <p>
  37. Gracze: <?php echo implode(', ', $info['playerList']); ?>
  38. </p>
  39. <?php
  40.  
  41. }
  42.  
  43. ?>
  44. </div>
  45. </body>
  46. </html>


Parse error: syntax error, unexpected T_STRING, expecting '(' in C:\Program Files\xampp\htdocs\mcInfo.php on line 3 znów coś sad.gif

Mógł by ktoś to poprawić ? Proszę.
Go to the top of the page
+Quote Post
markonix
post
Post #9





Grupa: Zarejestrowani
Postów: 2 707
Pomógł: 290
Dołączył: 16.12.2008
Skąd: Śląsk

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


Czy znasz chociaż podstawy języka angielskiego?


--------------------
Go to the top of the page
+Quote Post
-Gość-
post
Post #10





Goście







Tak, ale nie rozumiem tego.

$info = fetch_server_info $config['server']['ip'], $config['server']['posrt'];

zrobiłem tak bez "("

i teraz coś innego

Parse error: syntax error, unexpected T_VARIABLE in C:\Program Files\xampp\htdocs\Index.php on line 5

co teraz ?

Ten post edytował mikoz55 16.05.2012, 14:40:19
Go to the top of the page
+Quote Post
markonix
post
Post #11





Grupa: Zarejestrowani
Postów: 2 707
Pomógł: 290
Dołączył: 16.12.2008
Skąd: Śląsk

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


Jeżeli byś przeczytał ten błąd to byś nie umieszczał w ostatnim poście kodu, który umieściłeś.

Ten post edytował markonix 16.05.2012, 14:38:56


--------------------
Go to the top of the page
+Quote Post
-Gość-
post
Post #12





Goście







Mógł by pan podać te linijki prawidłowo ?
Go to the top of the page
+Quote Post
markonix
post
Post #13





Grupa: Zarejestrowani
Postów: 2 707
Pomógł: 290
Dołączył: 16.12.2008
Skąd: Śląsk

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


  1. $info = fetch_server_info ($config['server']['ip'], $config['server']['posrt']);

fetch_server_info to funkcja, a jej argumenty podaje się w nawiasie okrągłym.


--------------------
Go to the top of the page
+Quote Post
-Gość-
post
Post #14





Goście







  1. $info = fetch_server_info ($config('server')('ip'), $config('server')('posrt'));


Tak?

Parse error: syntax error, unexpected '(' in C:\Program Files\xampp\htdocs\Index.php on line 5
Go to the top of the page
+Quote Post
markonix
post
Post #15





Grupa: Zarejestrowani
Postów: 2 707
Pomógł: 290
Dołączył: 16.12.2008
Skąd: Śląsk

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


Zaraz mnie strzeli....
Skopiować nie potrafisz nawet?


--------------------
Go to the top of the page
+Quote Post
-Gość-
post
Post #16





Goście







Chciałbym to rozumieć, ale jeszcze nie umiem php, i nie wiem co źle robię, chciał bym żeby Pan podał mi prawidłową część tego kodu.
Go to the top of the page
+Quote Post
k_@_m_i_l
post
Post #17





Grupa: Zarejestrowani
Postów: 349
Pomógł: 72
Dołączył: 22.01.2008
Skąd: Wadowice/Oświęcim

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


Cytat(markonix @ 16.05.2012, 15:46:51 ) *
  1. $info = fetch_server_info ($config['server']['ip'], $config['server']['posrt']);

fetch_server_info to funkcja, a jej argumenty podaje się w nawiasie okrągłym.



No przecież Ci podał !
Skopiuj to co masz powyżej, wklej i będzie działać.


--------------------
"PHP to człowiek. MySQL to również człowiek."
Go to the top of the page
+Quote Post
-Gość-
post
Post #18





Goście







Zrobiłem to dawno, zmieniłem w mcinfo.php 1 rzecz,

i wyskoczył kolejny błąd

Parse error: syntax error, unexpected T_STRING in C:\Program Files\xampp\htdocs\mcInfo.php on line 4

  1. $socket fsockopen($ip, $port, $errno, $errstr, 0.5);
Go to the top of the page
+Quote Post
hind
post
Post #19





Grupa: Zarejestrowani
Postów: 142
Pomógł: 24
Dołączył: 30.03.2009
Skąd: Rokitno Szlacheckie

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


Ja się tylko podepne
czy $config['server']['posrt'] nie powinno być $config['server']['port'] (literówka, która w tym kontekście bardziej pasuje)
Go to the top of the page
+Quote Post
markonix
post
Post #20





Grupa: Zarejestrowani
Postów: 2 707
Pomógł: 290
Dołączył: 16.12.2008
Skąd: Śląsk

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


Gdzie znikł znak równości?


--------------------
Go to the top of the page
+Quote Post

2 Stron V   1 2 >
Closed TopicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 21.08.2025 - 06:08