99色视频在线观看-99色视频在线-99色视频-99色精品-99色播-99色吧

 
深圳網(wǎng)站建設(shè)設(shè)計(jì)

將想法與焦點(diǎn)和您一起共享

深圳網(wǎng)站建設(shè)設(shè)計(jì) 深圳網(wǎng)站優(yōu)化排名 深圳網(wǎng)站設(shè)計(jì)制作欣賞

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

2017-07-26  閱讀: 深圳網(wǎng)站建設(shè)設(shè)計(jì)

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

這些問題提出了網(wǎng)絡(luò)統(tǒng)計(jì)的概念。通常情況下,網(wǎng)站管理員使用某些程序,如谷歌Analytics或軟件,來完成他們的工作。這些程序獲取關(guān)于站點(diǎn)訪問者的各種信息。他們發(fā)現(xiàn)頁面視圖,訪問,獨(dú)特的訪問者,瀏覽器,IP地址,等等。但這究竟是如何實(shí)現(xiàn)的呢?請(qǐng)跟隨本教程如何創(chuàng)建你自己的網(wǎng)站統(tǒng)計(jì)程序使用PHP,JavaScript,Ajax,和SQLite。

首先,讓我們從一些簡(jiǎn)單的HTML標(biāo)記開始,它將充當(dāng)我們所跟蹤的頁面:

<!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 #完整的元素將被填充動(dòng)態(tài)JavaScript一旦頁面視圖已成功通過我們的網(wǎng)站統(tǒng)計(jì)跟蹤。為了啟動(dòng)跟蹤,我們可以使用jQuery和Ajax請(qǐng)求:

<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>

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

當(dāng)DOM準(zhǔn)備好了,我們首先把我們的數(shù)據(jù)、文本。本文在查詢字符串的格式,將數(shù)據(jù)發(fā)送到process.php,將跟蹤此頁面視圖。

然后我們創(chuàng)建一個(gè)Ajax請(qǐng)求,它使用POST方法發(fā)送表單數(shù)據(jù)。

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

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

一旦這個(gè)請(qǐng)求完成,H2 #完整的元素是充滿成功的通知

我們下一步的工作是寫process.php。它的主要目標(biāo)是獲取有關(guān)Web統(tǒng)計(jì)信息的信息,并將其存儲(chǔ)在數(shù)據(jù)庫中。由于我們的數(shù)據(jù)庫尚未作出,我們必須創(chuàng)建一個(gè)簡(jiǎn)單的文件,安裝,這將為我們做這件事:

<?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!';
?>

這段代碼大部分是直截了當(dāng)?shù)摹K诜?wù)器的根目錄中打開一個(gè)數(shù)據(jù)庫,并為它創(chuàng)建一個(gè)數(shù)據(jù)庫。在sqlcreatetable美元的字符串是一個(gè)SQLite命令,使我們的統(tǒng)計(jì)表。該表包含四列:頁面、IP地址、意見和推薦:

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

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

視圖是一個(gè)包含頁面被瀏覽次數(shù)的整數(shù)。

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

現(xiàn)在到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 );

這第一段代碼連接到我們的統(tǒng)計(jì)數(shù)據(jù)庫,并獲取當(dāng)前訪問所需的信息。它還查詢數(shù)據(jù)庫并獲取以前存儲(chǔ)的任何信息。我們使用此信息創(chuàng)建更新表。

下一個(gè)工作是查找舊信息:
# 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;
}


上面的代碼查找表中的所有以前的信息。這是至關(guān)重要的,我們需要更新視圖的數(shù)量(增加了一個(gè)),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]++;

上面的兩個(gè)循環(huán)非常相似。他們從數(shù)據(jù)庫中獲取信息并用正則表達(dá)式解析它。一旦解析了這個(gè)信息,它就存儲(chǔ)在一個(gè)數(shù)組中。然后使用當(dāng)前訪問的信息更新每個(gè)數(shù)組。然后,可以使用此信息創(chuàng)建最終字符串:
# 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 );

最后的字符串現(xiàn)在創(chuàng)建。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。作為一個(gè)回顧,發(fā)現(xiàn)訪客的IP地址和引用,使用的值來創(chuàng)建兩個(gè)字符串,增加一個(gè)頁面瀏覽數(shù),和地方的所有這些值到數(shù)據(jù)庫。

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

現(xiàn)在只剩下一個(gè)任務(wù)了。我們必須顯示網(wǎng)絡(luò)統(tǒng)計(jì)信息。讓我們把以下文件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地址,并從數(shù)據(jù)庫引用。然后,它繼續(xù)以無序列表格式輸出它們。

將文章分享到..
日韩专区在线播放| 日韩在线观看视频网站| 91麻豆国产| 欧美爱爱网| 亚洲精品中文一区不卡| 久久精品店| 精品国产亚洲人成在线| 久久精品成人一区二区三区| 91麻豆国产级在线| 99热精品一区| 精品久久久久久免费影院| 亚洲第一页乱| 国产成+人+综合+亚洲不卡| 欧美日本韩国| 日本特黄特色aa大片免费| 欧美爱爱网| 久久国产精品只做精品| 亚洲第一页色| 91麻豆精品国产自产在线观看一区| 欧美18性精品| 国产一区精品| 日日夜人人澡人人澡人人看免| 国产一区精品| 国产原创中文字幕| 国产精品1024在线永久免费| 欧美电影免费看大全| 精品久久久久久免费影院| 精品久久久久久综合网| 黄视频网站在线观看| 久久精品欧美一区二区| 亚洲精品影院| 精品国产香蕉在线播出| 精品国产三级a| 免费一级片在线| 毛片电影网| 九九久久99综合一区二区| 日韩av东京社区男人的天堂| 四虎影视久久久| 日本在线不卡免费视频一区| 四虎影视久久久| 91麻豆精品国产片在线观看| 国产视频一区二区在线播放| 二级片在线观看| 国产国语对白一级毛片| 免费一级片在线观看| 毛片高清| 久久精品大片| 二级特黄绝大片免费视频大片| 99热热久久| 国产不卡高清| 九九免费精品视频| 国产视频久久久| 日本在线不卡免费视频一区| 四虎久久影院| 久久久成人影院| 久久国产一区二区| 精品国产亚一区二区三区| 免费一级生活片| 午夜精品国产自在现线拍| 欧美激情一区二区三区视频高清| 日韩一级黄色| 青青久久国产成人免费网站| 精品视频在线观看一区二区| 日本免费乱理伦片在线观看2018| 欧美α片无限看在线观看免费| 精品国产香蕉在线播出| 国产网站免费视频| 欧美一区二区三区在线观看| 99热精品在线| 国产麻豆精品| 精品久久久久久免费影院| 天天做日日爱夜夜爽| 欧美激情一区二区三区在线| 99热精品在线| 日韩av成人| 深夜做爰性大片中文| 日本免费看视频| 一级女性大黄生活片免费| 黄视频网站免费观看| 日韩av成人| 欧美1区| 99热热久久| 一级片片| 日韩男人天堂| 成人免费网站视频ww| 国产精品自拍在线观看| 久久国产影视免费精品| 午夜精品国产自在现线拍| 九九干| 久久精品道一区二区三区| 欧美1区2区3区| 久草免费在线观看| 久久久成人影院| 久久久久久久免费视频| 免费国产在线观看| 欧美另类videosbestsex高清 | 精品国产一区二区三区精东影业| 精品国产三级a∨在线观看| 日本久久久久久久 97久久精品一区二区三区 狠狠色噜噜狠狠狠狠97 日日干综合 五月天婷婷在线观看高清 九色福利视频 | 韩国三级视频网站| 国产成a人片在线观看视频| 精品视频一区二区三区| 深夜做爰性大片中文| 九九免费高清在线观看视频| 欧美激情一区二区三区在线 | 日韩综合| 亚洲精品久久玖玖玖玖| 国产91精品一区| 精品视频免费在线| a级黄色毛片免费播放视频| 青青久久国产成人免费网站| 日韩专区在线播放| 欧美a级大片| 国产a毛片| 天天做日日干| 欧美另类videosbestsex高清 | 精品视频在线观看一区二区| 久久精品道一区二区三区| 午夜在线亚洲| 二级特黄绝大片免费视频大片| 免费的黄视频| 99色视频| 黄视频网站免费看| 亚洲天堂免费| 国产91素人搭讪系列天堂| 九九久久99| 欧美夜夜骑 青草视频在线观看完整版 久久精品99无色码中文字幕 欧美日韩一区二区在线观看视频 欧美中文字幕在线视频 www.99精品 香蕉视频久久 | 一级片片| 成人免费网站久久久| 国产一区二区福利久久| 99热精品在线| 国产精品12| 天天做日日爱| 日韩在线观看视频黄| 色综合久久天天综线观看| 可以在线看黄的网站| 色综合久久手机在线| 91麻豆精品国产自产在线 | 国产伦理精品| 色综合久久手机在线| 香蕉视频三级| 精品国产一区二区三区久久久蜜臀| 精品久久久久久综合网| 国产不卡高清在线观看视频| 国产精品自拍亚洲| 欧美另类videosbestsex| 欧美a级片免费看| 国产伦精品一区二区三区无广告| 欧美一级视频免费| 麻豆网站在线看| 99色吧| 国产精品免费久久| 久久成人亚洲| 国产美女在线观看| 国产91素人搭讪系列天堂| 99热精品在线| 青草国产在线| 日韩综合| 国产精品1024永久免费视频 | 999久久狠狠免费精品| 欧美大片一区| 国产伦理精品| 黄视频网站在线观看| 精品视频在线看 | 日韩欧美一二三区| 成人在激情在线视频| 免费国产在线观看| 精品国产三级a| 国产美女在线观看| 国产91素人搭讪系列天堂| 国产精品自拍亚洲| 日韩免费在线| 国产视频一区二区三区四区| 欧美另类videosbestsex| 欧美激情一区二区三区视频| 青青青草视频在线观看| 精品在线免费播放| 成人av在线播放| 精品视频在线看 | 国产精品免费久久| 日本特黄特黄aaaaa大片| 中文字幕一区二区三区 精品| 日韩中文字幕一区| 999久久狠狠免费精品| 99热精品在线| 久久久久久久久综合影视网| 黄视频网站在线免费观看| 尤物视频网站在线| 成人a级高清视频在线观看| a级毛片免费观看网站| 日韩字幕在线| 欧美大片aaaa一级毛片| 久久精品欧美一区二区| 黄视频网站在线看| 精品视频免费在线| 青青青草影院 | 日本在线不卡免费视频一区| 国产高清在线精品一区a| 91麻豆精品国产自产在线观看一区 | 久久福利影视|