存档

文章标签 ‘验证码’

nginx配置反向代理使用discuz的时候无法加载验证码和安全问答

2018年6月22日 没有评论

今天配置nginx反向代理的时候,发现无法加载验证码和安全问答问题

经过研究和谷歌搜索,发现原来discuz会在头部判断用户来源

所以解决办法是在nginx的虚拟主机配置中加入:

proxy_pass_header User-Agent;

proxy_set_header Host $host;

这样才能正确加载discuz中的验证码和安全问题

如果你也遇到了在nginx中无法加载discuz中的验证码,请使用上方同样的方法,我列举一个虚拟主机的配置例子:

server {
listen 80;
server_name bbs.aaa.com;
location / {
proxy_pass http://bbs.aaa.com:82;
proxy_redirect http://bbs.aaa.com:82/ /;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass_header User-Agent;
proxy_set_header Host $host;

}
access_log logs/bbs.aaa.com.access.log;
}

php生成文件夹版验证码

2015年7月14日 没有评论

1,文件夹yzm.png

2,文件:confirmcode.class.php

3,文件:create.php

4,字体:font.ttf

5,文件:如何调用.php

——————————-

confirmcode.class.php:

<?php
header(‘Content-type:image/png’);
class imageCaptcha{
private $height;
private $width;
private $textNum;
private $textContent;
private $fontColor;
private $randFontColor;
private $fontSize;
private $fontFamily;
private $bgColor;
private $randBgColor;
private $textLang;
private $noisePoint;
private $noiseLine;
private $distortion;
private $distortionImage;
private $showBorder;
private $image;
public function imageCaptcha(){
$this->textNum=4;
$this->fontSize=15;
$this->fontFamily=”;
$this->textLang=’en’;
$this->noisePoint=0;
$this->noiseLine=0;
$this->distortion=false;
$this->showBorder=false;
}
public function set_show_mode($w,$h,$num,$fc,$fz,$ff_url,$lang,$bc,$m,$n,$b,$border){
$this->width=$w;
$this->height=$h;
$this->textNum=$num;
$this->fontColor=sscanf($fc,’#%2x%2x%2x’);
$this->fontSize=$fz;
$this->fontFamily=$ff_url;
$this->textLang=$lang;
$this->bgColor=sscanf($bc,’#%2x%2x%2x’);
$this->noisePoint=$m;
$this->noiseLine=$n;
$this->distortion=$b;
$this->showBorder=$border;
}
public function initImage(){
if(empty($this->width)){
$this->width=floor($this->fontSize*1.3)*$this->textNum+10;
}
if(empty($this->height)){
$this->height=floor($this->fontSize*2.5);
}
$this->image=imagecreatetruecolor($this->width,$this->height);
if(empty($this->bgColor)){
$this->randBgColor=imagecolorallocate($this->image,mt_rand(100,255),mt_rand(100,255),mt_rand(100,255));
}
else{
$this->randBgColor=imagecolorallocate($this->image,$this->bgColor[0],$this->bgColor[1],$this->bgColor[2]);
}
imagefill($this->image,0,0,$this->randBgColor);
}
public function randText($type){
$string=”;
switch($type){
case ‘en’:
$str=’ABCDEFGHJKLMNPQRSTVWXYabcdehkmnprsvwxy35678′;
for($i=0;$i<$this->textNum;$i++){
$string=$string.’,’.$str[mt_rand(0,42)];
}
break;
}
return substr($string,1);
}
public function createText(){
$text_array=explode(‘,’,$this->randText($this->textLang));
$this->textContent=join(”,$text_array);
if(empty($this->fontColor)){
$this->randFontColor=imagecolorallocate($this->image,mt_rand(0,100),mt_rand(0,100),mt_rand(0,100));
}
else{
$this->randFontColor=imagecolorallocate($this->image,$this->fontColor[0],$this->fontColor[1],$this->fontColor[2]);
}
for($i=0;$i<$this->textNum;$i++){
$angle=mt_rand(-1,1)*mt_rand(1,20);
imagettftext($this->image,$this->fontSize,$angle,8+$i*floor($this->fontSize*1.3),3+floor($this->height*0.75),$this->randFontColor,$this->fontFamily,$text_array[$i]);
}
}
public function createNoisePoint(){
for($i=0;$i<$this->noisePoint;$i++){
$pointColor=imagecolorallocate($this->image,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
imagesetpixel($this->image,mt_rand(0,$this->width),mt_rand(0,$this->height),$pointColor);
}
}
public function createNoiseLine(){
for($i=0;$i<$this->noiseLine;$i++){
$lineColor=imagecolorallocate($this->image,mt_rand(0,255),mt_rand(0,255),20);
imageline($this->image,0,mt_rand(0,$this->width),$this->width,mt_rand(0,$this->height),$lineColor);
}
}
public function distortionText(){
$this->distortionImage=imagecreatetruecolor($this->width,$this->height);
imagefill($this->distortionImage,0,0,$this->randBgColor);
for($x=0;$x<$this->width;$x++){
for($y=0;$y<$this->height;$y++){
$rgbColor=imagecolorat($this->image,$x,$y);
imagesetpixel($this->distortionImage,(int)($x+sin($y/$this->height*2*M_PI-M_PI*0.5)*3),$y,$rgbColor);
}
}
$this->image=$this->distortionImage;
}
public function createImage(){
$this->initImage();
$this->createText();
$this->createNoisePoint();
$this->createNoiseLine();
if($this->distortion!=false){
$this->distortionText();
}
if($this->showBorder){
imagerectangle($this->image,0,0,$this->width-1,$this->height-1,$this->randFontColor);
}
imagepng($this->image);
imagedestroy($this->image);
if($this->distortion!=false){
imagedestroy($this->distortionImage);
}
return $this->textContent;
}
}
$code_obj=new imageCaptcha();
$code_obj->set_show_mode(’85’,’30’,’4′,”,’15’,’font.ttf’,’en’,’#fcfefb’,mt_rand(5,10),mt_rand(1,3),false,false);
$code=$code_obj->createImage();
$f=fopen(‘code.txt’,”w”);
fwrite($f,strtolower($code));
fclose($f);
?>

——————————–

create.php:

<?php
//die(“closed”);
header(‘content-type:text/plain; charset=utf-8’);
set_time_limit(0);
for($i=1;$i<=20;$i++){
mkdir(‘yzm.png/’.$i);
for($k=1;$k<=50;$k++){
//获取图片
ob_start();
readfile(‘http://test.shiwufenzhong.com/create_yzm/confirmcode.class.php’);
$img=ob_get_contents();
ob_end_clean();
//获取验证码
$fp=fopen(‘code.txt’,”r”);
$code=fread($fp,1024);
fclose($fp);
//保存图片
$md5_code=hash(‘md5’,$code);
$md5_picname=substr(hash(‘md5’,$code.$i.$k),8,16);
$fp=fopen(‘yzm.png/’.$i.’/’.$md5_picname.’.png’,”w”);
fwrite($fp,$img);
fclose($fp);
//生成php文件夹
mkdir(‘yzm.png/’.$i.’/php’);
//生成php文件
$fp=fopen(‘yzm.png/’.$i.’/php/’.$k.’.php’,”w”);
fwrite($fp,”<?php \$yzm=array(‘pic’=>'”.$md5_picname.”‘,’key’=>'”.$md5_code.”‘);?>”);
fclose($fp);
}
}
die(“<h1>done …</h1>”);
?>

————————–

如何调用.php:

<?php
$yzmpngPath=mt_rand(1,20).’/’;
require(‘yzm.png/’.$yzmpngPath.’php/’.mt_rand(1,50).’.php’);
$session_id=$_POST[‘sessionid’];
if($session_id){
if(!preg_match(‘/^[a-zA-Z0-9]{26}$/’,$session_id)){exit();}
session_id($session_id);session_start();
}
else {session_start();$session_id=session_id();}
//请求超过3次的时候,以后每次请求间隔需要10秒
$new_session_n=intval($_SESSION[‘vanpeopleYZM’][‘requestNums’])+1;
if($new_session_n>4){
$time_line=$_SERVER[‘REQUEST_TIME’]-intval($_SESSION[‘vanpeopleYZM’][‘requestTime’]);
if($time_line<10){
echo json_encode(array(‘status’=>’error’,’errorStr’=>’速度过快,’.(10-$time_line).’秒后重试’,’fastCounterTime’=>10-$time_line,’sessionid’=>$session_id));
exit();
}
else {$new_session_n=1;}
}
$_SESSION[‘YZM’]=array(
‘key’=>$yzm[‘key’],’requestTime’=>$_SERVER[‘REQUEST_TIME’],’requestNums’=>$new_session_n
);
echo json_encode(
array(
‘status’=>’ok’,’sessionid’=>$session_id,’pic’=>$yzmpngPath.$yzm[‘pic’],’key’=>$yzm[‘key’]
)
);exit();
?>

 

分类: php学习 标签:

discuz论坛地址栏带端口号的解决方法【nginx+apache验证码不显示】

2014年12月24日 没有评论

我们往往会使用nginx+apache来作为服务器环境,nginx使用80端口,Apache使用82端口,那么当我们安装discuz的时候,在加入了nginx映射到Apache端口后,往往discuz的链接地址栏上会出现端口号,如82

那么我们如何解决这个问题呢?

x2寻找文件source/class/class_core.php,寻找:$_G[‘siteport’]

将此行注释即可,或者强制在此文件的头部,加上:$_SERVER[‘HTTP_HOST’]=”www.域名.com”;

到此就可以解决discuz论坛地址栏带端口号的解决方法【nginx+apache反射】,但是x2.5是修改:

source/class/discuz/discuz_application.php

————————–

但是你会发现另外一个问题,就是验证码不能正确显示,解决办法如下:

直接在config/config_global.php下增加$_SERVER[‘HTTP_HOST’]=”www.域名.com”;即可解决所有问题

研究半天实在搞不定,原来还有此绝招~

 

php生成验证码类【还不错】

2014年12月11日 没有评论

<?php
session_start();
header(‘Content-type:image/png’);
$serverTime = $_SERVER[‘REQUEST_TIME’];
if ($_SESSION[‘confirmCode’][‘errorTimes’] > 8 && $serverTime – $_SESSION[‘confirmCode’][‘time’] < 20) {
$_SESSION[‘confirmCode’][‘code’] = ‘whatabadman!’;
$img_file = ‘yzmBad.gif’;
$fp = fopen($img_file, ‘rb’);
$content = fread($fp, filesize($img_file));
fclose($fp);
echo $content;
} else {
if ($_SESSION[‘confirmCode’][‘errorTimes’] > 8) {
$_SESSION[‘confirmCode’][‘errorTimes’] = 1;
} else {
$_SESSION[‘confirmCode’][‘errorTimes’] = intval($_SESSION[‘confirmCode’][‘errorTimes’]) + 1;
}
}
class imageCaptcha
{
private $height;
private $width;
private $textNum;
private $textContent;
private $fontColor;
private $randFontColor;
private $fontSize;
private $fontFamily;
private $bgColor;
private $randBgColor;
private $textLang;
private $noisePoint;
private $noiseLine;
private $distortion;
private $distortionImage;
private $showBorder;
private $image;
public function imageCaptcha()
{
$this->textNum = 4;
$this->fontSize = 14;
$this->fontFamily = ”;
$this->textLang = ‘en’;
$this->noisePoint = 0;
$this->noiseLine = 0;
$this->distortion = false;
$this->showBorder = false;
}
public function set_show_mode($w, $h, $num, $fc, $fz, $ff_url, $lang, $bc, $m, $n, $b, $border)
{
$this->width = $w;
$this->height = $h;
$this->textNum = $num;
$this->fontColor = sscanf($fc, ‘#%2x%2x%2x’);
$this->fontSize = $fz;
$this->fontFamily = $ff_url;
$this->textLang = $lang;
$this->bgColor = sscanf($bc, ‘#%2x%2x%2x’);
$this->noisePoint = $m;
$this->noiseLine = $n;
$this->distortion = $b;
$this->showBorder = $border;
}
public function initImage()
{
if (empty($this->width)) {
$this->width = floor($this->fontSize * 1.3) * $this->textNum + 10;
}
if (empty($this->height)) {
$this->height = floor($this->fontSize * 2.5);
}
$this->image = imagecreatetruecolor($this->width, $this->height);
if (empty($this->bgColor)) {
$this->randBgColor = imagecolorallocate($this->image, mt_rand(100, 255), mt_rand(100, 255), mt_rand(100, 255));
} else {
$this->randBgColor = imagecolorallocate($this->image, $this->bgColor[0], $this->bgColor[1], $this->bgColor[2]);
}
imagefill($this->image, 0, 0, $this->randBgColor);
}
public function randText($type)
{
$string = ”;
switch ($type) {
case ‘en’:
$str = ‘ABCDEFGHJKLMNPQRSTVWXYabcdehkmnprsvwxy35678’;
for ($i = 0; $i < $this->textNum; $i++) {
$string = $string . ‘,’ . $str[mt_rand(0, 42)];
}
break;
}
return substr($string, 1);
}
public function createText()
{
$text_array = explode(‘,’, $this->randText($this->textLang));
$this->textContent = join(”, $text_array);
if (empty($this->fontColor)) {
$this->randFontColor = imagecolorallocate($this->image, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
} else {
$this->randFontColor = imagecolorallocate($this->image, $this->fontColor[0], $this->fontColor[1], $this->fontColor[2]);
}
for ($i = 0; $i < $this->textNum; $i++) {
$angle = mt_rand(-1, 1) * mt_rand(1, 20);
imagettftext($this->image, $this->fontSize, $angle, 5 + $i * floor($this->fontSize * 1.3), floor($this->height * 0.75), $this->randFontColor, $this->fontFamily, $text_array[$i]);
}
}
public function createNoisePoint()
{
for ($i = 0; $i < $this->noisePoint; $i++) {
$pointColor = imagecolorallocate($this->image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
imagesetpixel($this->image, mt_rand(0, $this->width), mt_rand(0, $this->height), $pointColor);
}
}
public function createNoiseLine()
{
for ($i = 0; $i < $this->noiseLine; $i++) {
$lineColor = imagecolorallocate($this->image, mt_rand(0, 255), mt_rand(0, 255), 20);
imageline($this->image, 0, mt_rand(0, $this->width), $this->width, mt_rand(0, $this->height), $lineColor);
}
}
public function distortionText()
{
$this->distortionImage = imagecreatetruecolor($this->width, $this->height);
imagefill($this->distortionImage, 0, 0, $this->randBgColor);
for ($x = 0; $x < $this->width; $x++) {
for ($y = 0; $y < $this->height; $y++) {
$rgbColor = imagecolorat($this->image, $x, $y);
imagesetpixel($this->distortionImage, (int) ($x + sin($y / $this->height * 2 * M_PI – M_PI * 0.5) * 3), $y, $rgbColor);
}
}
$this->image = $this->distortionImage;
}
public function createImage()
{
$this->initImage();
$this->createText();
$this->createNoisePoint();
$this->createNoiseLine();
if ($this->distortion != false) {
$this->distortionText();
}
if ($this->showBorder) {
imagerectangle($this->image, 0, 0, $this->width – 1, $this->height – 1, $this->randFontColor);
}
imagepng($this->image);
imagedestroy($this->image);
if ($this->distortion != false) {
imagedestroy($this->distortionImage);
}
return $this->textContent;
}
}
$code_obj = new imageCaptcha();
$code_obj->set_show_mode(’85’, ’30’, ‘4’, ”, ’14’, ‘font/’ . rand(1, 6) . ‘.ttf’, ‘en’, ‘#fcfefb’, mt_rand(5, 10), mt_rand(1, 3), false, false);
$_SESSION[‘confirmCode’][‘code’] = $code_obj->createImage();
$_SESSION[‘confirmCode’][‘time’] = $serverTime;

?>

分类: php学习 标签:

nginx配置反向代理使用discuz的时候无法加载验证码和安全问答

2013年8月20日 没有评论

今天配置nginx反向代理的时候,发现无法加载验证码和安全问答问题

经过研究和谷歌搜索,发现原来discuz会在头部判断用户来源

所以解决办法是在nginx的虚拟主机配置中加入:

proxy_pass_header User-Agent;

proxy_set_header Host $host;

这样才能正确加载discuz中的验证码和安全问题

如果你也遇到了在nginx中无法加载discuz中的验证码,请使用上方同样的方法,我列举一个虚拟主机的配置例子:

 

server {
listen       80;
server_name  bbs.aaa.com;
location / {
proxy_pass              http://bbs.aaa.com:82;
proxy_redirect          http://bbs.aaa.com:82/ /;
proxy_set_header        X-Real-IP       $remote_addr;
proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass_header User-Agent;
proxy_set_header Host $host;

}
access_log  logs/bbs.aaa.com.access.log;
}

css.php