MENU

随机外链图片API

2020 年 07 月 14 日 • 阅读: 478 • 教程阅读设置

随机图片api的用处应该都知道,可用来制作随机背景图片,实现每访问一次,背景图片便自动换一张

已搭建好的演示: img.hacker.hk

教程:

1.首先,新建 img.txt 文件,内容为图片外链,一行一个,列如下方:

https://cdn.jsdelivr.net/gh/pic-cdn/cdn1@latest/2020/04/29/c7126cc145d2ff68273b2eb429965493.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn1@latest/2020/04/29/2c7b91e76a66606268d666931c686e59.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn1@latest/2020/04/29/bee94169707121b69e5adc8f08f9897f.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn1@latest/2020/04/30/42f4d80468fa4a43b8d9b747972db2ea.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn1@latest/2020/04/30/522cd5295e8779887141e5ff2a578d46.png
https://ae01.alicdn.com/kf/U76044e5ff86a4b888adf7fcc026ca06bD.jpg
https://ae01.alicdn.com/kf/U29df8154a9ee48c2990179d0f321fb10Q.jpg
https://ae01.alicdn.com/kf/Uc8cadda582074f91a1f2e93358206ca9a.jpg
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@5b595305ede7efb33efa61f10d67775bae1a1e3c/2020/09/09/5610ee38b1183ce22be6b2c2427591cf.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@7903d0678389ce573b966284b5259156126cd3a2/2020/09/09/6a916c1392b55d6ec6d078fbb4f83f62.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@935b8ebd2d8ba2076bab2ed8f7175370207527bb/2020/09/09/a4d8821519e433ffd6cef9cbb59c6c8f.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@50b15321a6b083da537932e60654dbc37753db79/2020/09/09/c4cc55653d5ff835830a7577e2476eeb.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@3591353705b731308e72c54c5752928bc6746cc1/2020/09/09/205a9256c1602f438aa7b0365be30335.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@a6ff623432cd16087e03eb75f84046718ed937e7/2020/09/09/862d39ad4f8d196c7821dd178fad6874.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@3ca2a92908673fc8ecf318fca52c0909e8397daf/2020/09/09/99c923fdb5f0a66d5b94b9d3503b7b29.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@6713337e4860884ed7e87cc39357337e302d238f/2020/09/09/3da541186cac713e3a18e1c1c018dec2.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@cf4247eb339402ead5d1acf95bf7b2b89b67e6f0/2020/09/09/cac1911e41db95e16d2fdc105977fa0f.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@b1dac108c5ce9af1aad48ab0cc722c0f2ac36227/2020/09/09/02c45bfc9087fa5c6035b7cd4c4eddb7.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@80d11cda404dd0d8deeff469cced2eefdb54e69e/2020/09/09/562cd6df31d98ed3893d68213870d759.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@897db63d24ecc000aa071a3ca18d776dc8f8e802/2020/09/09/e97b9be47686dc8bafb824a7a60825ac.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@b0fcae6657293eda333479b108ac5e3ba17fe525/2020/09/09/19fba1c0ca77872e6632838a86e93808.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@7ccf8ea884fa9169939cfdc3c7d0babea10e5630/2020/09/09/09ddc55d4af983dbeaf83dc8854eebc3.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@73391a7bbcb4eaee3c6b7a7752769f8361ba7045/2020/10/09/5f3800ee97d05698fcafb228d32b6448.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@5e5c2f0ddc9ce8194b3d7342d095eb73085c29f0/2020/10/09/3b82a72c08e9ce7674b07a7f3155098e.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@81ef5c15f942e01b39fadf575fb8859a8d6917f7/2020/10/09/ef2db51138bbffdeb909e33d536eea03.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@55fe6162b70072a23055f4eac6ce61f69d2dd27a/2020/10/09/33c4783f88b1eeea6d15cbffd5f7ab03.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@e21b57242df6bce643b7f3c2e2bec8f2149e40cb/2020/10/09/8aeb108a892898e676e7dfd5113eaf45.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@ffed1319f575e49397d3db7e657a88624090ae57/2020/10/09/e8af1da14fa11b0055bf8bf8f7991e71.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@1c64529bd1bc537646e237b436b418402f15144e/2020/10/09/fab537eeafb4eafc250d55c7d36af500.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@403f0f413ba2054b47857dc39c6d68d9ae8e70e9/2020/10/09/6d97447afa23799c4f6466e503251745.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@9d9af1393c1f7a54eba8f751a0cd4ff8f3f03edd/2020/10/09/8a36246b48bb71186e46bf113712afc3.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@47a67e9566b5705eec69dfb817862e2de07c8ec6/2020/10/09/1cf8e73cd81c44bb849ed9ca69f6eb76.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@d77861dc8c9d0b1475dce7d4825649082c2abf96/2020/10/09/7be4423d80a7562e7c50b3e2cc06ba50.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@869074c66976485893e12166ae2d11854272d9af/2020/10/09/22bf74ee67751a2c3b1c9b12ef0e949b.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@9791924492fdb4a0f6ce356e1b2446baa85d38ef/2020/10/09/c87175cbeb9a9b04ce3ce453f76ff7c8.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@eaa8af587a344f8898436b7cf5164add76eb5e81/2020/10/09/d88da2cebf9b055589e12e6c7492ef82.png
https://cdn.jsdelivr.net/gh/pic-cdn/cdn2@7407cea072e242b96d1bad521a32130747c7c460/2020/10/09/fa3402aeefc0330a0ba2cbbc8d45cae5.png

2.新建一个 .php 格式文件,名称随意,内容复制下方:

<?php
$arr=file('img.txt');
$n=count($arr)-1;
for ($i=1;$i<=1;$i++){
$x=rand(0,$n);
header("Location:".$arr[$x],"\n");
}
?>

3.上传这两文件至主机或服务器,然后访问http://你的域名(IP)/自定义.php
即可看到每次访问的图片是随机的

最后编辑于: 2020 年 11 月 06 日