Skip to content

Commit 73ae027

Browse files
committed
Add support for JSONP
1 parent 480a0ad commit 73ae027

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

sharrre.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
header('content-type: application/json');
2+
header('content-type: application/json; charset=utf-8');
33
//Sharrre by Julien Hany
44
$json = array('url'=>'','count'=>0);
55
$json['url'] = $_GET['url'];
@@ -27,7 +27,19 @@
2727

2828
}
2929
}
30-
echo str_replace('\\/','/',json_encode($json));
30+
31+
if(isset($_GET['callback']) && is_valid_callback($_GET['callback'])){
32+
echo $_GET['callback'] . '('.str_replace('\\/','/',json_encode($json)).')';
33+
}else{
34+
echo str_replace('\\/','/',json_encode($json));
35+
}
36+
37+
function is_valid_callback($subject)
38+
{
39+
$identifier_syntax = '/^[$_\p{L}][$_\p{L}\p{Mn}\p{Mc}\p{Nd}\p{Pc}\x{200C}\x{200D}\.]*+$/u';
40+
41+
return preg_match($identifier_syntax, $subject);
42+
}
3143

3244
function parse($encUrl){
3345
$options = array(

0 commit comments

Comments
 (0)