Skip to content

Instantly share code, notes, and snippets.

@alexantr
Created September 30, 2019 09:27
Show Gist options
  • Save alexantr/7a437a35a9c67b1f6c3b3ff7fa763948 to your computer and use it in GitHub Desktop.
Save alexantr/7a437a35a9c67b1f6c3b3ff7fa763948 to your computer and use it in GitHub Desktop.
Download latest adminer: php dl_adminer.php
<?php
$url = 'https://www.adminer.org/latest-mysql-en.php';
$data = get_web_page($url);
if (isset($data['url'], $data['content'])) {
print_r($data['url']);
file_put_contents(basename($data['url']), $data['content']);
} elseif (isset($data['error'])) {
print_r($data['error']);
}
function get_web_page($url)
{
$options = [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_USERAGENT => 'CocoJumboo/1.0',
CURLOPT_AUTOREFERER => true,
CURLOPT_MAXREDIRS => 10,
];
$ch = curl_init($url);
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
if (curl_errno($ch)) {
$error = curl_error($ch);
curl_close($ch);
return [
'error' => $error,
];
}
$last_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
curl_close($ch);
return [
'content' => $content,
'url' => $last_url,
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment