1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 04:38:27 +01:00
php-e107/e107_handlers/secure_img_handler.php

72 lines
1.9 KiB
PHP
Raw Normal View History

2006-12-02 04:36:16 +00:00
<?php
/*
2009-11-12 15:11:17 +00:00
* e107 website system
*
2009-11-18 01:06:08 +00:00
* Copyright (C) 2008-2009 e107 Inc (e107.org)
2009-11-12 15:11:17 +00:00
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
*
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/secure_img_handler.php,v $
2010-02-10 18:18:01 +00:00
* $Revision$
* $Date$
* $Author$
2009-11-12 15:11:17 +00:00
*/
2006-12-02 04:36:16 +00:00
if (!defined('e107_INIT')) { exit; }
class secure_image {
var $random_number;
function secure_image() {
list($usec, $sec) = explode(" ", microtime());
$this->random_number = str_replace(".", "", $sec.$usec);
}
function create_code() {
global $pref, $sql, $IMAGES_DIRECTORY, $HANDLERS_DIRECTORY;
/*
2006-12-02 04:36:16 +00:00
require_once('e107_class.php');
$e107 = new e107(false, false);
$e107->set_paths();
$imgpy = str_replace($HANDLERS_DIRECTORY, "", $e107->file_path);
*/
$imgp = dirname(__FILE__);
if (substr($imgp,-1,1) != '/') $imgp .= '/';
if (!isset($HANDLERS_DIRECTORY)) require_once($imgp.'../e107_config.php');
$imgp = str_replace($HANDLERS_DIRECTORY,$IMAGES_DIRECTORY,$imgp);
2006-12-02 04:36:16 +00:00
mt_srand ((double)microtime() * 1000000);
$maxran = 1000000;
$rand_num = mt_rand(0, $maxran);
$datekey = date("r");
$rcode = hexdec(md5($_SERVER['HTTP_USER_AGENT'] . serialize($pref). $rand_num . $datekey));
$code = substr($rcode, 2, 6);
$recnum = $this->random_number;
$del_time = time()+1200;
$sql->db_Insert("tmp", "'{$recnum}',{$del_time},'{$code},{$imgp}'");
return $recnum;
}
function verify_code($rec_num, $checkstr) {
global $sql, $tp;
if ($sql->db_Select("tmp", "tmp_info", "tmp_ip = '".$tp -> toDB($rec_num)."'")) {
$row = $sql->db_Fetch();
$sql->db_Delete("tmp", "tmp_ip = '".$tp -> toDB($rec_num)."'");
2009-04-21 08:22:21 +00:00
list($code, $path) = explode(",", $row['tmp_info']);
2006-12-02 04:36:16 +00:00
return ($checkstr == $code);
}
return FALSE;
}
function r_image() {
global $HANDLERS_DIRECTORY;
$code = $this->create_code();
2009-04-21 08:22:21 +00:00
return "<img src='".e_HTTP.$HANDLERS_DIRECTORY."secure_img_render.php?{$code}' class='icon secure-image' alt='' />";
2006-12-02 04:36:16 +00:00
}
}
?>