Я хочу проверить, имеет ли домен действительный сертификат SSL.
В linux bash я запускаю:
Код: Выделить всё
curl https://google.com -vI
Код: Выделить всё
--- (more text before...)
* Server certificate:
* subject: CN=*.google.com
* start date: Oct 7 08:23:38 2024 GMT
* expire date: Dec 30 08:23:37 2024 GMT
* subjectAltName: host "google.com" matched cert's "google.com"
* issuer: C=US; O=Google Trust Services; CN=WR2
* SSL certificate verify ok.
--- (more text after...)
Я хочу сделать то же самое в PHP с помощью этого кода:
Код: Выделить всё
$url = "https://google.com/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$RAWresponse = curl_exec($ch);
dd($RAWresponse);
Код: Выделить всё
HTTP/1.1 301 Moved Permanently
Location: https://www.google.com/
Content-Type: text/html; charset=UTF-8
Content-Security-Policy-Report-Only: object-src 'none';base-uri 'self';script-src 'nonce-Jfg7vMsTbRraHV67JGhJ2w' 'strict-dynamic' 'report-sample' 'unsafe-eval'
Date: Fri, 08 Nov 2024 00:47:17 GMT
Expires: Sun, 08 Dec 2024 00:47:17 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 220
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
301 Moved
301 Moved
The document has moved
[url=https://www.google.com/]here[/url].
Итак, если я добавлю в PHP-скрипт:
Код: Выделить всё
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
Код: Выделить всё
"""
HTTP/2 301
location: https://www.google.com/
content-type: text/html; charset=UTF-8
content-security-policy-report-only: object-src 'none';base-uri 'self';script-src 'nonce-ZkddZzdxc8LNgXdPiViKFA' 'strict-dynamic' 'report-sample' 'unsafe-eval'
date: Fri, 08 Nov 2024 13:48:16 GMT
expires: Sun, 08 Dec 2024 13:48:16 GMT
cache-control: public, max-age=2592000
server: gws
content-length: 220
x-xss-protection: 0
x-frame-options: SAMEORIGIN
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
HTTP/2 200
expires: -1
cache-control: private, max-age=0
content-type: text/html; charset=ISO-8859-1
content-security-policy-report-only: object-src 'none';base-uri 'self';script-src 'nonce-gfxfoZ5jJWu8xejGzBPTqQ' 'strict-dynamic' 'report-sample' 'unsafe-eval'
accept-ch: Sec-CH-Prefers-Color-Scheme
p3p: CP="This is not a P3P policy! See g.co/p3phelp for more info."
server: gws
x-xss-protection: 0
x-frame-options: SAMEORIGIN
set-cookie: AEC=AVYB7coF4DLJ8Q8OWyH_By8SSs0qOmFJeFhjBzJDUuq2Dc2FCfLwiOXh; expires=Wed, 07-May-2025 13:48:16 GMT; path=/; domain=.google.com; Secure; HttpOnly; S
set-cookie: NID=519=hlZvdatNc7eC6S1ziob5sEq8f4pLZjXKg5J21LEwLS_-7a9WDktrNX_qzepsvbnyYO54OjrhpwAqc4KTc1fxscVPX99NIzxuPazPXmJTEBizke-pFD-p-4yS4lhWLggWTYp1wj9yxp8d
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
accept-ranges: none
vary: Accept-Encoding
Подробнее здесь: [url]https://stackoverflow.com/questions/79168493/get-ssl-status-using-php-curl-vs-command-line-curl[/url]