一段很简单的PHP代码,用于手机拨号

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>XXX联系方式</title>
<meta name="viewport" content="width=device-width; initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <style>
        .table th { 
            text-align: center; 
            font-size: 18px;
            vertical-align: middle !important;
            }
        .table td {
            font-size: 16px;
            vertical-align: middle !important;            
        } 
        h2 { font-weight:bold;text-align: center;}
    </style>
</head>
<body>
<h2>XXX联系方式</h2> 
<table class="table table-bordered">   
    <thead>   
        <tr> 
            <th>序号</th>                
            <th>姓名</th>   
            <th>操作</th>   
        </tr>   
    </thead>   
    <tbody>   
        <?php
    
            $conn = mysqli_connect('127.0.0.1', 'root', 'root','table') or die ('连接失败: ' . mysqli_error()) ;
            // 设置编码,防止中文乱码
            mysqli_query($conn , "set names utf8"); 
            $sql = 'select * from TB_NLianXiFS order by id asc'; $retval = mysqli_query($conn, $sql ) or die("Error in query: $sql. ".mysql_error());
            while($row = mysqli_fetch_assoc($retval))
            {
                echo '<tr>';
                echo '<td align="center">'.$row['id'].'</td>';
                echo '<td>'.$row['name'].'</td>';
                echo '<td><button type="button" class="btn btn-success" onclick="Calltel('.$row['tel'].');">&nbsp;拨号&nbsp;</button> </td>';
                echo "</tr>";
            }
            mysqli_free_result($retval);
            $ip = getIp();
            $rq = date("Y-m-d h:i:s"); 
            $InsertSQL = "Insert into tb_njlb(ip,riqi) values ('$ip','$rq')" ;
            $result = mysqli_query($conn,$InsertSQL)or die("Error in Query ".mysql_error()); 
            mysqli_close($conn);
        ?>        
    </tbody>   
</table> 
<script type="text/javascript">
    function Calltel(tel){
        window.location.href = "tel:"+tel;
    }
</script>
</body>
</html>
<?php
function getIp()
{
    if ($_SERVER["HTTP_CLIENT_IP"] && strcasecmp($_SERVER["HTTP_CLIENT_IP"], "unknown")) {
        $ip = $_SERVER["HTTP_CLIENT_IP"];
    } else {
        if ($_SERVER["HTTP_X_FORWARDED_FOR"] && strcasecmp($_SERVER["HTTP_X_FORWARDED_FOR"], "unknown")) {
            $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
        } else {
            if ($_SERVER["REMOTE_ADDR"] && strcasecmp($_SERVER["REMOTE_ADDR"], "unknown")) {
                $ip = $_SERVER["REMOTE_ADDR"];
            } else {
                if (isset ($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'],
                        "unknown")
                ) {
                    $ip = $_SERVER['REMOTE_ADDR'];
                } else {
                    $ip = "unknown";
                }
            }
        }
    }
    return ($ip);
}
?>

 

posted @ 2020-03-11 16:53  李先森°  阅读(792)  评论(0编辑  收藏  举报