2008年5月31日星期六

[jQuery] 点击这里搜索...

我们经常看到有些搜索框内有灰色的文字:点击这里进行搜索... 我们点击的时候,他就会自动消失. 使用jQuery可以很方便的实现这个功能.

HTML:

 <form action="#" method="post">
<input id="SearchText" name="text" />
<button>Search</button>
</form>

JavaScript:

 function populateElement(selector, defvalue) {
if($.trim($(selector).val()) == "") {
$(selector).val(defvalue);
}

$(selector).focus(function() {
if($(selector).val() == defvalue) {
$(selector).val("");
}
});

$(selector).blur(function() {
if($.trim($(selector).val()) == "") {
$(selector).val(defvalue);
}
});
}
 
使用方法:
populateElement('#SearchText', 'Enter your search term here..');

2007年9月10日星期一

just test html code display

<input name ="remember" type="checkbox"> Remember me next time<br> 


--
令狐葱
http://linghucong.blogspot.com
MSN:jiguofei@msn.com

2007年6月16日星期六

test

Remember me next time

php中图片验证码的生成

/*文件一:authpage.php*/


请输入验证码:






/*文件二:*/

//生成验证码图片
Header("Content-type: image/PNG");
srand((double)microtime()*1000000);//播下一个生成随机数字的种子,以方便下面随机数生成的使用

session_start();//将随机数存入session中
$_SESSION['authnum']="";
$im = imagecreate(62,20); //制定图片背景大小

$black = ImageColorAllocate($im, 0,0,0); //设定三种颜色
$white = ImageColorAllocate($im, 255,255,255);
$gray = ImageColorAllocate($im, 200,200,200);

imagefill($im,0,0,$gray); //采用区域填充法,设定(0,0)

while(($authnum=rand()%100000)<10000);
//将四位整数验证码绘入图片
$_SESSION['authnum']=$authnum;
imagestring($im, 5, 10, 3, $authnum, $black);
// 用 col 颜色将字符串 s 画到 image 所代表的图像的 x,y 座标处(图像的左上角为 0, 0)。
//如果 font 是 1,2,3,4 或 5,则使用内置字体

for($i=0;$i<200;$i++) //加入干扰象素
{
$randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
}
ImagePNG($im);
ImageDestroy($im);
?>
参考文章:http://www.phpe.net/articles/353.shtml
http://www.webdn.com/web_file/program/php/0602080424/

在登陆界面实现Remember me功能

登陆form中有:
 Remember me next time
设置session之后需要设置cookie。cookie就是临时存储用户信息的文件,保存在用户机器上。一下代码位于登陆中验证用户通过后:
   /* Username and password correct, register session variables */
$user = stripslashes($_POST['user']);
$_SESSION['username'] = $user;
$_SESSION['password'] = $pass;

/**
* the user has requested that we remember that he's logged in, so
* we set two cookies. One to hold his username,
* and one to hold his password. We set them both to
* expire in 100 days. Now, next time he comes to our site, we will
* log him in automatically.
*/
if(isset($_POST['remember'])){
setcookie("cookname", $_SESSION['username'], time()+60*60*24*100, "/");
setcookie("cookpass", $_SESSION['password'], time()+60*60*24*100, "/");
}
检查是否设置cookie:
function checkLogin(){
/* Check if user has been remembered */
if(isset($_COOKIE['cookname']) && isset($_COOKIE['cookpass'])){
$_SESSION['username'] = $_COOKIE['cookname'];
$_SESSION['password'] = $_COOKIE['cookpass'];
}

/* Username and password have been set */
if(isset($_SESSION['username']) && isset($_SESSION['password'])){
/* Confirm that username and password are valid */
if(confirmUser($_SESSION['username'], $_SESSION['password']) != 0){
/* Variables are incorrect, user not logged in */
unset($_SESSION['username']);
unset($_SESSION['password']);
return false;
}
return true;
}
/* User not logged in */
else{
return false;
}
}
在logout的时候
if(isset($_COOKIE['cookname']) && isset($_COOKIE['cookpass'])){
setcookie("cookname", "", time()-60*60*24*100, "/");
setcookie("cookpass", "", time()-60*60*24*100, "/");
}
参考:http://evolt.org/article/comment/17/60265/index.html