{"id":10327,"date":"2023-01-06T12:23:00","date_gmt":"2023-01-06T15:23:00","guid":{"rendered":"https:\/\/ajuda.locaweb.com.br\/?post_type=ht_kb&#038;p=10327"},"modified":"2023-01-30T11:20:30","modified_gmt":"2023-01-30T14:20:30","slug":"tudo-sobre-curl-hospedagem-de-sites","status":"publish","type":"ht_kb","link":"https:\/\/www.locaweb.com.br\/ajuda\/wiki\/tudo-sobre-curl-hospedagem-de-sites\/","title":{"rendered":"Tudo sobre cURL &#8211; Hospedagem de Sites"},"content":{"rendered":"    \t\t<div class=\"hts-messages hts-messages--info  hts-messages--withtitle hts-messages--withicon \"   >\r\n    \t\t\t<span class=\"hts-messages__title\"><b>Informa\u00e7\u00e3o!<\/b><\/span>    \t\t\t    \t\t\t\t<p>\r\n    \t\t\t\t\tVeja neste artigo como utilizar o Curl em seu servi\u00e7o de Hospedagem de Sites.    \t\t\t\t<\/p>\r\n    \t\t\t    \t\t\t\r\n    \t\t<\/div><!-- \/.ht-shortcodes-messages -->\r\n    \t\t\n<h6><span id=\"Buscando_uma_p.C3.A1gina_na_internet\" class=\"mw-headline\">Buscando uma p\u00e1gina na internet<\/span><\/h6>\n<pre>&lt;?php\r\n$ch = curl_init();\r\ncurl_setopt($ch, CURLOPT_URL, \"http:\/\/example.com\/\");\r\ncurl_setopt($ch, CURLOPT_HEADER, 0);\r\ncurl_exec($ch);\r\ncurl_close($ch);\r\n?&gt;<\/pre>\n<h6><span id=\"Alternativa_para_a_fun.C3.A7.C3.A3o_file_get_contents\" class=\"mw-headline\">Alternativa para a fun\u00e7\u00e3o file_get_contents<\/span><\/h6>\n<h6><span id=\"file_get_contents\" class=\"mw-headline\">file_get_contents<\/span><\/h6>\n<pre>&lt;?php\r\n$file_contents = file_get_contents('http:\/\/example.com\/');\r\n\r\n\/\/ display file\r\necho $file_contents;\r\n?&gt;<\/pre>\n<h6><span id=\"Aplicando_cURL\" class=\"mw-headline\">Aplicando cURL<\/span><\/h6>\n<pre>&lt;?php\r\n$ch = curl_init();\r\n$timeout = 5; \/\/ set to zero for no timeout\r\ncurl_setopt ($ch, CURLOPT_URL, 'http:\/\/example.com');\r\ncurl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);\r\ncurl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);\r\n$file_contents = curl_exec($ch);\r\ncurl_close($ch);\r\n\r\n\/\/ display file\r\necho $file_contents;\r\n?&gt;<\/pre>\n<h6><span id=\"Aplicando_cURL_.28alternativa.29\" class=\"mw-headline\">Aplicando cURL (alternativa)<\/span><\/h6>\n<pre>&lt;?php\r\n$site_url = 'http:\/\/example.com';\r\n$ch = curl_init();\r\n$timeout = 5; \/\/ set to zero for no timeout\r\ncurl_setopt ($ch, CURLOPT_URL, $site_url);\r\ncurl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);\r\n\r\nob_start();\r\ncurl_exec($ch);\r\ncurl_close($ch);\r\n$file_contents = ob_get_contents();\r\nob_end_clean();\r\n\r\necho $file_contents;\r\n?&gt;<\/pre>\n<h6><span class=\"mw-headline\">Obtendo dados bin\u00e1rios<\/span><\/h6>\n<h6><span id=\"Imagem\" class=\"mw-headline\">Imagem<\/span><\/h6>\n<ul>\n<li>Este script recupera uma imagem remota e atribui os dados binarios na vari\u00e1vel $image antes de emitir a imagem para o navegador:<\/li>\n<\/ul>\n<pre>&lt;?php\r\n$image_url = \"http:\/\/example.com\/image.jpg\";\r\n$ch = curl_init();\r\n$timeout = 0;\r\ncurl_setopt ($ch, CURLOPT_URL, $image_url);\r\ncurl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);\r\n\r\n\/\/ Getting binary data\r\ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);\r\ncurl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);\r\n\r\n$image = curl_exec($ch);\r\ncurl_close($ch);\r\n\r\n\/\/ output to browser\r\nheader(\"Content-type: image\/jpeg\");\r\nprint $image;\r\n?&gt;<\/pre>\n<h6><span id=\"Alternativa_para_a_fun.C3.A7.C3.A3o_file\" class=\"mw-headline\">Alternativa para a fun\u00e7\u00e3o file<\/span><\/h6>\n<h6><span id=\"Fun.C3.A7.C3.A3o_File\" class=\"mw-headline\">Fun\u00e7\u00e3o File<\/span><\/h6>\n<pre>&lt;?php\r\n$lines = file('http:\/\/example.com\/');\r\n\r\n\/\/ display file line by line\r\nforeach($lines as $line_num =&gt; $line) {\r\n    echo \"Line # {$line_num}\u00a0: \".htmlspecialchars($line).\"&lt;br \/&gt;\\n\";\r\n}\r\n?&gt;<\/pre>\n<h6><span id=\"Aplicando_cURL_2\" class=\"mw-headline\">Aplicando cURL<\/span><\/h6>\n<pre>&lt;?php\r\n$ch = curl_init();\r\n$timeout = 5; \/\/ set to zero for no timeout\r\ncurl_setopt ($ch, CURLOPT_URL, 'http:\/\/example.com');\r\ncurl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);\r\ncurl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);\r\n$file_contents = curl_exec($ch);\r\ncurl_close($ch);\r\n$lines = array();\r\n$lines = explode(\"\\n\", $file_contents);\r\n\r\n\/\/ display file line by line\r\nforeach($lines as $line_num =&gt; $line) {\r\n    echo \"Line # {$line_num}\u00a0: \".htmlspecialchars($line).\"&lt;br \/&gt;\\n\";\r\n}\r\n?&gt;<span id=\"Obtendo_dados_bin.C3.A1rios\" class=\"mw-headline\"><\/span><\/pre>\n    \t\t<div class=\"hts-messages hts-messages--info  hts-messages--withtitle hts-messages--withicon \"   >\r\n    \t\t\t<span class=\"hts-messages__title\"><b>Conhe\u00e7a!<\/b><\/span>    \t\t\t    \t\t\t\t<p>\r\n    \t\t\t\t\tAproveite e conhe\u00e7a outros produtos da Locaweb, como o Clic Lead, <a href=\"https:\/\/www.locaweb.com.br\/clic-lead\/\" target=\"_blank\" rel=\"noopener noreferrer\">clique aqui<\/a> e saiba mais!    \t\t\t\t<\/p>\r\n    \t\t\t    \t\t\t\r\n    \t\t<\/div><!-- \/.ht-shortcodes-messages -->\r\n    \t\t\n","protected":false},"excerpt":{"rendered":"<p>Buscando uma p\u00e1gina na internet &lt;?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, &#8220;http:\/\/example.com\/&#8221;); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); ?&gt; Alternativa para a fun\u00e7\u00e3o file_get_contents file_get_contents &lt;?php $file_contents = file_get_contents(&#8216;http:\/\/example.com\/&#8217;); \/\/ display file echo $file_contents; ?&gt; Aplicando cURL &lt;?php $ch = curl_init(); $timeout = 5; \/\/ set to zero for no timeout&#8230;<\/p>\n","protected":false},"author":6,"comment_status":"closed","ping_status":"closed","template":"","format":"standard","meta":{"footnotes":""},"ht-kb-category":[119],"ht-kb-tag":[418],"class_list":["post-10327","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-hospedagem-de-sites","ht_kb_tag-categoriahospedagem"],"_links":{"self":[{"href":"https:\/\/www.locaweb.com.br\/ajuda\/wp-json\/wp\/v2\/ht-kb\/10327","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.locaweb.com.br\/ajuda\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/www.locaweb.com.br\/ajuda\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.locaweb.com.br\/ajuda\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.locaweb.com.br\/ajuda\/wp-json\/wp\/v2\/comments?post=10327"}],"version-history":[{"count":4,"href":"https:\/\/www.locaweb.com.br\/ajuda\/wp-json\/wp\/v2\/ht-kb\/10327\/revisions"}],"predecessor-version":[{"id":29680,"href":"https:\/\/www.locaweb.com.br\/ajuda\/wp-json\/wp\/v2\/ht-kb\/10327\/revisions\/29680"}],"wp:attachment":[{"href":"https:\/\/www.locaweb.com.br\/ajuda\/wp-json\/wp\/v2\/media?parent=10327"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/www.locaweb.com.br\/ajuda\/wp-json\/wp\/v2\/ht-kb-category?post=10327"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/www.locaweb.com.br\/ajuda\/wp-json\/wp\/v2\/ht-kb-tag?post=10327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}