다이렉트로 SSL 소켓에 접속하는 예제입니다.

<?php 
 // note that "ssl" is the protocol, NOT "https" 
 $hostname  = "ssl://your-secure-site.com"; 
 $port      = 443; 

 // create and configure the client socket 
 $fp = fsockopen($hostname, $port); 
 if ($fp) { 
    stream_set_timeout($fp, 30); 
     
  // send data (or build HTTPS headers similar to first example) 
  fwrite($fp, "your message goes here"); 
     
    // read response 
    while (!feof($fp)) { 
        echo fgets($fp, 128); 
    } 
     
    // close the socket 
    fclose($fp); 
 } 
 ?>

다음은 HTTP 소켓에 접속하는 방법입니다.

<?php 
 // don't need to specify http, it's the default protocol 
 $hostname = "www.google.com"; 
 $port     = 80; 

 // create and configure the client socket 
 $fp = fsockopen($hostname, $port); 
 // optional: $error_number, $error_string, $connect_timeout 

 if ($fp) { 

    // seconds to wait for i/o operations 
    stream_set_timeout($fp, 30);
     
    // send request headers 
    fwrite($fp, "GET / HTTP/1.1\r\n"); 
    fwrite($fp, "Host: $hostname\r\n");



    // Accept, User-Agent, Referer, etc.  
    fwrite($fp, $additional_headers); 

    fwrite($fp, "Connection: close\r\n"); 
     
    // read response 
  $response = ""; 
    while (!feof($fp)) { 
        $response .= fgets($fp, 128); 
    } 
  echo $response; 
     
    // close the socket 
    fclose($fp); 
 } 
 ?>

출처: http://arguments.callee.info/2009/02/10/http-https-and-ssl-via-php/

0 댓글