Computer >> Computer tutorials >  >> Programming >> PHP

PHP https://


Introduction

The https:// and https:// wrappers enable read only access to resources and files through HTTP procol. When handling virtual name-based host, host: header is also sent along with user_agent (if configured in php.ini)

The http header information is stored in $http_response_header variable. These headers have to be processed to know URL of resource where the document comes from with the help of from: header.

HTTPS is supported only if openssl extension is enabled in php.ini settings. Both HTTP and HTTPS connections are read only and don't support writing or copying files.

Usage

Representation of file name in different possible ways is as follows −

https://localhost
https://example.com
https://localhost?name='Ram'&age=20
https://example.com
https://username:[email protected]

Example

<?php
$url = 'https://www.tutorialspoint.com/php7/php7_closure_call.htm';
if (!$fp = fopen($url, 'r')) {
   trigger_error("Unable to open URL ($url)", E_USER_ERROR);
}
$meta = stream_get_meta_data($fp);
print_r($meta);
?>

Above script reads header metadata from http URL

Array(
   [crypto] => Array(
      [protocol] => TLSv1.2
      [cipher_name] => ECDHE-RSA-AES128-GCM-SHA256
      [cipher_bits] => 128
      [cipher_version] => TLSv1/SSLv3
   )

   [timed_out] =>
   [blocked] => 1
   [eof] =>
   [wrapper_data] => Array(
      [0] => HTTP/1.0 200 OK
      [1] => Age: 1310067
      [2] => Cache-Control: max-age=2592000
      [3] => Content-Type: text/html; charset=UTF-8
      [4] => Date: Mon, 14 Sep 2020 17:15:36 GMT
      [5] => Expires: Wed, 14 Oct 2020 17:15:36 GMT
      [6] => Last-Modified: Sun, 30 Aug 2020 13:21:09 GMT
      [7] => Server: ECS (nag/99AA)
      [8] => Strict-Transport-Security: max-age=63072000; includeSubdomains
      [9] => Vary: Accept-Encoding
      [10] => X-Cache: HIT
      [11] => X-Content-Type-Options: nosniff
      [12] => X-Frame-Options: SAMEORIGIN
      [13] => X-XSS-Protection: 1; mode=block
      [14] => Content-Length: 24102
      [15] => Connection: close
   )
   [wrapper_type] => http
   [stream_type] => tcp_socket/ssl
   [mode] => r
   [unread_bytes] => 0
   [seekable] =>
   [uri] => https://www.tutorialspoint.com/php7/php7_closure_call.htm
)