📄 polerio.class.php
字号:
elseif(ereg("Opera", getenv("HTTP_USER_AGENT"))) $browser = "Opera";
elseif(ereg("MSIE", getenv("HTTP_USER_AGENT"))) $browser = "MSIE";
elseif(ereg("Lynx", getenv("HTTP_USER_AGENT"))) $browser = "Lynx";
elseif(ereg("WebTV", getenv("HTTP_USER_AGENT"))) $browser = "WebTV";
elseif(ereg("Konqueror", getenv("HTTP_USER_AGENT"))) $browser = "Konqueror";
elseif((eregi("bot", getenv("HTTP_USER_AGENT"))) || (ereg("Google", getenv("HTTP_USER_AGENT"))) || (ereg("Slurp", getenv("HTTP_USER_AGENT"))) || (ereg("Scooter", getenv("HTTP_USER_AGENT"))) || (eregi("Spider", getenv("HTTP_USER_AGENT"))) || (eregi("Infoseek", getenv("HTTP_USER_AGENT")))) $browser = "Bot";
else $browser = "Other";
return $browser;
}
function GetOS()
{
/* Get the Operating System data */
if(ereg("Win", getenv("HTTP_USER_AGENT"))) $os = "Windows";
elseif((ereg("Mac", getenv("HTTP_USER_AGENT"))) || (ereg("PPC", getenv("HTTP_USER_AGENT")))) $os = "Mac";
elseif(ereg("Linux", getenv("HTTP_USER_AGENT"))) $os = "Linux";
elseif(ereg("FreeBSD", getenv("HTTP_USER_AGENT"))) $os = "FreeBSD";
elseif(ereg("SunOS", getenv("HTTP_USER_AGENT"))) $os = "SunOS";
elseif(ereg("IRIX", getenv("HTTP_USER_AGENT"))) $os = "IRIX";
elseif(ereg("BeOS", getenv("HTTP_USER_AGENT"))) $os = "BeOS";
elseif(ereg("OS/2", getenv("HTTP_USER_AGENT"))) $os = "OS/2";
elseif(ereg("AIX", getenv("HTTP_USER_AGENT"))) $os = "AIX";
else $os = "Other";
return $os;
}
function TimeAndRandom()
{
/* * I've read about microtime() * I think it is more useful than calling the random * The purpose of this is just to make distinct number * Advantage, fixed distance in microtime. rand is not. * srand((double)microtime()*1000000); * return time().rand(); * */ $tim = microtime();
$mtime = substr($tim,11,10).substr($tim,2,8);
return $mtime;
}
function CheckEmailPassed($email="")
{
if (!eregi ("^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+\\.)+[a-z]{2,4}$", $email)) die ("Invalid Email");
}
function SessionGetVar($name)
{
global $HTTP_SESSION_VARS;
if(Polerio::PostNuke()) $var = "PNSV$name";
if(!Polerio::PostNuke()) $var = "PMLV$name";
global $$var;
if (!empty($$var)) {
return $$var;
} else return $var;
}
function SessionSetVar($name, $value)
{
$var = "PMLV$name";
if(Polerio::PostNuke()) $var = "PNSV$name";
global $$var;
$$var = $value;
session_register($var);
return true;
}
function VarPrepForStore()
{
$resarray = array();
foreach (func_get_args() as $ourvar) {
// Prepare var
if (!get_magic_quotes_runtime()) {
$ourvar = addslashes($ourvar);
}
// Add to array
array_push($resarray, $ourvar);
}
// Return vars
if (func_num_args() == 1) {
return $resarray[0];
} else {
return $resarray;
}
}
function Redirect($redirecturl)
{
if (preg_match('!^http!', $redirecturl)) {
// Absolute URL - simple redirect
Header("Location: $redirecturl");
return;
} else {
// Removing leading slashes from redirect url
$redirecturl = preg_replace('!^/*!', '', $redirecturl);
// Get base URL
$baseurl = Polerio::GetBaseURL();
Header("Location: $baseurl$redirecturl");
}
}
function SelectColor()
{
/* * Added sep 24, 2002 for use in selecting color * returns array bgcolor */ global $pmlconfig;
if($pmlconfig['PnThOver']!=0) {
$bgcolor[3] = $pmlconfig['bgcolor3'];
$bgcolor[2] = $pmlconfig['bgcolor2'];
$bgcolor[1] = $pmlconfig['bgcolor1'];
} else
{
global $bgcolor1,$bgcolor2,$bgcolor3;
$bgcolor[3] = $bgcolor3;
$bgcolor[2] = $bgcolor2;
$bgcolor[1] = $bgcolor1;
}
return $bgcolor;
}
function VarCleanFromInput()
{
/** * clean user input * <br> * Gets a global variable, cleaning it up to try to ensure that * hack attacks don't work * @param var name of variable to get * @param ... * @returns string/array * @return prepared variable if only one variable passed * in, otherwise an array of prepared variables */ $search = array('|</?\s*SCRIPT.*?>|si',
'|</?\s*FRAME.*?>|si',
'|</?\s*OBJECT.*?>|si',
'|</?\s*META.*?>|si',
'|</?\s*APPLET.*?>|si',
'|</?\s*LINK.*?>|si',
'|</?\s*IFRAME.*?>|si',
'|STYLE\s*=\s*"[^"]*"|si');
$replace = array('');
$resarray = array();
foreach (func_get_args() as $var) {
// Get var
global $$var;
if (empty($var)) {
return;
}
$ourvar = $$var;
if (!isset($ourvar)) {
array_push($resarray, NULL);
continue;
}
if (empty($ourvar)) {
array_push($resarray, $ourvar);
continue;
}
// Add to result array
array_push($resarray, $ourvar);
}
// Return vars
if (func_num_args() == 1) {
return $resarray[0];
} else {
return $resarray;
}
}
function SecGenAuthKey($modname='')
{
/* Added some security scripts do elimiante simultaneous send error which * cause to much delete, update, or insert */ /** * generate an authorisation key * <br> * The authorisation key is used to confirm that actions requested by a * particular user have followed the correct path. Any stage that an * action could be made (e.g. a form or a 'delete' button) this function * must be called and the resultant string passed to the client as either * a GET or POST variable. When the action then takes place it first calls * <code>pnSecConfirmAuthKey()</code> to ensure that the operation has * indeed been manually requested by the user and that the key is valid * * @public * @param modname the module this authorisation key is for (optional) * @returns string * @return an encrypted key for use in authorisation of operations */ if (empty($modname)) {
$modname = Polerio::VarCleanFromInput('module');
}
// Date gives extra security but leave it out for now
// $key = pnSessionGetVar('rand') . $modname . date ('YmdGi');
$key = Polerio::SessionGetVar('rand') . $modname;
// Encrypt key
$authid = md5($key);
// Return encrypted key
return $authid;
}
function SecConfirmAuthKey($authid='')
{
/** * confirm an authorisation key is valid * <br> * See description of <code>pnSecGenAuthKey</code> for information on * this function * @public * @returns bool * @return true if the key is valid, false if it is not */ // Regenerate static part of key
$partkey = Polerio::SessionGetVar('rand');
// Not using time-sensitive keys for the moment
// // Key life is 5 minutes, so search backwards and forwards 5
// // minutes to see if there is a match anywhere
// for ($i=-5; $i<=5; $i++) {
// $testdate = mktime(date('G'), date('i')+$i, 0, date('m') , date('d'), date('Y'));
//
// $testauthid = md5($partkey . date('YmdGi', $testdate));
// if ($testauthid == $authid) {
// // Match
//
// // We've used up the current random
// // number, make up a new one
// srand((double)microtime()*1000000);
// pnSessionSetVar('rand', rand());
//
// return true;
// }
// }
if ((md5($partkey)) == $authid) {
// Match - generate new random number for next key and leave happy
srand((double)microtime()*1000000);
Polerio::SessionSetVar('rand', rand());
return true;
}
// Not found, assume invalid
return false;
}
function SelectGID()
{
/** * To activate multi-admin capability * the program should get his/her gid or group id * The uid resides in the session */ $id = Polerio::SessionGetVar('uid');
$table = Polerio::DBGetTables();
$users = $table['users'];
$users_col = $table['users_column'];
list($dbconn) = Polerio::DBGetConn();
$sql="select $users_col[gid] from $users where $users_col[uid]=$id";
$recordSet = $dbconn->Execute($sql); return $recordSet->fields[0];
}
// taken from php.net
function _make_seed()
{
list($usec, $sec) = explode(' ', microtime());
return (float) $sec + ((float) $usec * 100000);
}
function makePass()
{
define('_SYLLABELS', "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789");
define('_MAKEPASS_LEN', 8);
define('_MAKEPASS_BOX', 5000);
// init some
$result = '';
mt_srand(Polerio::_make_seed());
$syllabels = _SYLLABELS;
$len = strlen($syllabels) - 1;
$box = "";
// create box
for($i = 0; $i < _MAKEPASS_BOX; $i++) {
$ch = $syllabels[mt_rand(0, $len)];
// about 20% upper case letters
if (mt_rand(0, $len) % 5 == 1) {
$ch = strtoupper($ch);
}
// filling up the box with random chars
$box .= $ch;
}
// now collect password from box
for($i = 0; $i < _MAKEPASS_LEN; $i++) {
$result .= $box[mt_rand(0, (_MAKEPASS_BOX - 1))];
}
return $result;
} }
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -