title: curl: can't fetch rss from website because of CloudFlare
body: <p>I'm notable to connect this site <a href="http://www.youm7.com/newtkarirrss.asp" rel="noreferrer">http://www.youm7.com/newtkarirrss.asp</a> using curl on the server</p>
  
  <p>But i can access it from <strong>localhost</strong> with out any problem</p>
  
  <p>Here is the test</p>
  
  <p><a href="http://www.tjreb.com/xml_grabber.php?feed=http://www.youm7.com/newtkarirrss.asp&amp;stack=1" rel="noreferrer">http://www.tjreb.com/xml_grabber.php?feed=http://www.youm7.com/newtkarirrss.asp&amp;stack=1</a></p>
  
  <p>Try The CNN rss feed</p>
  
  <p><a href="http://www.tjreb.com/xml_grabber.php?feed=http://rss.cnn.com/rss/edition_meast.rss&amp;stack=0" rel="noreferrer">http://www.tjreb.com/xml_grabber.php?feed=http://rss.cnn.com/rss/edition_meast.rss&amp;stack=0</a></p>
  
  <p>How can i bypass this error</p>
  
  <p>Here is my source code</p>
  
  <pre><code>&lt;?php
    class xml_grabber
          {
              private $xml_file       = '' ;
              private $xml_link       = '' ;
              private $xml_dom        = '' ;
              private $xml_type       = '' ;
              private $xml_content    = '' ;
              private $xml_errors     = array() ;
              public  $xml_stack      = 0  ;
  
              public function __construct($link_file_com = '')
                     {
                         if(!$link_file_com)
                              {
                                $this-&gt;xml_errors['construct'] = 'No Xml In Construct' ;
                                return false;
                              }
                         elseif(!function_exists('simplexml_load_file') || !function_exists('simplexml_load_string') || !function_exists('simplexml_import_dom'))
                              {
                                $this-&gt;xml_errors['functions'] = 'simple xml function not exists' ;
                                return false;
                              }
                         else
                              {
                               $this-&gt;set_xml($link_file_com) ;
                              }
                        // ini_set('memory_limit', '100M');
                     }
  
               public function set_xml($xml)
                     {
                        if(isset($xml{3}))
                          {
                             if(file_exists($xml))
                                {
                                  $this-&gt;xml_type = 1 ;
                                  $this-&gt;xml_file = $xml ;
                                }
                            elseif(filter_var($xml, FILTER_VALIDATE_URL))
                                {
                                  $this-&gt;xml_type = 2 ;
                                  $this-&gt;xml_link = $xml ;
                                }
                            else
                                {
                                  $this-&gt;xml_type = 3 ;
                                  $this-&gt;xml_dom  = $xml ;
                                }
                          }
                        else
                          {
                            $this-&gt;xml_type = '' ;
                          }
                     }
  
               public function get_xml()
                     {
                        if($this-&gt;xml_type == '')
                              {
                                return false ;
                              }
                        elseif($this-&gt;xml_type == 1)
                              {
                                return $this-&gt;xml_file ;
                              }
                        elseif($this-&gt;xml_type == 2)
                              {
                                return $this-&gt;xml_link ;
                              }
                        elseif($this-&gt;xml_type == 3)
                              {
                                return $this-&gt;xml_dom ;
                              }
                     }
  
               public function set_columns($new_columns= array())
                     {
                        return $this-&gt;xml_columns = $new_columns ;
                     }
               public function get_columns()
                     {
                       return $this-&gt;xml_columns ;
                     }
  
               public function load()
                     {
                       if($this-&gt;xml_type == '')
                              {
                                $this-&gt;xml_errors['loader'] = 'Unknown XML type' ;
                                return false;
                              }
                        elseif($this-&gt;xml_type == 1)
                              {
                                $dom = simplexml_load_file($this-&gt;xml_file,null, LIBXML_NOCDATA) ;
                                $this-&gt;xml_content = $dom ;
                              }
                        elseif($this-&gt;xml_type == 2)
                              {
                                 $con = $this-&gt;connect($this-&gt;xml_link);
                                 if($this-&gt;xml_stack == 1)
                                      {
                                         echo $con; die();
                                      }       
                                 $this-&gt;xml_content = simplexml_load_string($con,null, LIBXML_NOCDATA) ;
                              }
                        elseif($this-&gt;xml_type == 3)
                              {
                                return $this-&gt;xml_dom ;
                              }
                     }
  
               public function fetch($return = 'array')
                      {
                          if($this-&gt;xml_content != '')
                              {
                                 $rss_feed = $this-&gt;xml_content ;
  
                                 $rss_title = (string) $rss_feed-&gt;channel-&gt;title ;
                                 $rss_link  = (string) $rss_feed-&gt;channel-&gt;link  ;
                                 $rss_cat   = (string) $rss_feed-&gt;channel-&gt;category  ;
                                 $rss_image = (string) $rss_feed-&gt;channel-&gt;image-&gt;url  ;
  
                                 $rss_summary =
                                              array
                                              (
                                                'info' =&gt;
                                                          array(
                                                                  'title'=&gt;$rss_title ,
                                                                  'link'=&gt;$rss_link ,
                                                                  'cat'=&gt;$rss_cat ,
                                                                  'image'=&gt;$rss_image
                                                                  ) ,
                                                'item' =&gt;  array()
  
                                              ) ;
  
  
  
                                 foreach($rss_feed-&gt;channel-&gt;item as $item)
                                         {
  
                                             if($item-&gt;enclosure &amp;&amp; $item-&gt;enclosure-&gt;attributes())
                                                  {
                                                      $image0 = $item-&gt;enclosure-&gt;attributes() ;
                                                      $image_url = $image0 ['url'] ;
                                                  }
  
                                            $rss_summary['item'][] =
                                                                      array(
                                                                          'title' =&gt; (string) $item-&gt;title ,
                                                                          'description' =&gt; (string) $item-&gt;description ,
                                                                          'link' =&gt; (string) $item-&gt;link ,
                                                                          'date' =&gt; (string) $item-&gt;pubDate ,
                                                                          'image' =&gt; (string) $item-&gt;image ,
                                                                          'image2' =&gt;  (string) $image0
                                                                      ) ;
                                         }
  
                                  if($return == 'json')
                                         {
                                           return json_encode($rss_summary) ;
                                         }
                                  elseif($return == 'serialize')
                                         {
                                           return serialize($rss_summary) ;
                                         }
                                  elseif($return == 'xml')
                                         {
                                           return xml_encode($rss_summary) ;
                                         }
                                  else
                                         {
                                           return $rss_summary ;
                                         }
  
                              }
                          else
                              {
                                $this-&gt;xml_errors['fetch'] = 'No Xml Content' ;
                              }
                      }
  
               protected function connect($link)
                      {
                        if(!filter_var($link, FILTER_VALIDATE_URL))
                                {
                                  $this-&gt;xml_errors['connect'] = 'Not Vaild Link To Get data' ;
                                  return false ;
                                }
                        if(function_exists('curl_init'))
                             {
                               $cu = curl_init();
                               curl_setopt($cu, CURLOPT_URL, $link);
                               curl_setopt($cu, CURLOPT_SSL_VERIFYPEER, false);
                               curl_setopt($cu, CURLOPT_SSL_VERIFYHOST, false);
                               //curl_setopt($cu, CURLOPT_REFERER, "http://www.tjreb.com");
                               //curl_setopt($cu, CURLOPT_HEADER, true);
                   //curl_setopt($cu, CURLOPT_FOLLOWLOCATION, false);
                   curl_setopt($cu, CURLOPT_RETURNTRANSFER, TRUE);
                               $co = curl_exec($cu) ;
                                 if($co)
                                      {
                                          $con = $co ;
                                      }
                                 else
                                      {
                                        $this-&gt;xml_errors['connect'] = 'No Result From Curl' ;
                                        $this-&gt;xml_errors['curl']  = curl_error($cu);
                                      }
                                curl_close($cu) ;
                                return $con ;
                             }
  
                      if(!$con and function_exists('ini_get'))
                          {
  
                               $url_fopen = ini_get('allow_url_fopen') ;
  
                               if($url_fopen == 0)
                                  {
                                     if(function_exists('ini_set'))
                                          {
                                            ini_set('allow_url_fopen', 1) ;
                                          }
                                     $check_fopen = 1 ;
                                  }
                               else
                                  {
                                     $check_fopen = 0 ;
                                  }
  
                               if($check_fopen == 1)
                                  {
                                    $url_fopen = ini_get('allow_url_fopen') ;
                                  }
  
                               if($url_fopen == 1)
                                  {
  
                                    if(function_exists('file_get_contents') and !$con)
                                     {
                                          $con = @file_get_contents($link) ;
                                          if($con)
                                              {
                                                return $con ;
                                              }
                                         else
                                              {
                                                $this-&gt;xml_errors['connect'] = 'No Result From file_get_contents' ;
                                              }
                                     }
  
                                elseif(function_exists('readfile') and !$con)
                                     {
                                          $con = @readfile($link);
                                          if($con)
                                              {
                                                return $con ;
                                              }
                                         else
                                              {
                                                $this-&gt;xml_errors['connect'] = 'No Result From readfile' ;
                                              }
                                     }
  
                                elseif(function_exists('file') and !$con)
                                     {
                                          $con = @file($link)  ;
                                          if($con)
                                              {
                                                return  $con ;
                                              }
                                         else
                                              {
                                                $this-&gt;xml_errors['connect'] = 'No Result From file' ;
                                              }
                                     }
  
                                  }
                          }
  
                        if(!$con)
                             {
                               $this-&gt;xml_errors['connect'] = 'Curl And Allow Url Fopen Disabled On Server' ;
                               return false ;
                             }
                      }
  
               public function get_error()
                      {
                         return $this-&gt;xml_errors ;
                      }
  
          }
  
  
  if(isset($_GET['feed']))
      {
         $url = addslashes($_GET['feed']) ;
      }
  else
      {
         $url = 'http://rss.cnn.com/rss/edition_meast.rss' ;
      }
  
  $fetch = $_GET['fetch'] ;
  $stack = $_GET['stack'] ;
  
  $xml = new xml_grabber($url) ;
  
  /*
   http://www.youm7.com/new3agelrss.asp
   http://www.youm7.com/newtkarirrss.asp
   http://www.almasryalyoum.com/rss_feed_term/223241/rss.xml
   http://gdata.youtube.com/feeds/api/playlists/18A7E36C33EF4B5D?v=2
   http://rss.cnn.com/rss/edition_meast.rss
   https://www.facebook.com/feeds/page.php?format=atom10&amp;id=40796308305
   https://www.facebook.com/feeds/page.php?format=rss20&amp;id=40796308305
   http://www.fwasl.com/feed
   https://www.facebook.com/feeds/page.php?format=atom10&amp;id=378156838895039
   */
  
  if(isset($stack))
  {
    $xml -&gt; xml_stack = intval($stack) ; 
  }   
  
  
  $res    = $xml -&gt; load()    ;
  
  $result = $xml -&gt; fetch($fetch)   ;
  
  if($result)
      {
        print_r ( $result ) ;
      }
  else
      {
        print_r ( $xml-&gt;get_error() ) ;
      }
  
  ?&gt;
  </code></pre>