概述view sourceprint?01.<?php02./*03. [UCenter Home] (C) 2007-2008 Comsenz Inc.04. $Id: function_common.php 2009-10-20 21:12:0005. @author ymaozi06. @copyright http://www.codedesign.cn/07. @uchome源码交流QQ群:8340026308.*/09. 10.if(!defined('IN_UCHOME')) {11. exit('Access Denied');12.}13./**14. * SQL ADDSLASHES 对sql的一些字符进行转义15. * @param string or array $string16. * @return string or array17. */18.function saddslashes($string) {19. if(is_array($string)) { //如果转入的是数组则对数组中的value进行递归转义20. foreach($string as $key => $val) {21. $string[$key] = saddslashes($val);22. }23. } else {24. $string = addslashes($string); //对单引号(')、双引号(")、反斜线()与 NUL(NULL 字符),进行转义25. }26. return $string;27.}28. 29./**30. * 取消HTML
代码31. * @param string or array $string32. * @return string or array33. */34.function shtmlspecialchars($string) {35. if(is_array($string)) {36. foreach($string as $key => $val) {37. $string[$key] = shtmlspecialchars($val);38. }39. } else {40. $string = preg_replace('/&((#(d{3,5}|x[a-fA-F0-9]{4})|[a-zA-Z][a-z0-9]{2,5});)/', '&\1',41. str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '>'), $string));//将传入的html中的&,",<,>,进行替换42. }43. return $string;44.}view sourceprint?001./**002. * 清空cookie与一些判断用户登录的信息003. */004.function clearcookie() {005. global $_SGLOBAL;006. 007. obclean(); //清除缓存008. ssetcookie('auth', '', -86400 * 365); //设置cookie名为auth的过期009. $_SGLOBAL['supe_uid'] = 0;010. $_SGLOBAL['supe_username'] = '';011. $_SGLOBAL['member'] = array(); //将这些全局变量清空012.}013. 014.//cookie设置015./**016. * 设置cookie017. * @param string cookie名018. * @param string cookie值019. * @param int cookie存储时间020. * @return void021. */022.function ssetcookie($var, $value, $life=0) {023. global $_SGLOBAL, $_SC, $_SERVER;024. setcookie($_SC['cookiepre'].$var, $value, $life?($_SGLOBAL['timestamp']+$life):0, $_SC['cookiepath'], $_SC['cookiedomain'], $_SERVER['SERVER_PORT']==443?1:0);025.}026. 027.//028./**029. * 创建数据库连接对象030. */031.function dbconnect() {032. global $_SGLOBAL, $_SC;033. 034. include_once(S_ROOT.'./source/class_mysql.php'); //引入数据库 *** 作类035. 036. if(empty($_SGLOBAL['db'])) { //如果没有创建数据库对象,则创建037. $_SGLOBAL['db'] = new dbstuff;038. $_SGLOBAL['db']->charset = $_SC['dbcharset'];039. $_SGLOBAL['db']->connect($_SC['dbhost'], $_SC['dbuser'], $_SC['dbpw'], $_SC['dbname'], $_SC['pconnect']);040. }041.}042. 043.//获取在线IP044.function getonlineip($format=0) {045. global $_SGLOBAL;046. 047. if(empty($_SGLOBAL['onlineip'])) {048. if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {049. //如果存在客户端ip,并通过strcasecmp(),比较不等于unknown,则获取客户端ip050. $onlineip = getenv('HTTP_CLIENT_IP');051. } elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {052. //如果存在代理ip,则获取代理ip053. $onlineip = getenv('HTTP_X_FORWARDED_FOR');054. } elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {055. //代理服务器 IP056. $onlineip = getenv('REMOTE_ADDR');057. } elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {058. $onlineip = $_SERVER['REMOTE_ADDR'];059. }060. preg_match("/[d.]{7,15}/", $onlineip, $onlineipmatches);061. //通过正则检验,是否是ip地址的格式062. $_SGLOBAL['onlineip'] = $onlineipmatches[0] ? $onlineipmatches[0] : 'unknown';063. }064. if($format) {065. $ips = explode('.', $_SGLOBAL['onlineip']); //将ip地址,以.为分隔存入到数组066. for($i=0;$i<3;$i++) {067. $ips[$i] = intval($ips[$i]);068. }069. return sprintf('%03d%03d%13d', $ips[0], $ips[1], $ips[2]);//返回ip地十的前三段,03d:三位整数,如果不足刚以0填充070. } else {071. return $_SGLOBAL['onlineip'];072. }073.}074. 075.//076./**077. * 判断当前用户登录状态078. */079.function checkauth() {080. global $_SGLOBAL, $_SC, $_SCONFIG, $_SCOOKIE, $_SN;081. 082. if($_SGLOBAL['mobile'] && $_GET['m_auth']) $_SCOOKIE['auth'] = $_GET['m_auth'];083. if($_SCOOKIE['auth']) { //如果设置了名了auth的cookie084. @list($password, $uid) = explode("t", authcode($_SCOOKIE['auth'], 'DECODE')); //通过authcode()
函数将加密过的auth进行解密,将解密的信息分别存在$password与$uid中085. $_SGLOBAL['supe
<div ID="Highlighter_359317">
<div >
<div >
<a title="view source" href="http://www.codedesign.cn/?p=100#viewSource" target="_blank" highlighterid="highlighter_359317" commandname="viewSource">view source<a title="print" href="http://www.codedesign.cn/?p=100#printSource" target="_blank" highlighterid="highlighter_359317" commandname="printSource">print<a title="?" href="http://www.codedesign.cn/?p=100#about" target="_blank" highlighterid="highlighter_359317" commandname="about">?
'
,进行替换
charset =
connect(
query(
fetch_array(
query(
fetch_array(
总结
以上是内存溢出为你收集整理的UCHome中关于公共函数(function_common.php)页面的代码分析(一)全部内容,希望文章能够帮你解决UCHome中关于公共函数(function_common.php)页面的代码分析(一)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
评论列表(0条)