2.核心代码
显示的逻辑:
//获取防止刷新的唯一标识符,start
$intFlag = substr(md5(time()),6);
$strFlag = 'BAOXIAOSS_'.$my_user_id.$intFlag;
$smarty->assign('check_is_agin_post', $strFlag);
//获取防止刷新的唯一标识符,end
注意:前端页面提交加入这个变量。
下面是提交的逻辑
//校验是否重复提交,start
if(!empty($post_data['check_is_agin_post']))
{
$check_is_agin_post = $_COOKIE[$post_data['check_is_agin_post']];
if(!empty($check_is_agin_post))
{
die('提交重复');
}
setcookie($post_data['check_is_agin_post'], 1, time()+10);
}
//校验是否重复提交,end
$request_url = db_url::getRequestUrlData();
$links = array(
array('href' =>$request_url['HTTP_REFERER'], 'text' => '返回')
);
3.类的方法
<?php
class db_url
{
static public $status_arr = array(
);
//获取请求的url
static function getRequestUrl()
{
//获取当前完整url,为了清晰,多定义几个变量,分几行写
$scheme = $_SERVER['REQUEST_SCHEME']; //协议
$domain = $_SERVER['HTTP_HOST']; //域名/主机
$requestUri = $_SERVER['REQUEST_URI']; //请求参数
//将得到的各项拼接起来
$currentUrl = $scheme . "://" . $domain . $requestUri;
return $currentUrl; //传回当前url
}
//返回请求URl的多个数据
static function getRequestUrlData()
{
//获取当前完整url,为了清晰,多定义几个变量,分几行写
$scheme = $_SERVER['REQUEST_SCHEME']; //协议
$domain = $_SERVER['HTTP_HOST']; //域名/主机
$requestUri = $_SERVER['REQUEST_URI']; //请求参数
//将得到的各项拼接起来
$currentUrl = $scheme . "://" . $domain . $requestUri;
$return_data = [
'REQUEST_SCHEME'=>$_SERVER['REQUEST_SCHEME'],
'HTTP_HOST'=>$_SERVER['HTTP_HOST'],
'HTTP_REFERER'=>$_SERVER['HTTP_REFERER'],
'REQUEST_URI'=>$_SERVER['REQUEST_URI'],
'url'=>$currentUrl,
];
return $return_data; //传回当前url
}
//获取url的参数返回数组
static function getParams($url)
{
$arr = parse_url($url);
$arr_query = self::convertUrlQuery($arr['query']);
return $arr_query?$arr_query:[];
}
static function convertUrlQuery($query)
{
$queryParts = explode('&', $query);
$params = array();
foreach ($queryParts as $param) {
$item = explode('=', $param);
$params[$item[0]] = $item[1];
}
return $params;
}
/**
* 将参数变为字符串
* @param $array_query
* @return string string 'm=content&c=index&a=lists&catid=6&area=0&author=0&h=0®ion=0&s=1&page=1' (length=73)
*/
static function getUrlQuery($array_query)
{
$tmp = array();
foreach($array_query as $k=>$param)
{
$tmp[] = $k.'='.$param;
}
$params = implode('&',$tmp);
return $params;
}
}
?>