I have previously written an article about anti-leeching in images. I have used sina short connections for my own webpage, which is convenient for short connections, the address is too long. the source code is shared below, which has comments and is not original. the code is as follows :? PhpSina... I have previously written an article about anti-leeching in images. I have used sina short connections for my own webpage, which is convenient for short connections, if the address is too long, the source code is shared below, which has annotations and is not original. the code is as follows:
Error) |! Isset ($ json [0]-> url_short) | $ json [0]-> url_short = '') return false; else return $ json [0]-> url_short;} // Obtain the long URL based on the short url. this function reuse a lot of codes in sinaShortenUrl to facilitate your reading and comparing, you can merge two function sinaExpandUrl ($ short_url) {// concatenate the request address. you can view $ url = 'http: // api.t.sina.com.cn/short_url/expand.json in the official documentation? Source = '. SINA_APPKEY. '& url_short = '. $ short_url; // get the request result $ result = curlQuery ($ url); // the following line of comment is used for debugging, you can remove the comment to see what is returned from sina // print_r ($ result); exit (); // parse json $ json = json_decode ($ result ); // if an exception occurs, false if (isset ($ json-> error) is returned. |! Isset ($ json [0]-> url_long) | $ json [0]-> url_long = '') return false; else return $ json [0]-> url_long;} // open-source phpfensi.com//the URL of the website to be scaled down =long long; // You can view it here, modify it to the URL you want to shorten or to get the post data or how to drop it. $ Url = filterUrl ($ url); $ short = sinaShortenUrl ($ url); $ ulong = sinaExpandUrl ($ short);?>
In this article, the appkey that has been attached to the short connection does not need to apply for the KEY by yourself. of course, if you need to use your own appkey, you can replace it by yourself. the usage depends on you, embedded into other programs for use? I don't care if I create a page that generates a short connection. I don't know how to use it. recently, it's relatively lazy.
Permanent link:
Reprint at will! Include the article address.