html+js使用了花海大佬的模板,我只是在js处加入了PHP
理论支持大部分ty主题
本站随跳转链接https://www.xxhzm.cn/jump/

<?php
$servername = "localhost";
$username = "数据库用户名";
$password = "数据库密码";
$dbname = "数据库名字";
 
// 创建连接
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
} 
 
$sql = "SELECT url FROM typecho_links";//数据表
$result = $conn->query($sql);
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>随机跳转</title>
</head>

<body>
        <script>
    function jumpUrl(){
        var arr = new Array(
            <?php
              while($row = $result->fetch_assoc()) {//遍历数组
                   print('"'.$row['url'].'",');//输出数据表内的链接
                }
                    $conn->close();
            ?>
        );
     window.location.href = arr[Math.floor(Math.random() * arr.length)];
    }
    
    setTimeout(function () {
    jumpUrl();},6000);//设定跳转时间,1s=1000
    </script>
    </body>

</html>



最后修改:2021 年 11 月 10 日 09 : 38 AM
如果觉得我的文章对你有用,请随意赞赏