API随机获取一言
发表于更新于
字数总计:294阅读时长:1分钟 郑州市
教程API分享API随机获取一言
梦爱吃鱼API随机获取一言代码
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
| <?php $counter = intval(file_get_contents("counter.dat")); $_SESSION['#'] = true; $counter++; $fp = fopen("counter.dat","w"); fwrite($fp, $counter); fclose($fp); ?>
<?php
$path = dirname(__FILE__); $file = file($path."binduyan.txt");
$arr = mt_rand( 0, count( $file ) - 1 ); $content = trim($file[$arr]);
if (isset($_GET['charset']) && !empty($_GET['charset'])) { $charset = $_GET['charset']; if (strcasecmp($charset,"gbk") == 0 ) { $content = mb_convert_encoding($content,'gbk', 'utf-8'); } } else { $charset = 'utf-8'; }
if ($_GET['encode'] === 'js') { echo "function binduyan(){document.write('" . $content ."');}"; }else if($_GET['encode'] === 'json'){ header('Content-type:text/json'); $content = array('text'=>$content); echo json_encode($content, JSON_UNESCAPED_UNICODE); }else { echo $content; }
|
上传你的服务器或者主机空间,命名随意后缀为.php
并在同级目录上传一个为binduyuan.txt
后缀的文件
PS:一句话占一行
访问形式为 http(s)://你的域名/你的命名.php
例如 https://bsgun.cn/binduyan.php
车到山前必有雾,船到桥头自然沉。