puiu91
10/1/2015 - 3:36 PM

Using php curl with CURLOPT_USERAGENT option

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);