Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Sprawdzanie statusu strony.
Forum PHP.pl > Forum > Przedszkole
cykcykacz
Witam,
mam skrypt, który sprawdza jaki jest status adresu url.
  1. <?php
  2. /*
  3. Author: Keyvan Minoukadeh
  4.  
  5. This script demonstrates how you can set callback functions to receive the
  6. HTTP response as it comes through.
  7.  
  8. The advantage of this is that you don't have to wait for the whole response
  9. to be returned before you start work on it, you can monitor for certain
  10. headers, start outputting while you're receiving, etc..
  11.  
  12. I wasn't aware these cURL options were available in PHP, but noticed them being
  13. used by Alan Knowles: <http://docs.akbkhome.com/phpmole/phpmole_webfetch.html>
  14.  
  15. For more info on CURLOPT_HEADERFUNCTION and CURLOPT_WRITEFUNCTION see:
  16. <http://curl.haxx.se/libcurl/c/curl_easy_setopt.html>
  17. */
  18.  
  19. $ch = curl_init();
  20.  
  21. curl_setopt($ch, CURLOPT_URL, 'http://www.wp.pl/');
  22. // Set callback function for headers
  23. curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header');
  24.  
  25. // Set callback function for body
  26. curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'read_body');
  27.  
  28. curl_exec($ch);
  29.  
  30. if ($error = curl_error($ch)) {
  31. echo "Error: $error<br />\n";
  32. }
  33.  
  34. // define callback functions
  35.  
  36. // Notes from <http://curl.haxx.se/libcurl/c/curl_easy_setopt.html>:
  37. // Return the number of bytes actually written or return -1 to signal error to
  38. // the library (it will cause it to abort the transfer with a CURLE_WRITE_ERROR
  39. // return code). (Added in 7.7.2)
  40. function read_header($ch, $string)
  41. {
  42. //$length = strlen($string);
  43.  
  44. $sentence = str_replace('Header:', '', $string);
  45. //print_r(explode(" ",$sentence));
  46. // $x = (explode(" ",$sentence));
  47. $x= $sentence.'<br/>';
  48. echo $x;
  49. /*echo $x[0];
  50.   echo $x[1];
  51.   echo $x[2];
  52.   echo $x[3];
  53.   echo '<br/>';*/
  54.  
  55. //return $length;
  56. }
  57.  
  58. // Notes from <http://curl.haxx.se/libcurl/c/curl_easy_setopt.html>:
  59. // Return the number of bytes actually taken care of. If that amount differs
  60. // from the amount passed to your function, it'll signal an error to the library
  61. // and it will abort the transfer and return CURLE_WRITE_ERROR.
  62. function read_body($ch, $string)
  63. {
  64. $length = strlen($string);
  65. echo "Received $length bytes<br />\n";
  66. return $length;
  67. }
  68.  
  69. ?>


I jeśli wszystko jest dobrze dostaje stosowny komunikat:
Kod
HTTP/1.1 200 OK


Np: w skrypcie mam adres http://www.wp.pl/

Ale jak dałem adres google https://www.google.pl/ dostałem taki komunikat:
Kod
Error: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed


Dlaczego nie dostałem komunikatu HTTP/1.1 200 OK?

Jak uzyskać taki komunikat że adres działa poprawnie ale coś jest nie tak?
jaslanin
masz na serwerze zainstalowane rozszerzenie php_openssl, można ustawić w php.ini

inna opcja to ustawienie CURLOPT_SSL_VERIFYPEER, CURLOPT_SSL_VERIFYHOST na false
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.