午夜久久久久久久久久一区二区_欧美日韩一区二区三区免费看 _欧美国产在线视频_亚洲影院一区

 
深圳網站建設設計

將想法與焦點和您一起共享

深圳網站建設設計 深圳網站優化排名 深圳網站設計制作欣賞

如何創建自己的程序(JavaScript、ajax、PHP)

2017-07-26  閱讀: 深圳網站建設設計

如何創建自己的程序(JavaScript、ajax、PHP)
深圳網站建設創建網站時,一個主要目標是吸引訪問者。交通產生是為了金錢目的,炫耀你的工作,或只是表達你的想法。有很多方法可以為你的網站創建流量。搜索引擎,社會化書簽,口碑只是幾個例子。但是你怎么知道這個交通是不是真的呢?你怎么知道你的客人是否會再次回來?

這些問題提出了網絡統計的概念。通常情況下,網站管理員使用某些程序,如谷歌Analytics或軟件,來完成他們的工作。這些程序獲取關于站點訪問者的各種信息。他們發現頁面視圖,訪問,獨特的訪問者,瀏覽器,IP地址,等等。但這究竟是如何實現的呢?請跟隨本教程如何創建你自己的網站統計程序使用PHP,JavaScript,Ajax,和SQLite。

首先,讓我們從一些簡單的HTML標記開始,它將充當我們所跟蹤的頁面:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Web Statistics</title>
</head>
<body>

<h2 id="complete"></h2>

</body>
</html>

H2 #完整的元素將被填充動態JavaScript一旦頁面視圖已成功通過我們的網站統計跟蹤。為了啟動跟蹤,我們可以使用jQuery和Ajax請求:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type='text/javascript'>
$(function() {
    // Set the data text
    var dataText = 'page=<?php echo $_SERVER['REQUEST_URI']; ?>&referrer=<?php echo $_SERVER['HTTP_REFERER']; ?>';

    // Create the AJAX request
    $.ajax({
        type: "POST",                    // Using the POST method
        url: "/process.php",             // The file to call
        data: dataText,                  // Our data to pass
        success: function() {            // What to do on success
            $('#complete').html( 'Your page view has been added to the statistics!' );
        }
    });
});
</script>

一步一步地考慮上面的代碼:

當DOM準備好了,我們首先把我們的數據、文本。本文在查詢字符串的格式,將數據發送到process.php,將跟蹤此頁面視圖。

然后我們創建一個Ajax請求,它使用POST方法發送表單數據。

如何創建自己的程序(JavaScript、ajax、PHP)

我們的表格數據(數據、文本)然后送到process.php在我們服務器的根。

一旦這個請求完成,H2 #完整的元素是充滿成功的通知

我們下一步的工作是寫process.php。它的主要目標是獲取有關Web統計信息的信息,并將其存儲在數據庫中。由于我們的數據庫尚未作出,我們必須創建一個簡單的文件,安裝,這將為我們做這件事:

<?php    
    # Open the database
    $handle = sqlite_open( $_SERVER['DOCUMENT_ROOT'].'stats.db', 0666, $sqliteError ) or die(  $sqliteError  );

    # Set the command to create a table
    $sqlCreateTable = "CREATE TABLE stats(page text UNIQUE, ip text, views UNSIGNED int DEFAULT 0, referrer text DEFAULT '')";

    # Execute it
    sqlite_exec( $handle, $sqlCreateTable );
    
    # Print that we are done
    echo 'Finished!';
?>

這段代碼大部分是直截了當的。它在服務器的根目錄中打開一個數據庫,并為它創建一個數據庫。在sqlcreatetable美元的字符串是一個SQLite命令,使我們的統計表。該表包含四列:頁面、IP地址、意見和推薦:

頁面是一個字符串,其中包含被視為相對鏈接的頁面(即索引PHP)。

IP地址也是一個字符串,其中包含訪問此頁的IP地址列表。它是在numvisits1格式(IP地址1)numvisits2(IP演說2)numvisits3(IP address3)等。例如,如果我們從74.35.286.15來訪10人次和5 86.31.23.78(假想的IP地址),這個字符串將“10(74.25.286.15)5(86.31.23.78)”。

視圖是一個包含頁面被瀏覽次數的整數。

引用在同一格式的字符串作為IP地址。它包含所有引用到這個網頁有多少下線了。

現在到process.php:

# Connect to the database
$handle = sqlite_open( $_SERVER['DOCUMENT_ROOT'].'/stats.db', 0666, $sqliteError ) or die( $sqliteError );

# Use the same-origin policy to prevent cross-site scripting (XSS) attacks
# Remember to replace http://yourdomain.com/ with your actual domain
if( strpos( $_SERVER['HTTP_REFERER'], 'http://yourdomain.com/' ) !== 0 ) {
     die( "Do not call this script manually or from an external source." );
}

# Obtain the necessary information, strip HTML tags, and escape the string for backup proetection
$page = sqlite_escape_string( strip_tags( $_POST['page'] ) );
$referrer = sqlite_escape_string( strip_tags( $_POST['referrer'] ) );
$ip = sqlite_escape_string( strip_tags( $_SERVER['REMOTE_ADDR'] ) );


# Query the database so we can update old information
$sqlGet = 'SELECT * FROM stats WHERE page = ''.$page.''';
$result = sqlite_query( $handle, $sqlGet );

這第一段代碼連接到我們的統計數據庫,并獲取當前訪問所需的信息。它還查詢數據庫并獲取以前存儲的任何信息。我們使用此信息創建更新表。

下一個工作是查找舊信息:
# Set up a few variables to hold old information
$views = 0;
$ips = '';
$referrers = '';
    
# Check if old information exists
if( $result && ( $info = sqlite_fetch_array( $result ) ) ) {
    # Get this information
    $views = $info['views'];
    $ips = $info['ip'].' ';
    if( $info['referrer'] )
        $referrers = $info['referrer'].' ';

    # Set a flag to state that old information was found
    $flag = true;
}


上面的代碼查找表中的所有以前的信息。這是至關重要的,我們需要更新視圖的數量(增加了一個),IP地址,和引薦。
# Create arrays for all referrers and ip addresses
$ref_num = array();
$ip_num = array();

# Find each referrer
$values = split( ' ', $referrers );

# Set a regular expression string to parse the referrer
$regex = '%(d+)((.*?))%';

# Loop through each referrer
foreach( $values as $value ) {
    # Find the number of referrals and the URL of the referrer
    preg_match( $regex, $value, $matches );
        
    # If the two exist
    if( $matches[1] && $matches[2] )
        # Set the corresponding value in the array ( referrer link -> number of referrals )
        $ref_num[$matches[2]] = intval( $matches[1] );
}
    
# If there is a referrer on this visit
if( $referrer )
    # Add it to the array
    $ref_num[$referrer]++;
    
# Get the IPs
$values = split( ' ', $ips );

# Repeat the same process as above
foreach( $values as $value ) {
    # Find the information
    preg_match( $regex, $value, $matches );
        
    # Make sure it exists
    if( $matches[1] && $matches[2] )
        # Add it to the array
        $ip_num[$matches[2]] = intval( $matches[1] );
}

# Update the array with the current IP.
$ip_num[$ip]++;

上面的兩個循環非常相似。他們從數據庫中獲取信息并用正則表達式解析它。一旦解析了這個信息,它就存儲在一個數組中。然后使用當前訪問的信息更新每個數組。然后,可以使用此信息創建最終字符串:
# Reset the $ips string
$ips = '';

# Loop through all the information
foreach( $ip_num as $key => $val ) {
    # Append it to the string (separated by a space)
    $ips .= $val.'('.$key.') ';
}

# Trim the String
$ips = trim( $ips );

# Reset the $referrers string
$referrers = '';

# Loop through all the information
foreach( $ref_num as $key => $val ) {
    # Append it
    $referrers .= $val.'('.$key.') ';
}

# Trim the string
$referrers = trim( $referrers );

最后的字符串現在創建。IPS和引薦的形式是:“numvisits1(IP / referrer1)numvisits2(IP / referrer2)等。例如,以下是引用字符串:

5(https://www.noupe.com) 10(http://css-tricks.com)

# Update the number of views
$views++;
    
# If we did obtain information from the database
# (the database already contains some information about this page)
if( $flag )
    # Update it
    $sqlCmd = 'UPDATE stats SET ip=''.$ips.'', views=''.$views.'', referrer=''.$referrers.'' WHERE page=''.$page.''';

# Otherwise
else
    # Insert a new value into it
    $sqlCmd = 'INSERT INTO stats(page, ip, views, referrer) VALUES (''.$page.'', ''.$ips.'',''.$views.'',''.$referrers.'')';
        
# Execute the commands
sqlite_exec( $handle, $sqlCmd );

這就是它的process.php。作為一個回顧,發現訪客的IP地址和引用,使用的值來創建兩個字符串,增加一個頁面瀏覽數,和地方的所有這些值到數據庫。

如何創建自己的程序(JavaScript、ajax、PHP)

現在只剩下一個任務了。我們必須顯示網絡統計信息。讓我們把以下文件display.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Web Statistics Display</title>
</head>
<body>

<?php
    # Open up the database
    $handle = sqlite_open( $_SERVER['DOCUMENT_ROOT'].'/stats.db', 0666, $sqliteError ) or die( $sqliteError );
    
    # Get all the statistics
    $sqlGet = 'SELECT * FROM stats';
    $result = sqlite_query( $handle, $sqlGet );
    
    # Create an unordered list
    echo "<ul>n";
    
    # If there are results
    if( $result ) {
        $page_views = 0;
        $unique_visitors = 0;
        
        # Fetch them
        while( ($info = sqlite_fetch_array( $result ) ) ) {
            # Get the page, views, IPs, and referrers
            $page = $info['page'];
            $views = $info['views'];
            $ips = $info['ip'];
            $referrers = $info['referrer'];
            
            # Print out a list element with the $page/$views information
            if( $views == 1 )
                echo "t<li>ntt<p>$page was viewed $views time:</p>n";
            else
                echo "t<li>ntt<p>$page was viewed $views times:</p>n";
            
            # Update the number of page views
            $page_views += $views;
            
            # Parse the data of IPs and Referrers using process.php's code
            preg_match_all( '%(d+)((.*?))%', $ips, $matches );
            
            # Find the size of the data
            $size = count( $matches[1] );
            
            # Create a sub list
            echo "tt<ul>n";
            
            # Loop through all the IPs
            for( $i = 0; $i < $size; $i++ ) {
                # Find the number of visits
                $num = $matches[1][$i];

                # Find the IP address
                $ip = $matches[2][$i];
                
                # Print the info in a list element
                if( $num == 1 )
                    echo "ttt<li>$num time by $ip</li>n";
                else
                    echo "ttt<li>$num times by $ip</li>n";
                
                # Update the number of unique visitors
                $unique_visitors++;
            }
            
            # Repeat the whole process for referrers
            preg_match_all( '%(d+)((.*?))%', $referrers, $matches );
            $size = count( $matches[1] );
            
            # Loop through each one
            for( $i = 0; $i < $size; $i++ ) {
                $num = $matches[1][$i];
                $referrer = $matches[2][$i];
                
                # Print out the info
                if( $num == 1 )
                    echo "ttt<li>$num referral by $referrer</li>n";
                else
                    echo "ttt<li>$num referrals by $referrer</li>n";
            }
            
            # End the sub-list
            echo "tt</ul>n";
            
            # End the list element
            echo "t</li>n";
        }
        
        echo "t<li>Total unique visitors: $unique_visitors</li>n";
        echo "t<li>Total page views: $page_views</li>n";
    }
    
    # End the unordered list
    echo "</ul>n";
    
    # Close the database
    sqlite_close($handle);
?>

</body>
</html>

它似乎令人生畏,但它是process.php非常相似。它解析頁面視圖,IP地址,并從數據庫引用。然后,它繼續以無序列表格式輸出它們。

將文章分享到..
午夜久久久久久久久久一区二区_欧美日韩一区二区三区免费看 _欧美国产在线视频_亚洲影院一区
在线不卡a资源高清| 久久嫩草精品久久久精品一| 免费毛片一区二区三区久久久| 免费观看一级特黄欧美大片| 亚洲成在线观看| 欧美成人精品不卡视频在线观看 | 可以免费看不卡的av网站| 狠狠色狠狠色综合| 久久夜色精品国产| 亚洲精品一区二区三区99| 欧美日韩影院| 午夜在线视频一区二区区别 | 欧美一区二区视频在线| 国产婷婷色综合av蜜臀av| 久久久久国产免费免费| 亚洲国产精品va在线看黑人| 欧美激情精品久久久久久蜜臀 | 亚洲四色影视在线观看| 国产精品毛片a∨一区二区三区|国 | 伊人久久综合| 亚洲一本视频| 欧美日韩国产精品自在自线| 亚洲风情亚aⅴ在线发布| 久久久久国产一区二区三区四区 | 亚洲大片av| 亚洲欧美精品一区| 欧美日韩在线不卡| 99re6这里只有精品| 欧美 日韩 国产在线| 亚洲激情av| 久热精品在线视频| 精东粉嫩av免费一区二区三区| 欧美精品18videos性欧美| 中文亚洲视频在线| 国产主播一区二区三区四区| 麻豆久久婷婷| 日韩小视频在线观看专区| 国产精品乱子久久久久| 亚洲一区二区免费视频| 国产精品福利网| 亚洲人成毛片在线播放| 国产精品视频专区| 欧美中文字幕在线视频| 怡红院精品视频在线观看极品| 欧美成年人视频网站欧美| 亚洲国产经典视频| 国产精品乱人伦一区二区| 久久久国产精彩视频美女艺术照福利| 136国产福利精品导航网址| 欧美日韩一区二区三区视频| 亚洲男女自偷自拍| 亚洲人妖在线| 欧美日韩性视频在线| 亚洲一区二区视频在线观看| 国产精品视频大全| 欧美一区二区三区婷婷月色| 亚洲第一在线综合网站| 欧美丝袜第一区| 久久精品人人做人人综合 | 女人香蕉久久**毛片精品| 伊人久久久大香线蕉综合直播| 欧美成人中文字幕| 亚洲欧洲在线一区| 欧美日韩ab片| 亚洲美女在线国产| 国产麻豆91精品| 欧美精品免费观看二区| 欧美亚洲日本一区| 极品少妇一区二区三区精品视频| 欧美成人自拍视频| 一区二区成人精品| 国模精品一区二区三区色天香| 欧美精品1区2区3区| 性色av一区二区三区| 国产在线拍偷自揄拍精品| 欧美日韩国产999| 麻豆91精品91久久久的内涵| 亚洲破处大片| 国产精品日日做人人爱| 开心色5月久久精品| 一本色道久久88综合日韩精品| 欧美偷拍另类| 亚洲国产精品一区二区第一页| 国产精品亚洲片夜色在线| 欧美屁股在线| 小黄鸭视频精品导航| 亚洲精品美女在线观看| 欧美性久久久| 久久久久国产精品一区三寸| 亚洲大胆美女视频| 国产精品成人观看视频免费 | 欧美日韩一区二区在线| 西瓜成人精品人成网站| 亚洲成色www久久网站| 欧美精品aa| 久久精品人人做人人综合| 亚洲综合成人在线| 亚洲一区免费视频| 亚洲国产裸拍裸体视频在线观看乱了 | 在线一区观看| 国产日韩欧美夫妻视频在线观看| 久久亚洲精品伦理| 亚洲性线免费观看视频成熟| 亚洲黄色在线看| 国产一区二区日韩| 欧美国产激情| 欧美成人dvd在线视频| 亚洲欧美日韩一区在线观看| 亚洲国产女人aaa毛片在线| 含羞草久久爱69一区| 国产精品影音先锋| 欧美日韩精品中文字幕| 欧美一区二区在线播放| 亚洲视频在线播放| 一区二区三区不卡视频在线观看| 国产精品v欧美精品v日韩 | 午夜精品视频一区| 久久嫩草精品久久久精品一| 欧美日韩精品一二三区| 国产日韩欧美不卡| 亚洲精品日韩在线| 欧美综合77777色婷婷| 欧美日本不卡| 国内激情久久| 一区二区欧美日韩| 久久xxxx| 欧美日韩在线三区| 伊人精品视频| 性做久久久久久免费观看欧美| 欧美精品一区三区| 国产在线播放一区二区三区| 一本一道久久综合狠狠老精东影业 | 亚洲欧美日韩区| 欧美v国产在线一区二区三区| 国产精品无码专区在线观看| 亚洲人体偷拍| 久久午夜激情| 国产精品自拍小视频| 亚洲免费不卡| 老司机免费视频一区二区| 国产嫩草一区二区三区在线观看| 亚洲美女精品成人在线视频| 久久久久久9| 国产精品一二一区| 亚洲最新视频在线| 欧美不卡视频| 精品av久久久久电影| 午夜久久99| 国产精品大片| 99国产精品自拍| 麻豆成人在线播放| 国产综合色精品一区二区三区| 亚洲影院免费观看| 欧美日韩高清一区| 亚洲国产美女| 久久综合中文字幕| 国产一区二区三区无遮挡| 亚洲男女自偷自拍| 国产精品福利在线观看| 日韩视频一区二区三区在线播放免费观看| 久久久综合免费视频| 国产一区二区三区四区五区美女 | 欧美日韩专区| 亚洲黄色在线看| 老**午夜毛片一区二区三区| 国产亚洲毛片| 欧美资源在线观看| 国产欧亚日韩视频| 亚洲欧美日韩视频一区| 国产精品扒开腿做爽爽爽视频| 日韩亚洲欧美中文三级| 欧美激情精品久久久久久| 91久久中文字幕| 欧美激情一区二区三区全黄 | 国产伦精品一区二区三区照片91 | 亚洲综合首页| 欧美日韩日本视频| 日韩视频在线观看国产| 欧美激情一区二区三区蜜桃视频 | 在线免费观看欧美| 久久精品官网| 国产一区二区三区在线观看视频| 欧美一级专区免费大片| 国产精品一级| 性伦欧美刺激片在线观看| 国产精品美女久久| 亚洲一区综合| 国产女主播一区二区三区| 午夜日韩在线| 国产欧美一区二区三区在线老狼| 午夜精品成人在线视频| 国产乱人伦精品一区二区| 欧美一级大片在线免费观看| 国产一二三精品| 久久久久久午夜| 亚洲高清精品中出| 欧美欧美天天天天操| 中文精品一区二区三区| 国产精品女人网站| 欧美在线一二三区|