Location: PHPKode > projects > Bloggie Lite > genscode.php
<?php

// Copyright (C) Bloggie Lite Written by : Sean
// http://www.mywebland.com , http://mybloggie.mywebland.com

// You are requested to retain this copyright notice in order to use
// this software.

//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either version 2
//of the License, or (at your option) any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.


header("Pragma: no-cache");
header("Expires: 0");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);

define('IN_BLOGGIE', true);
$bloggie_root_path = './';

include_once($bloggie_root_path.'config.php');
include_once($bloggie_root_path.'includes/db.php');
include_once($bloggie_root_path.'includes/functions.php');
$pref_data = pref_data() ;
include_once($bloggie_root_path.'language/'.$pref_data['language']);
set_magic_quotes_runtime(0);

$user_ip = $_SERVER['REMOTE_ADDR'];
define('COMMENT_COOKIE', md5($user_ip));
if(isset($_COOKIE[COMMENT_COOKIE])) {

   $show_code ="";

   $chars = "ABCDEFGHJKMNPRSTUVWXYZ23456789";
   $len   = strlen($chars)-1;

   for($i=0;$i<5;$i++) {
      $randomcode = substr($chars,rand(0,$len),1);
      $show_code .= $randomcode;
   }

   $comment_cookie = $_COOKIE[COMMENT_COOKIE];

   $sql = "SELECT * FROM ".SCODE_TBL." WHERE cookie = '".$comment_cookie."'";
   if( !($result = $db->sql_query($sql)) ) {
       $sql_error = $db->sql_error();
        error($lang['Error'], 'SQL Query Error : '.$sql_error['message'].' !');
   }
   if( $db->sql_numrows($result)> 0 ) {
      $sqlupdate = "UPDATE ".SCODE_TBL." SET  scode='$show_code',  timestamp = '".time()."' WHERE cookie='$comment_cookie'";
      if( !($result = $db->sql_query($sqlupdate)) ) {
            $sql_error = $db->sql_error();
            error($lang['Error'], 'SQL Query Error : '.$sql_error['message'].' !');
      }
   } else {
      $sql = "INSERT INTO ".SCODE_TBL." SET cookie='$comment_cookie', scode='$show_code', timestamp='".time()."'";
      if( !($result = $db->sql_query($sql)) ) {
         $sql_error = $db->sql_error();
         error($lang['Error'], 'SQL Query Error : '.$sql_error['message'].' !');
      }
   }

   echo "<div  style=\" background:url(".$pref_data['bloggie_path']."/images/dot.png); border: 0px solid #c0c0c0; padding:5px; width:110px;
           font-size:20px; color:#000000; text-align: center; letter-spacing : 0.2em;\" ><b>".$show_code."</b></div>";
}  else  {
    echo "<span style=\"color:#ff0000;\">Cookies expired or Abnormal operation ! .<br />(a)Please try to refresh browser !<br />(b) Please allow your browser to accept cookies !</span>";
}

?>
Return current item: Bloggie Lite