title: file_get_contents through tor
body: <p>So, I was looking for away to find a title of a page using php. After researching for 5 seconds, I found right here, the answer:</p>
  
  <pre><code>        function get_title($url){
          $str = file_get_contents($url);
          if(strlen($str)&gt;0){
            $str = trim(preg_replace('/\s+/', ' ', $str)); 
            preg_match("/\&lt;title\&gt;(.*)\&lt;\/title\&gt;/i",$str,$title); 
            return $title[1];
          }
        }
  </code></pre>
  
  <p>But I need that through Tor Proxy, so 5 seconds research on this sites and your wisdom, I found:</p>
  
  <pre><code>        $aContext = array(
          'http' =&gt; array(
              'proxy' =&gt; 'proxy:port',
              'request_fulluri' =&gt; true,
          )
      );
  
      $cxContext = stream_context_create($aContext);
  </code></pre>
  
  <p>Puting it all together, I did this:</p>
  
  <pre><code>        $aContext = array(
          'http' =&gt; array(
              'proxy' =&gt; '127.0.0.1:9150',
              'request_fulluri' =&gt; true,
          )
      );
  
      $cxContext = stream_context_create($aContext);
  
      function get_title($url){
          global $cxContext;
          $str = file_get_contents($url, False, $cxContext);
  
          if(strlen($str)&gt;0){
            $str = trim(preg_replace('/\s+/', ' ', $str));
            preg_match("/\&lt;title\&gt;(.*)\&lt;\/title\&gt;/i",$str,$title); 
            return $title[1];
          }
        }
  
  echo get_title('http://' . $theonionurl);
  </code></pre>
  
  <p>But, that's not working. the log shows:</p>
  
  <blockquote>
    <p>PHP Warning:  file_get_contents(<a href="http://the_onion_address_to_check.onion" rel="nofollow noreferrer">http://the_onion_address_to_check.onion</a>): failed to open stream: Connection refused in /var/www/html/mychecker.php on line 44, referer: <a href="http://my_onion_address.onion/mychecker.php" rel="nofollow noreferrer">http://my_onion_address.onion/mychecker.php</a></p>
  </blockquote>
  
  <p>I changed the port to 9050, still not working.</p>
  
  <p>What am I doing wrong ???</p>
  
  <p>(obviously, I checked, the urls to check are valid and accessible through tor browser)</p>