Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]API
szymon202
post 19.03.2015, 21:23:18
Post #1





Grupa: Zarejestrowani
Postów: 152
Pomógł: 0
Dołączył: 13.08.2013

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


Kod do odbierania statusu:
  1. <?php
  2. if (isset($_POST['check_code']) && isset($_POST['code'])) {
  3.  
  4. $code = $_POST['code'];
  5.  
  6. $api = @file_get_contents("http://xxx.net/api/api.php?code=$code");
  7.  
  8. if(isset($api)) {
  9. $api = json_decode($api);
  10.  
  11. if(isset($api->error) && $api->error) {
  12. echo $api->error;
  13. } else {
  14. if($api->status=="OK") {
  15. echo 'Poprawny kod. Doładowuję '.$api->cash.' zł';
  16. } else {
  17. echo 'Błędny kod';
  18. }
  19. }
  20. } else {
  21. echo 'Brak połączenia z API';
  22. }
  23. }
  24.  
  25. ?>
  26.  
  27. <form method="post">
  28. <h4>Kod SMS</h4>
  29. <input class="form-control" type="text" name="code" class="text" size="15" value="" /><br>
  30. <input name="check_code" type="submit" value="Sprawdz" />
  31. </form>


Kod API:
  1. <?php
  2. $settings['userid'] = 1;
  3. $settings['serviceid'] = 1;
  4. $code = $_GET['code'];
  5.  
  6. $microsms[] = array("netto" => 0.50,"number" => 7055,"product" => "kawamintai");
  7. $handle = fopen("http://xxx.xxx.xxx/check_multi.php?userid=" . $settings['userid'] . "&code=" . $code . '&serviceid=' . $settings['serviceid'], 'r');
  8. $check = fgetcsv($handle, 1024);
  9. fclose($handle);
  10.  
  11. header("Content-Type:application/json");
  12. if(!empty($_GET['code'])) {
  13. $code=$_GET['code'];
  14. $ok = $check[0] == 1;
  15. if($code == $ok) {
  16. deliver_response("OK","1.23","OK_CODE");
  17. } else {
  18. deliver_response("FAIL",NULL,"BAD_CODE");
  19. }
  20. }
  21.  
  22. function deliver_response($status, $cash, $error) {
  23. header("HTTP/1.1 $status $cash");
  24.  
  25. $response['status']=$status;
  26. $response['cash']=$cash;
  27. $response['error']=$error;
  28.  
  29. $json_response=json_encode($response);
  30. echo $json_response;
  31. }
  32. ?>


Za każdym razem w formularzu zwraca błędny kod, a wchodząc przez link z API jest dobrze i zwraca OK.
Dodam, że kod zużywa, ale pisze Błędny kod.

@ref

Ten post edytował szymon202 18.03.2015, 17:10:36
Go to the top of the page
+Quote Post
Aqu
post 19.03.2015, 21:36:07
Post #2





Grupa: Zarejestrowani
Postów: 279
Pomógł: 58
Dołączył: 14.07.2012

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


  1. $api = json_decode($api);
  2. var_dump($api);
  3.  


Zobacz co tam dostajesz, bo kod wydaje się poprawny.
Usuń też małpę sprzed file_get_, jeśli postawiłeś to na jakimś darmowym serwerze, to możesz mieć wyłączoną tą funkcję.
Go to the top of the page
+Quote Post
szymon202
post 19.03.2015, 21:54:58
Post #3





Grupa: Zarejestrowani
Postów: 152
Pomógł: 0
Dołączył: 13.08.2013

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


Cytat(Aqu @ 19.03.2015, 21:36:07 ) *
  1. $api = json_decode($api);
  2. var_dump($api);
  3.  


Zobacz co tam dostajesz, bo kod wydaje się poprawny.
Usuń też małpę sprzed file_get_, jeśli postawiłeś to na jakimś darmowym serwerze, to możesz mieć wyłączoną tą funkcję.


NULL
Hosting to VPS.

Po włączeniu flag błędów.

Linia 17:
  1. if($api->status=="OK") {
Go to the top of the page
+Quote Post
Aqu
post 19.03.2015, 22:05:46
Post #4





Grupa: Zarejestrowani
Postów: 279
Pomógł: 58
Dołączył: 14.07.2012

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


  1. $api = file_get_contents("http://xxx.net/api/api.php?code=$code");
  2. var_dump($api);
  3.  

Wywal małpę i zobacz co jest pobierane z tej strony.
Go to the top of the page
+Quote Post
szymon202
post 19.03.2015, 22:08:11
Post #5





Grupa: Zarejestrowani
Postów: 152
Pomógł: 0
Dołączył: 13.08.2013

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


Cytat(Aqu @ 19.03.2015, 22:05:46 ) *
  1. $api = file_get_contents("http://xxx.net/api/api.php?code=$code");
  2. var_dump($api);
  3.  

Wywal małpę i zobacz co jest pobierane z tej strony.


string(0) ""

Warning: file_get_contents(http://xxx.net/api/api.php?code=12345678): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in /home/admin/web/xxxi.net/public_html/api.php on line 9

Ten post edytował szymon202 19.03.2015, 22:15:31
Go to the top of the page
+Quote Post
Aqu
post 19.03.2015, 22:57:53
Post #6





Grupa: Zarejestrowani
Postów: 279
Pomógł: 58
Dołączył: 14.07.2012

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


I nie widzisz o co chodzi? Serio chcesz pobrać jakieś dane ze strony xxx.net?
Go to the top of the page
+Quote Post
szymon202
post 20.03.2015, 19:48:04
Post #7





Grupa: Zarejestrowani
Postów: 152
Pomógł: 0
Dołączył: 13.08.2013

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


Cytat(Aqu @ 19.03.2015, 22:57:53 ) *
I nie widzisz o co chodzi? Serio chcesz pobrać jakieś dane ze strony xxx.net?

W moim kodzie strona jest poprawna. Nie chcę robić tutaj reklam.
// Nie zauważyłem. Jak wejdę na PC to zobaczę

Jednak w moim kodzie adres jest poprawny.

Ten post edytował szymon202 20.03.2015, 15:07:07
Go to the top of the page
+Quote Post
Aqu
post 20.03.2015, 19:58:45
Post #8





Grupa: Zarejestrowani
Postów: 279
Pomógł: 58
Dołączył: 14.07.2012

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


Hm, może spróbuj tego: http://stackoverflow.com/questions/1052474...ks-in-a-browser

  1. $opts = array('http'=>array('header' => "User-Agent:MyAgent/1.0\r\n"));
  2. $context = stream_context_create($opts);
  3. $header = file_get_contents('https://www.example.com',false,$context);
Go to the top of the page
+Quote Post
szymon202
post 20.03.2015, 20:04:57
Post #9





Grupa: Zarejestrowani
Postów: 152
Pomógł: 0
Dołączył: 13.08.2013

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


Cytat(Aqu @ 20.03.2015, 19:58:45 ) *
Hm, może spróbuj tego: http://stackoverflow.com/questions/1052474...ks-in-a-browser

  1. $opts = array('http'=>array('header' => "User-Agent:MyAgent/1.0\r\n"));
  2. $context = stream_context_create($opts);
  3. $header = file_get_contents('https://www.example.com',false,$context);


Niestety, ale nadal to samo.

Błąd tutaj:
$api = file_get_contents("http://mojastrona.net/api/api.php?code=$code", false, $context);
Warning: file_get_contents(http://mojastrone.net/api/api.php?code=b3r9i9o4): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in /home/admin/web/mojastrona.net/public_html/api.php on line 11

Ten post edytował szymon202 20.03.2015, 20:13:01
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 13.06.2025 - 00:40