-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunshorten_url.php
51 lines (46 loc) · 1.67 KB
/
unshorten_url.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<html>
<form action="" method="post" style="text-align: center;">
<input name="urls" placeholder="put those pesky shortened links here" textarea style="width: 100%; height: 30vh;"><br>
<p><button style="background-color: black; color: white; padding: 5px; border-radius: 5px;" type="submit" name="submit">get me my urls</button><p>
</form>
</html>
<?php
function unshorten_url($url) {
$ch = curl_init($url);
curl_setopt_array($ch, array(
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_SSL_VERIFYHOST => FALSE,
CURLOPT_SSL_VERIFYPEER => FALSE,
));
curl_exec($ch);
$url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
curl_close($ch);
return 'url:'.$url;
echo'url:'.$url;
}
if(isset($_POST["submit"])){
$urls = $_POST["urls"];
}
$pattern = '/(?:[^\s]+@[a-z]+(\.[a-z]+)+)|(?:(?:(?:[a-z]+:\/\/)|(?!\s))[a-z]+(\.[a-z]+)+(\/[^\s]*)?)/';
preg_match_all($pattern, $urls, $out);
$count = count($out[0]);
echo "<b> Number of URLS</b> =" .$count."<br>";
for ($row=0; $row<$count;$row++){
$link = $out[0][$row];
get_headers($link);
$url = preg_replace(array('/\s{2,}/', '/[\t\n]/'), ' ', $link);
unshorten_url($link);
$ch = curl_init($url);
curl_setopt_array($ch, array(
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_SSL_VERIFYHOST => FALSE,
CURLOPT_SSL_VERIFYPEER => FALSE,
));
curl_exec($ch);
$url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
curl_close($ch);
echo $row.': <a href='.$url.'>'.$url.'</a><br>';
}
?>