12c04-2.php

来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 34 行

PHP
34
字号
<?php// This is our include file.  Include it on every page in your website, and//  it handles tracking the user for you.  Start by opening our session...session_start();// If the additional id is not present, then this is a new session.  //  Generate a 40 character unique identifier using the function created //  in Listing 1.11. This combined with the session id, with hope to serve//  as a TRUE unique ID.$refer = 'NULL';if (!isset($_SESSION['addid'])) {    $_SESSION['addid'] = sha1($_SERVER['HTTP_USER_AGENT'] .         $_SERVER['REMOTE_ADDR'] . time() . rand());        // Also, since this is the 'first visit', let's store the referrer    $refer = "'{$_SERVER['HTTP_REFERER']}'";}// Open a database connection (Update these with your own DB server info)$db = mysql_connect('localhost', 'my_user', 'my_password')     or die('DB Failure: ' . mysql_error());mysql_select_db('my_database');// Do the insert:$sid = session_id();mysql_query("    insert into web_tracker        (session, addid,          url, refer)    values        ('{$sid}', '{$_SESSION['addid']}',          '{$_SERVER['REQUEST_URI']}', {$refer})    ");?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?