search
Homephp教程PHP源码smarty结合xajax检测用户名简单实例

<script>ec(2);</script>

  /*****************************************

   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' ? '该用户名已经注册' :'可以注册');
       $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');//显示模板内容
?>

 







请输入用户名:
 
 
 



Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function