smarty结合xajax检测用户名简单实例
<?php
/*****************************************
Title :smarty结合xajax检测用户名简单实例
Author:leehui1983(辉老大)
Finish Date :2006-12-09
*****************************************/
//为避免中文乱码,需要在 xajax.inc.php 需要改一下默认的encoding:define ('XAJAX_DEFAULT_CHAR_ENCODING', 'gbk' )UTF8编码格式文件不需要更改
require_once('./libs/Smarty.class.php');//包含smarty类库
require('./xajax/xajax.inc.php');//包含xajax类库
function checkusername($textvalue){//编写需要的PHP函数
$checkresult=($textvalue=='test' ? '<font color=red>该用户名已经注册</font>' :'<font color=red>可以注册</font>');
$objresponse=new xajaxResponse();//实例化xajaxresponse对象
$objresponse->addassign("result","innerHTML",$checkresult);//指定ID为result的元素中添加内容$checkresult
return $objresponse;//返回结果文本
}
$xajax=new xajax();//实例化xajax对象
$smarty=new Smarty();//实例化smarty对象
$smarty->template_dir = "./templates";//设置模板目录
$smarty->compile_dir = "./templates_c"; //设置编译目录
$smarty->caching = false; //设置缓存方式
/*****************************************************
左右边界符,默认为{},但实际应用当中容易与JavaScript
相冲突,所以建议设成<{}>或其它。
*****************************************************/
$smarty->left_delimiter = "<{";
$smarty->right_delimiter = "}>";
$xajax->registerFunction("checkusername");//注册checkusername函数
$xajax->processRequests();//调用xajax用于接管请求
$smarty->assign('xajax_javascript', $xajax->getJavascript('./xajax/'));//输出JS代码,注意('./xajax/')中参数为xajax.inc.php父目录,在同意目录下可不同填写,否则必须填写
$smarty->assign('title','smarty结合xajax检测用户名简单实例');//替换模板内容
$smarty->display('index.tpl');//显示模板内容
?>
<html>
<head>
<title><{$title}></title>
<{$xajax_javascript}><{*使smarty支持xajax*}>
</head>
<body>
<form name="check" >
请输入用户名:
<input type="text" name="username" />
<input type="button" name="button" value="检查用户名" />
<div id="result"></div>
</form>
</body>
</html>
php fck文章分页 fckeditor文章分页代码
<?php
$page =isset($_GET['page'])?$_GET['page']:1;//这里了得当前文章的分页编号如果没有就为1
$split ='<div style="page-break-after: always"><span style="display: none"> </span></div>';
//这里是fckeditor文章的分页代码
$array =explode($split,$rs->new_content);
if($page>sizeof($array) ){//判断从地址栏获得的分页编号是不是大于总分页的长度,如果是就输出第一页的内容
echo $array[0];
}else{
echo $array[$page-1];//不是就输出$page-1这里因为php函数的下标是从0开始的
}
if(sizeof($array)>1){ //这里是判断如果文章没有分页就不显示第N页,
for($i=1;$i<=sizeof($array);$i++){
echo "<a href=?id=$type_id&page=".$i.">[".$i."页]</a> ";
}
}
?>
原创文章:www.111cn.net 转载请注明
<?
$conn=mysql_connect("localhost","root","2328725");
mysql_select_db("novel");
mysql_query("set names 'utf8'");
if($provincecode!=""&&$provincecode!=650000&&$provincecode!=710000&&$provincecode!=810000&&$provincecode!=820000&&$provincecode!=110000&&$provincecode!=120000&&$provincecode!=310000&&$provincecode!=500000){
$sql="select * from city where provincecode=$provincecode";
$result=mysql_query($sql);
echo "<select onchange='queryArea(this.options[this.selectedIndex].value)'>\n";
echo "<option value='-1' selected>请选择城市</option>\n";
while($row=mysql_fetch_row($result)){
echo "<option value='$row[1]'>$row[2]</option>\n";
}
echo "</select>\n";
}
if($citycode!=""){
$sql="select * from area where citycode=$citycode";
$result=mysql_query($sql);
echo "<select>\n";
echo "<option value='-1' selected>请选择县</option>\n";
while($row=mysql_fetch_row($result)){
echo "<option value='$row[1]'>$row[2]</option>\n";
}
echo "</select>\n";
}
?>
<html>
<head>
<meta http-equiv="Content-Type" c />
<script type="text/javascript">
var xmlHttp;
var requestType="";
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();
}
}
function queryCity(citycode){
createXMLHttpRequest();
type="city";
var url="data.php?provincecode="+citycode;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.send(null);
}
function queryArea(citycode){
createXMLHttpRequest();
type="area";
var url="data.php?citycode="+citycode;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.send(null);
}
function handleStateChange(){
if(xmlHttp.readystate==4){
if(xmlHttp.status==200){
if(type=="city"){
showcity();
}else if(type="area"){
showarea();
}
}
}
}
function showcity(){
document.getElementById("city").innerHTML=xmlHttp.responseText;
document.getElementById("area").innerHTML="";
}
function showarea(){
document.getElementById("area").innerHTML=xmlHttp.responseText;
}
</script>
</head>
<body>
<?
$conn=mysql_connect("localhost","root","2328725");
mysql_select_db("novel");
mysql_query("set names 'utf8'");
$sql="select * from province";
$result=mysql_query($sql);
echo "<from id='form1'>\n";
echo "<select id='province' onchange='queryCity(this.options[this.selectedIndex].value)'>\n";
echo "<option value='-1' selected>请选择省份</option>\n";
while($row=mysql_fetch_row($result)){
echo "<option value='$row[1]'>$row[2]</option>\n";
}
echo "</select>\n";
echo "<span id='city'></span>\n";
echo "<span id='area'></span>\n";
echo "</form>\n";
?>
</body>
</html>
<?
function _countMaskPos()
{
if($this->_isFull())
{
switch($this->mask_position)
{
case 1:
// 左上
$this->mask_pos_x = $this->mask_offset_x + $this->img_border_size;
$this->mask_pos_y = $this->mask_offset_y + $this->img_border_size;
break;
case 2:
// 左下
$this->mask_pos_x = $this->mask_offset_x + $this->img_border_size;
$this->mask_pos_y = $this->src_h - $this->mask_h - $this->mask_offset_y;
break;
case 3:
// 右上
$this->mask_pos_x = $this->src_w - $this->mask_w - $this->mask_offset_x;
$this->mask_pos_y = $this->mask_offset_y + $this->img_border_size;
break;
case 4:
// 右下
$this->mask_pos_x = $this->src_w - $this->mask_w - $this->mask_offset_x;
$this->mask_pos_y = $this->src_h - $this->mask_h - $this->mask_offset_y;
break;
default:
// 默认将水印放到右下,偏移指定像素
$this->mask_pos_x = $this->src_w - $this->mask_w - $this->mask_offset_x;
$this->mask_pos_y = $this->src_h - $this->mask_h - $this->mask_offset_y;
break;
}
}
else
{
switch($this->mask_position)
{
case 1:
// 左上
$this->mask_pos_x = $this->mask_offset_x + $this->img_border_size;
$this->mask_pos_y = $this->mask_offset_y + $this->img_border_size;
break;
case 2:
// 左下
$this->mask_pos_x = $this->mask_offset_x + $this->img_border_size;
$this->mask_pos_y = $this->dst_h - $this->mask_h - $this->mask_offset_y - $this->img_border_size;
break;
case 3:
// 右上
$this->mask_pos_x = $this->dst_w - $this->mask_w - $this->mask_offset_x - $this->img_border_size;
$this->mask_pos_y = $this->mask_offset_y + $this->img_border_size;
break;
case 4:
// 右下
$this->mask_pos_x = $this->dst_w - $this->mask_w - $this->mask_offset_x - $this->img_border_size;
$this->mask_pos_y = $this->dst_h - $this->mask_h - $this->mask_offset_y - $this->img_border_size;
break;
default:
// 默认将水印放到右下,偏移指定像素
$this->mask_pos_x = $this->dst_w - $this->mask_w - $this->mask_offset_x - $this->img_border_size;
$this->mask_pos_y = $this->dst_h - $this->mask_h - $this->mask_offset_y - $this->img_border_size;
break;
}
}
}
/**
* 设置字体信息
*/
function _setFontInfo()
{
if(is_numeric($this->font))
{
$this->font_w = imagefontwidth($this->font);
$this->font_h = imagefontheight($this->font);
// 计算水印字体所占宽高
$word_length = strlen($this->mask_word);
$this->mask_w = $this->font_w*$word_length;
$this->mask_h = $this->font_h;
}
else
{
$arr = imagettfbbox ($this->font_size,0, $this->font,$this->mask_word);
$this->mask_w = abs($arr[0] - $arr[2]);
$this->mask_h = abs($arr[7] - $arr[1]);
}
}
/**
* 设置新图尺寸
*
* @param integer $img_w 目标宽度
* @param integer $img_h 目标高度
*/
function _setNewImgSize($img_w, $img_h=null)
{
$num = func_num_args();
if(1 == $num)
{
$this->img_scale = $img_w;// 宽度作为比例
$this->fill_w = round($this->src_w * $this->img_scale / 100) - $this->img_border_size*2;
$this->fill_h = round($this->src_h * $this->img_scale / 100) - $this->img_border_size*2;
// 源文件起始坐标
$this->src_x = 0;
$this->src_y = 0;
$this->copy_w = $this->src_w;
$this->copy_h = $this->src_h;
// 目标尺寸
$this->dst_w = $this->fill_w + $this->img_border_size*2;
$this->dst_h = $this->fill_h + $this->img_border_size*2;
}
if(2 == $num)
{
$fill_w = (int)$img_w - $this->img_border_size*2;
$fill_h = (int)$img_h - $this->img_border_size*2;
if($fill_w < 0 || $fill_h < 0)
{
die("图片边框过大,已超过了图片的宽度");
}
$rate_w = $this->src_w/$fill_w;
$rate_h = $this->src_h/$fill_h;
switch($this->cut_type)
{
case 0:
// 如果原图大于缩略图,产生缩小,否则不缩小
if($rate_w < 1 && $rate_h < 1)
{
$this->fill_w = (int)$this->src_w;
$this->fill_h = (int)$this->src_h;
}
else
{
if($rate_w >= $rate_h)
{
$this->fill_w = (int)$fill_w;
$this->fill_h = round($this->src_h/$rate_w);
}
else
{
$this->fill_w = round($this->src_w/$rate_h);
$this->fill_h = (int)$fill_h;
}
}
$this->src_x = 0;
$this->src_y = 0;
$this->copy_w = $this->src_w;
$this->copy_h = $this->src_h;
// 目标尺寸
$this->dst_w = $this->fill_w + $this->img_border_size*2;
$this->dst_h = $this->fill_h + $this->img_border_size*2 - 10 ;//补偿round误差 消除白边;
break;
// 自动裁切
case 1:
// 如果图片是缩小剪切才进行操作
if($rate_w >= 1 && $rate_h >=1)
{
if($this->src_w > $this->src_h)
{
$src_x = round($this->src_w-$this->src_h)/2;
$this->setSrcCutPosition($src_x, 0);
$this->setRectangleCut($fill_h, $fill_h);
$this->copy_w = $this->src_h;
$this->copy_h = $this->src_h;
}
elseif($this->src_w < $this->src_h)
{
$src_y = round($this->src_h-$this->src_w)/2;
$this->setSrcCutPosition(0, $src_y);
$this->setRectangleCut($fill_w, $fill_h);
$this->copy_w = $this->src_w;
$this->copy_h = $this->src_w;
}
else
{
$this->setSrcCutPosition(0, 0);
$this->copy_w = $this->src_w;
$this->copy_h = $this->src_w;
$this->setRectangleCut($fill_w, $fill_h);
}
}
else
{
$this->setSrcCutPosition(0, 0);
$this->setRectangleCut($this->src_w, $this->src_h);
$this->copy_w = $this->src_w;
$this->copy_h = $this->src_h;
}
// 目标尺寸
$this->dst_w = $this->fill_w + $this->img_border_size*2;
$this->dst_h = $this->fill_h + $this->img_border_size*2;
break;
// 手工裁切
case 2:
$this->copy_w = $this->fill_w;
$this->copy_h = $this->fill_h;
// 目标尺寸
$this->dst_w = $this->fill_w + $this->img_border_size*2;
$this->dst_h = $this->fill_h + $this->img_border_size*2;
break;
default:
break;
}
}
// 目标文件起始坐标
$this->start_x = $this->img_border_size;
$this->start_y = $this->img_border_size;
}
/**
* 检查水印图是否大于生成后的图片宽高
*/
function _isFull()
{
Return ( $this->mask_w + $this->mask_offset_x > $this->fill_w
|| $this->mask_h + $this->mask_offset_y > $this->fill_h)
?true:false;
}
/**
* 检查水印图是否超过原图
*/
function _checkMaskValid()
{
if( $this->mask_w + $this->mask_offset_x > $this->src_w
|| $this->mask_h + $this->mask_offset_y > $this->src_h)
{
die("水印图片尺寸大于原图,请缩小水印图");
}
}
/**
* 取得图片类型
*
* @param string $file_path 文件路径
*/
function _getImgType($file_path)
{
$type_list = array("1"=>"gif","2"=>"jpg","3"=>"png","4"=>"swf","5" => "psd","6"=>"bmp","15"=>"wbmp");
if(file_exists($file_path))
{
$img_info = @getimagesize ($file_path);
if(isset($type_list[$img_info[2]]))
{
Return $type_list[$img_info[2]];
}
}
else
{
die("文件不存在,不能取得文件类型!");
}
}
/**
* 检查图片类型是否合法,调用了array_key_exists函数,此函数要求
* php版本大于4.1.0
*
* @param string $img_type 文件类型
*/
function _checkValid($img_type)
{
if(!array_key_exists($img_type, $this->all_type))
{
Return false;
}
}
/**
* 按指定路径生成目录
*
* @param string $path 路径
*/
function _mkdirs($path)
{
$adir = explode('/',$path);
$dirlist = '';
$rootdir = array_shift($adir);
if(($rootdir!='.'||$rootdir!='..')&&!file_exists($rootdir))
{
@mkdir($rootdir);
}
foreach($adir as $key=>$val)
{
if($val!='.'&&$val!='..')
{
$dirlist .= "/".$val;
$dirpath = $rootdir.$dirlist;
if(!file_exists($dirpath))
{
@mkdir($dirpath);
@chmod($dirpath,0777);
}
}
}
}
/**
* 垂直翻转
*
* @param string $src 图片源
*/
function _flipV($src)
{
$src_x = $this->getImgWidth($src);
$src_y = $this->getImgHeight($src);
$new_im = imagecreatetruecolor($src_x, $src_y);
for ($y = 0; $y < $src_y; $y++)
{
imagecopy($new_im, $src, 0, $src_y - $y - 1, 0, $y, $src_x, 1);
}
$this->h_src = $new_im;
}
/**
* 水平翻转
*
* @param string $src 图片源
*/
function _flipH($src)
{
$src_x = $this->getImgWidth($src);
$src_y = $this->getImgHeight($src);
$new_im = imagecreatetruecolor($src_x, $src_y);
for ($x = 0; $x < $src_x; $x++)
{
imagecopy($new_im, $src, $src_x - $x - 1, 0, $x, 0, 1, $src_y);
}
$this->h_src = $new_im;
}
}
?>
下面来看使用方法:
require_once('lib/ImageHandler.phpcls');
$imgHandler_Obj = new ImageHandler();
/* 默认缩小放大 */
$imgHandler_Obj->setSrcImg("img/xrk.jpg");
$imgHandler_Obj->setDstImg("tmp/New_Image_0.jpg");
$imgHandler_Obj->setCutType(0);
// 指定缩放比例
$imgHandler_Obj->createImg(20);//50 100 200 试试
/* 1, 文字水印图片缩小
$imgHandler_Obj->setSrcImg("img/xrk.jpg");
$imgHandler_Obj->setMaskFont("Fonts/STXINGKA.TTF");
$imgHandler_Obj->setMaskFontSize(15);
$imgHandler_Obj->setMaskFontColor("#0061A7");
$imgHandler_Obj->setMaskTxtPct(20);
$imgHandler_Obj->setDstImgBorder(0,"#dddddd");
$imgHandler_Objext = "Happy漫步者";
//$str = mb_convert_encoding($imgHandler_Objext,"UTF-8","GBK");
$imgHandler_Obj->setMaskWord($imgHandler_Objext);
// 指定固定宽高 输出到浏览器
$imgHandler_Obj->createImg(400,400);
*/
/* 2, 加水印图片缩小
$imgHandler_Obj->setSrcImg("img/test.jpg");
$imgHandler_Obj->setDstImg("tmp/New_Image_2.jpg");
$imgHandler_Obj->setMaskImg("img/t.gif");
$imgHandler_Obj->setMaskPosition(0);//0为在图片右下角加入水印
$imgHandler_Obj->setMaskImgPct(60);
$imgHandler_Obj->setDstImgBorder(1,"#dddddd");
// 指定缩放比例
$imgHandler_Obj->createImg(400,400);
*/
/* 3, 同步缩小
$imgHandler_Obj->setSrcImg("img/test.jpg");
$imgHandler_Obj->setCutType(0);//同步缩小
$imgHandler_Obj->setDstImg("tmp/New_Image_3.jpg");
$imgHandler_Obj->createImg(150,160);
*/
/* 4, 剪裁图片
$imgHandler_Obj->setSrcImg("img/test.jpg");
$imgHandler_Obj->setCutType(2);//指明为手工裁切
$imgHandler_Obj->setSrcCutPosition(50, 50);// 源图起点坐标
$imgHandler_Obj->setRectangleCut(300, 200);// 裁切尺寸
$imgHandler_Obj->setDstImg("tmp/New_Image_4.jpg");
$imgHandler_Obj->createImg(300,200);
*/
相关文章
- php 获取用户IP与IE信息程序 function onlineip() { global $_SERVER; if(getenv('HTTP_CLIENT_IP')) { $onlineip = getenv('HTTP_CLIENT_IP');...2016-11-25
- php简单用户登陆程序代码 这些教程很对初学者来讲是很有用的哦,这款就下面这一点点代码了哦。 <center> <p> </p> <p> </p> <form name="form1...2016-11-25
- 当来访者浏览器语言是中文就进入中文版面,国外的用户默认浏览器不是中文的就跳转英文页面。 <?php $lan = substr( $HTTP_ACCEPT_LANGUAGE,0,5); if ($lan == "zh-cn") print("<meta http-equiv='refresh' c...2015-11-08
- 【问题描述】:同一用户在同一时间多次登录如果不能检测出来,是危险的。因为,你无法知道是否有其他用户在登录你的账户。如何禁止同一用户多次登录呢? 【解决方案】 (1) 每次登录,身份认证成功后,重新产生一个session_id。 s...2015-11-24
- 一个用Javascript检测用户输入密码强度的效果代码,以下代码主要是从以下四个方面检测用户输入的密码的强度的,有兴趣的朋友可以自己添加或修改成自己想要的形式! 1. 如果输入的密码位数少于5位,那么就判定为弱。 2. 如果...2015-10-23
- 这是注册程序是一款当用户输入完用户名是,就会自动去数据库中查询用户要注册的用户名是否己经被注册了,如果是返回提示否则提示可以注册。 conn.php文件 代...2016-11-25
- 这篇文章主要给大家介绍了关于微信小程序用户授权最佳实践的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-05-08
- cookie 的用途之一是存储用户在特定网站上的密码和 id。另外,也用于存储起始页的首选项。在提供个人化查看的网站上,将要求阁下的网络浏览器利用阁下计算机硬驱上的少量...2016-11-25
- 这篇文章主要介绍了smarty中改进truncate使其支持中文的方法,涉及针对Smarty源码中truncate源文件进行函数功能扩展的相关技巧,需要的朋友可以参考下...2016-06-12
- 知识归纳因为MySQL是使用User和Host两个字段来确定用户身份的,这样就带来一个问题,就是一个客户端到底属于哪个host。 如果一个客户端同时匹配几个Host,对用户的确定将按照下面的优先级来排 基本观点越精确的匹配越优先...2015-11-08
- 这篇文章主要介绍了sqlserver添加sa用户和密码的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-05-07
- 注册页面是大多数网站必备的页面,所以很有必要对自己的注册页面做些精心的设计。下面三张图,第一张是注册的展示页面,第二张思维导图就一个简单的逻辑,第三张是通过firebug查看调用的JS文件。 一、给每个输入框写下说明在...2015-11-24
- 装完数据库清理一些默认账号的时候不小心把root删除了,flush privileges 之后的新 root 忘了grant任何权限,查看mysqld选项里面有个 −−skip-grant-tables复制代码 代码如下: #/usr/libexec/mysqld --verbos...2015-03-15
Win2012服务器 远程桌面帐户允许多用户同时登录的配置方法
这篇文章主要介绍了Win2012服务器 远程桌面帐户允许多用户同时登录的配置方法,需要的朋友可以参考下...2016-11-01- 第一,网站的内容;请各位站长朋友不要一天到晚只想着出什么好的绝招来推广网站,却忽略了网站的内容;其实网站的内容是极为重要的,因为这是你的本,你的根!网站的内容只有不断...2017-07-06
- 这篇文章主要介绍了关于JSP用户登录连接数据库的相关资料,需要的朋友可以参考下面文章内容...2021-09-07
- 一位站长译的一个国外的如何判断用户是否访问过某个网址文章,个人感觉写得非常不错,下面分享一下。 我们经常有这样的需求:想知道用户之前有没有访问过某个网址。有...2016-09-20
- 这篇文章主要介绍了dos之net创建管理员用户的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-06-30
- 这篇文章主要介绍了Oracle用户自定义异常实现过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-09-29
- 这篇文章主要为大家详细介绍了JQuery用户名校验的具体实现,感兴趣的小伙伴们可以参考一下...2016-03-22