Introduction and trial of PHP Ajax framework xajax

Source: Internet
Author: User

I. Comparison between xajax and other Ajax frameworks
Xajax features are simple, but flexible !~ Unlike some other big frameworks, it has powerful functions, but the execution speed is not flattering .. Although there are many functions, they are not flexible enough. With many APIs, learning is like learning a new language.
II. Introduction to xajax Functions
Xajax features are relatively simple, but it is flexible because it is simple. At the same time, this also requires the user to have a certain understanding of the ipvcr platinum Pt/vbs client script. Because its functions are relatively active. It can be said that xajax alone can be used, but nothing can be done with JS/vbs.
Xajax mainly uses the xajaxresponse class, which provides some methods, for example:
1. addalert ($ smsg)
Pop-up warning
2. addscr platinum Pt ($ SJS)
Execute a JS segment
3. $ objresponse-> addassign ("","","")
Attaches a value to an element on the page or modifies its attributes.
And so on ....

Therefore, xajax is not dead. It cannot provide the xxx function, but it can flexibly control the JS/vbs of the client to achieve the desired effect.

Iii. xajax installation and configuration
No special installation or configuration is required. You only need to download the package and decompress it to the website directory.
:
Http://www.xajaxproject.org/

4. Use xajax for Member registration and login
1. Database
Use mysql5.0 and database name ZL table name zl_user table structure
Id int (11) auto_increment
Zl_user varchar (50)
Zl_pwd varchar (50)
Email varchar (50)

Http://blog.knowsky.com/

2. Reg. php registration file (for instructions)

<? PHP
Require_once ("INC/xajax. Inc. php ");
// To use xajax, you must first introduce xajax. Inc. php
$ Xajax = new xajax ("INC/signup. php ");
// Create an xajax object named singup. php
$ Xajax-> registerfunction ("processform ");
// Use the processform function in singup. php
?>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<LINK rel = "stylesheet" href = "http://blogbeta.blueidea.com/css/style.css" _ fcksavedurl = "" http://blogbeta.blueidea.com/css/style.css "" type = "text/CSS">
<Title> untitled document </title>
<? PHP $ xajax-> printmediacr partition Pt ('inc/');?>
<SCR limit PT Type = "text/merge Cr limit PT">
Function submitsignup ()
{
Xajax. $ ('submitclick'). Disabled = true;
Xajax. $ ('submitclick'). value = "http://blogbeta.blueidea.com/wait ...";
// Modify the attribute of ID to submitbutton
Xajax_processform (xajax. getformvalues ("signupform "));
// Here, xajax _ is followed by the function to be used. processform is followed by the set of signupform items.
Return false;
}
</Scr platinum Pt>
</Head>
<Body> <Form ID = "signupform" Action = "distinct Cr limit PT: void (null);" define nsubmit = "submitsignup ();">
<Div id = "Main">
<Div id = "M1"> User Registration </div>
<Div id = "formdiv">
<Table width = "100%" border = "0" cellspacing = "0" cellpadding = "5">
<Tr>
<TD align = "right"> </TD>
<TD> </TD>
</Tr>
<Tr>
<TD width = "31%" align = "right"> User name: </TD>
<TD width = "69%"> <input name = "USR" type = "text" id = "USR"/>
* </TD>
</Tr>
<Tr>
<TD align = "right"> password: </TD>
<TD> <input name = "PWD" type = "password" id = "PWD"/>
* </TD>
</Tr>
<Tr>
<TD align = "right"> password: </TD>
<TD> <input name = "pwd2" type = "password" id = "pwd2"/>
* </TD>
</Tr>
<Tr>
<TD align = "right"> Email: </TD>
<TD> <input name = "email" type = "text" id = "email"/>
* Password retrieval </TD>
</Tr>
<Tr align = "center">
<TD colspan = "2"> <input type = "Submit" name = "submitbutton" value = "Submit" class = "button"/>
<Input type = "reset" name = "submit2" value = "reset" class = "button"/> </TD>
</Tr>
</Table>
</Div>
</Div>
</Form>
</Body>
</Html>

Click Submit and execute the processform function in singup. php.

3. INC/singup. php

<? PHP
Define ('xajax _ default_char_encoding ', 'gb2312 ');
// Note that gb2312 must be set here, otherwise Chinese characters will be garbled
Require_once ("xajax. Inc. php ");
Require_once ("function. php ");
$ Xajax = new xajax ();
$ Xajax-> registerfunction ("processform ");
// Same as the reg. php file

Function processform ($ aformvalues)
{
$ Objresponse = new xajaxresponse ();
Require_once ("conn. php ");
$ USR = $ aformvalues ['usr'];
$ Email = $ aformvalues ['email '];
$ Pwd = $ aformvalues ['pwd'];
$ PW = MD5 ($ PWD );
$ Errmsg = "";
// Invalid characters to be filtered
$ Arrfiltrate = array ("'", ";", "union ");

Foreach ($ aformvalues as $ key => $ value ){
If (funstringexist ($ value, $ arrfiltrate )){
$ Objresponse-> addalert ("the entered information contains invalid characters \" '; Union! \"");
$ Objresponse-> addassign ("submitbutton", "value", "continue ");
$ Objresponse-> addassign ("submitbutton", "disabled", false );
Return $ objresponse;
}
}

If (TRIM ($ USR) = "")
{
$ Errmsg. = "Enter the user name! \ N ";
}
If (TRIM ($ PWD) = "")
{
$ Errmsg. = "enter the password! \ N ";
}
If ($ PWD! = $ Aformvalues ['pwd2 '])
{
$ Errmsg. = "the two passwords are inconsistent! \ N ";
}

If (! Checkemailaddr ($ email ))
{
$ Errmsg. = "the email address is incorrect! \ N ";
}
$ SQL = "select * From zl_usr where zl_usr = '$ usr '";
$ Result = mysql_query ($ SQL, $ dB );
If ($ myrow = mysql_fetch_array ($ result )){
$ Errmsg. = "the user name already exists! \ N ";
}
If ($ errmsg = "")
{
$ Sform = "successfully registered <br> User name:". $ USR. "<br> Email:". $ email ."";
$ SQL = "insert into zl_usr (zl_usr, zl_pwd, email) values ('$ usr',' $ PW ',' $ email ')";
$ Result = mysql_query ($ SQL, $ dB );
$ Objresponse-> addassign ("formdiv", "innerhtml", $ sform );
}
Else
{
$ Objresponse-> addalert ($ errmsg );
// The error message is displayed.
$ Objresponse-> addassign ("submitbutton", "value", "continue ");
// Modify the value of submitbutton to continue
$ Objresponse-> addassign ("submitbutton", "disabled", false );
// Modify the attributes of the submitbutton.
}

Return $ objresponse;
}

$ Xajax-> processrequests ();
?>

This file checks the validity of the information, including: whether the user name has been registered, whether there are illegal characters in the information, whether the email address is correct, and whether the two passwords are consistent, if there is no error, enter it in the database and
$ Objresponse-> addassign ("formdiv", "innerhtml", $ sform );
Re-insert in formdivCode, The content is $ sform
$ Sform = "successfully registered <br> User name:". $ USR. "<br> Email:". $ email ."";

If an error message exists
$ Objresponse-> addalert ($ errmsg );
// The error message is displayed.
$ Objresponse-> addassign ("submitbutton", "value", "continue ");
$ Objresponse-> addassign ("submitbutton", "disabled", false );
// Modify the attributes of the submitbutton.

3. login. php login file

<? PHP
Require_once ("INC/xajax. Inc. php ");
$ Xajax = new xajax ("INC/login. php ");
$ Xajax-> registerfunction ("processform ");
?>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<LINK rel = "stylesheet" href = "http://blogbeta.blueidea.com/css/style.css" _ fcksavedurl = "" http://blogbeta.blueidea.com/css/style.css "" type = "text/CSS">
<Title> untitled document </title>
<? PHP $ xajax-> printmediacr partition Pt ('inc/');?>
<SCR limit PT Type = "text/merge Cr limit PT">
Function submitsignup ()
{
Xajax. $ ('submitclick'). Disabled = true;
Xajax. $ ('submitclick'). value = "http://blogbeta.blueidea.com/wait ...";
Xajax_processform (xajax. getformvalues ("signupform "));
Return false;
}
</Scr platinum Pt>
</Head>
<Body> <Form ID = "signupform" Action = "distinct Cr limit PT: void (null);" define nsubmit = "submitsignup ();">
<Div id = "Main">
<Div id = "M1"> User Login </div>
<Div id = "formdiv">
<Table width = "100%" border = "0" cellspacing = "0" cellpadding = "5">
<Tr>
<TD align = "right"> </TD>
<TD> </TD>
</Tr>
<Tr>
<TD width = "31%" align = "right"> User name: </TD>
<TD width = "69%"> <input name = "USR" type = "text" id = "USR"/>
* </TD>
</Tr>
<Tr>
<TD align = "right"> password: </TD>
<TD> <input name = "PWD" type = "password" id = "PWD"/>
* </TD>
</Tr>

<Tr align = "center">
<TD colspan = "2"> <input type = "Submit" name = "submitbutton" value = "Submit" class = "button"/>
<Input type = "reset" name = "submit2" value = "reset" class = "button"/> </TD>
</Tr>
</Table>
</Div>
</Div>
</Form>
</Body>
</Html>

4. processing files for INC/login. php Login

<? PHP
Define ('xajax _ default_char_encoding ', 'gb2312 ');
Require_once ("xajax. Inc. php ");
Require_once ("function. php ");
$ Xajax = new xajax ();
$ Xajax-> registerfunction ("processform ");

Function processform ($ aformvalues)
{
$ Objresponse = new xajaxresponse ();
Require_once ("conn. php ");
$ USR = $ aformvalues ['usr'];
$ Email = $ aformvalues ['email '];
$ Pwd = $ aformvalues ['pwd'];
$ PW = MD5 ($ PWD );
$ Errmsg = "";
// Invalid characters to be filtered
$ Arrfiltrate = array ("'", ";", "union ");

Foreach ($ aformvalues as $ key => $ value ){
If (funstringexist ($ value, $ arrfiltrate )){
$ Objresponse-> addalert ("the entered information contains invalid characters \" '; Union! \"");
$ Objresponse-> addassign ("submitbutton", "value", "continue ");
$ Objresponse-> addassign ("submitbutton", "disabled", false );
Return $ objresponse;
}
}

If (TRIM ($ USR) = "")
{
$ Errmsg. = "Enter the user name! \ N ";
}
If (TRIM ($ PWD) = "")
{
$ Errmsg. = "enter the password! \ N ";
}
$ SQL = "select * From zl_usr where zl_usr = '$ usr' and zl_pwd =' $ PW '";
$ Result = mysql_query ($ SQL, $ dB );
If (! $ Myrow = mysql_fetch_array ($ result )){
$ Errmsg. = "the user name does not exist or the password is incorrect! \ N ";
}
If ($ errmsg = "")
{
$ Sform = "Login successful ";
$ Objresponse-> addassign ("formdiv", "innerhtml", $ sform );
}
Else
{
$ Objresponse-> addalert ($ errmsg );
$ Objresponse-> addassign ("submitbutton", "value", "continue ");
$ Objresponse-> addassign ("submitbutton", "disabled", false );
}

Return $ objresponse;
}

$ Xajax-> processrequests ();
?>

Login to the registration process is similar, no nonsense :)

In addition, the following two file codes are used: conn. php function. php.
Conn. php

<? PHP
$ Database = "ZL"; // MySQL Database Name
$ Db = mysql_connect ("127.0.0.1", "root", "123456"); // MySQL database username and password
Mysql_select_db ($ database, $ dB );
?>
Function. php

<? PHP
Function checkemailaddr ($ c_mailaddr)
{
If (! Eregi ("^ [_ a-z0-9-] (. [_ a-z0-9-]) * @ [a-z0-9-] (. [a-z0-9-]) * $ ",
$ C_mailaddr ))
{
Return false;
}
Return true;
}
// Whether the value in the array exists
Function funstringexist ($ strfiltrate, $ arrfiltrate ){
Foreach ($ arrfiltrate as $ key => $ value ){
If (eregi ($ value, $ strfiltrate )){
Return true;
}
}
Return false;
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.