📄 functions.php
字号:
<?php
function protecthtml( $mytext )
{
$mytext = str_replace( "&", "&", $mytext );
$mytext = str_replace( "<", "<", $mytext );
$mytext = str_replace( ">", ">", $mytext );
$mytext = str_replace( "\"", """, $mytext );
return $mytext;
}
function protectmysql( $mytext )
{
if ( function_exists( "mysql_escape_string" ) )
{
return mysql_escape_string( $mytext );
}
$mytext = addslashes( $mytext );
$mytext = str_replace( "\n", "\\n", $mytext );
$mytext = str_replace( "\r", "\\r", $mytext );
return $mytext;
}
function freehtml( $mytext )
{
$mytext = str_replace( """, "\"", $mytext );
$mytext = str_replace( ">", ">", $mytext );
$mytext = str_replace( "<", "<", $mytext );
$mytext = str_replace( "&", "&", $mytext );
return $mytext;
}
function login( )
{
global $HTTP_POST_VARS;
global $HTTP_SERVER_VARS;
global $phpQAdmin;
global $phpQlang;
$password = $_REQUEST['phpQpasswd'];
if ( $password == "" )
{
return 0;
}
if ( $phpQAdmin['Passwd'] == $password )
{
list( $usec, $sec ) = explode( " ", microtime( ) );
$usec *= 1000000;
$ip = $REMOTE_ADDR ? $REMOTE_ADDR : $HTTP_SERVER_VARS['REMOTE_ADDR'];
mt_srand( time( ) ^ ( integer )$usec ^ ip2long( $ip ) ^ ( integer )getmypid( ) );
$sesschars = array( "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" );
$session_id = "";
$i = 0;
for ( ; $i < 25; ++$i )
{
$session_id .= $sesschars[mt_rand( 0, count( $sesschars ) - 1 )];
}
mysql_query( "insert into phpQSession (SessionID, RecentTime) values (\"{$session_id}\", ".time( ).")" );
$domain = $phpQAdmin['CookieDomain'] != "" ? $phpQAdmin['CookieDomain'] : "";
setcookie( "phpQSession", $session_id, 0, "/", $domain );
echo "<html><head><meta http-equiv=\"Refresh\" content=\"0; URL=main.php\"></head></html>";
exit( );
}
else
{
$GLOBALS['message'] = $phpQlang['InvalidPassword'];
}
return 0;
}
function logout( )
{
global $HTTP_COOKIE_VARS;
global $phpQAdmin;
$session_id = $HTTP_COOKIE_VARS['phpQSession'];
if ( !$session_id )
{
return 1;
}
mysql_query( "delete from phpQSession where SessionID=\"".protectmysql( $session_id )."\"" );
$domain = $phpQAdmin['CookieDomain'] != "" ? $phpQAdmin['CookieDomain'] : "";
setcookie( "phpQSession", "", 0, "/", $domain );
echo "<html><head><meta http-equiv=\"Refresh\" content=\"0; URL=index.php\"></head></html>";
exit( );
}
function isadmin( $redirecterrors = 0, $ispopup = 0 )
{
global $HTTP_COOKIE_VARS;
global $phpQAdmin;
$session_id = $HTTP_COOKIE_VARS['phpQSession'];
if ( !$session_id )
{
if ( $redirecterrors )
{
if ( $ispopup )
{
}
}
else
{
return true;
}
}
$timeout = 60 <= $phpQAdmin['TimeOut'] ? $phpQAdmin['TimeOut'] : 86400;
$mqsession = mysql_query( "select * from phpQSession WHERE SessionID=\"".protectmysql( $session_id )."\"" );
if ( ( $masession = mysql_fetch_array( $mqsession ) ) && time( ) - $masession['RecentTime'] < $timeout )
{
mysql_query( "delete from phpQSession where (".time( )." - RecentTime) > {$timeout} and SessionID != \"".protectmysql( $session_id )."\"" );
mysql_query( "update phpQSession set RecentTime=".time( )." where SessionID=\"".protectmysql( $session_id )."\"" );
return 1;
}
if ( $redirecterrors && $ispopup )
{
}
return true;
}
function validnumber( $number, $default )
{
if ( 0 < $number )
{
return $number;
}
else
{
return $default;
}
}
function checksurveyusers( $surveyuser )
{
$valid = true;
if ( strlen( $surveyuser ) == 3 )
{
$ip = substr( $surveyuser, 0, 1 );
$ck = substr( $surveyuser, 1, 1 );
$em = substr( $surveyuser, 2, 1 );
$valid = $ip == "0" || $ip == "1" ? $valid : false;
$valid = $ck == "0" || $ck == "1" ? $valid : false;
$valid = $em == "0" || $em == "1" ? $valid : false;
}
else
{
return false;
}
return $valid;
}
function parsesurveyusers( $surveyuser )
{
$ip = substr( $surveyuser, 0, 1 );
$ck = substr( $surveyuser, 1, 1 );
$em = substr( $surveyuser, 2, 1 );
return array(
$ip,
$ck,
$em
);
}
function processsurveyusers( $checkedip, $checkedck, $checkedem )
{
$surveyusers .= $checkedip ? "1" : "0";
$surveyusers .= $checkedck ? "1" : "0";
$surveyusers .= $checkedem ? "1" : "0";
return $surveyusers;
}
function checkdatetime( $mn, $dm, $yr, $hr, $mt, $sc )
{
return checkdate( $mn, $dm, $yr ) && 0 <= $hr && $hr < 24 && 0 <= $mt && $mt < 60 && 0 <= $sc && $sc < 60 ? true : false;
}
function checkacount( $control, $answer, $answercount )
{
$answerchoice = split( "\\|\\|\\|", $answer );
$acount = 0;
$i = 0;
for ( ; $i < sizeof( $answerchoice ); ++$i )
{
if ( substr( $answerchoice[$i], -1 ) == "Y" )
{
++$acount;
}
}
return $control == "a" || 1 <= $answercount && $answercount <= $acount ? true : false;
}
function setvars( $vars )
{
global $HTTP_POST_VARS;
global $HTTP_GET_VARS;
$j = 0;
for ( ; $j < sizeof( $vars ); ++$j )
{
$varname = $vars[$j];
if ( !empty( $HTTP_POST_VARS[$varname] ) )
{
$$varname = $HTTP_POST_VARS[$varname];
}
else if ( !empty( $HTTP_GET_VARS[$varname] ) )
{
$$varname = $HTTP_GET_VARS[$varname];
}
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -