Advertisement
ravel571

getInfo()

May 1st, 2013
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.64 KB | None | 0 0
  1. function getInfo()
  2. {
  3.  
  4.     $num = func_num_args();
  5.    
  6.     if (($num >= 1) AND ($num <= 2))
  7.     {
  8.        
  9.         $ch = curl_init();
  10.         curl_setopt($ch, CURLOPT_URL, func_get_arg(0));
  11.         curl_setopt($ch, CURLOPT_FAILONERROR, true);
  12.        
  13.         curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 5.1; rv:20.0) Gecko/20100101 Firefox/20.0");
  14.        
  15.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  16.         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  17.  
  18.         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);       
  19.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  20.         curl_setopt($ch, CURLOPT_TIMEOUT, 1);
  21.        
  22.         if ($num == 2)
  23.         {
  24.            
  25.             if (is_array(func_get_arg(1)))
  26.             {
  27.                
  28.                 $array = array();
  29.                
  30.                 foreach (func_get_arg(1) as $key => $val)
  31.                 {
  32.                    
  33.                     $array[] = $key."=".$val;
  34.                
  35.                 }
  36.                
  37.                 $postdata = implode("&", $array);
  38.                
  39.                 curl_setopt($ch, CURLOPT_POST, true);
  40.                 curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
  41.                
  42.             }
  43.             else
  44.             {
  45.                
  46.                 throw new Exception("2-ой аргумент не является массивом.");
  47.            
  48.             }
  49.            
  50.         }
  51.        
  52.         $data = curl_exec($ch);
  53.         $info = curl_getinfo($ch);
  54.         $info['data'] = $data;
  55.         curl_close($ch);
  56.        
  57.         return $info;
  58.    
  59.     }
  60.     else
  61.     {
  62.        
  63.         throw new Exception("Не верное количество аргументов.");
  64.    
  65.     }
  66.  
  67. }
  68.  
  69. /*example*/
  70.  
  71. try
  72. {
  73.     $array = array(
  74.     "username" => "test",
  75.     "password" => "test",
  76.     "thisPage" => "pispWhois",
  77.     "domain_name" => "example.com");
  78.    
  79.     echo "<pre>";
  80.     print_r(getInfo("https://www.webnames.ru:81/RegTimeSRS.pl", $array));
  81.     echo "</pre>";
  82.  
  83. }
  84. catch(Exception $e)
  85. {
  86.    
  87.     echo $e -> getMessage();
  88.    
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement