downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/curl.examples-basic.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/curl.examples.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'curl.examples-basic.php',
   
1 => 'Using PHP\'s cURL module to fetch the example.com homepage',
  ),
 
'up' =>
  array (
   
0 => 'curl.examples.php',
   
1 => 'Examples',
  ),
 
'prev' =>
  array (
   
0 => 'curl.examples.php',
   
1 => 'Examples',
  ),
 
'next' =>
  array (
   
0 => 'ref.curl.php',
   
1 => 'cURL Functions',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="curl.examples-basic" class="section">
  <p class="para">
   Once you&#039;ve compiled PHP with cURL support, you can begin using
   the cURL functions. The basic idea behind the cURL functions is
   that you initialize a cURL session using the
   <a href="function.curl-init.php" class="function">curl_init()</a>, then you can set all your
   options for the transfer via the <a href="function.curl-setopt.php" class="function">curl_setopt()</a>,
   then you can execute the session with the
   <a href="function.curl-exec.php" class="function">curl_exec()</a> and then you finish off
   your session using the <a href="function.curl-close.php" class="function">curl_close()</a>.
   Here is an example that uses the cURL functions to fetch the
   example.com homepage into a file:
   </p><div class="example">
    <p><b>Example #1 Using PHP&#039;s cURL module to fetch the example.com homepage</b></p>
    <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$ch&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">curl_init</span><span style="color: #007700">(</span><span style="color: #DD0000">"http://www.example.com/"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"example_homepage.txt"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"w"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">curl_setopt</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">CURLOPT_FILE</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">curl_setopt</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">CURLOPT_HEADER</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">curl_exec</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">curl_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div><p>
  </p>
 </div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites