Skip to content

Instantly share code, notes, and snippets.

@f0t0n
Created April 22, 2012 11:20
Show Gist options
  • Save f0t0n/2463694 to your computer and use it in GitHub Desktop.
Save f0t0n/2463694 to your computer and use it in GitHub Desktop.
Using php curl with CURLOPT_USERAGENT option
<?php
$username='h2odev';
$password='likewater';
$location='http://h2odev.law.harvard.edu/playlists/151';
$baseUrl = 'http://h2odev.law.harvard.edu/';
$currDir = dirname(__FILE__) . DIRECTORY_SEPARATOR;
$userAgent = require($currDir . 'cuseragent.php');
$ch = curl_init ();
curl_setopt($ch,CURLOPT_URL,$location);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_USERPWD,"$username:$password");
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
$result = curl_exec ($ch);
curl_close($ch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment