易截截图软件、单文件、免安装、纯绿色、仅160KB
热门标签: c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 最新文章 : php

PHP用户登录注册模块实现


PHP用户登录模块实现
项目包含的功能脚本:
login.php//登录
reg.php//注册用户
user_add.php//注册校验脚本
user_login_check.php//登录校验脚本
image.php//验证码图片生成脚本
流程:
设计数据库:
包含用户uid,用户名,密码,昵称,性别,邮箱,注册时间
sql语句如下
create table users (uid bigint(20) not null auto_increment primary key unique key,username varchar(100) default null, userpassword varchar(100) default null, nickname varchar(100) default null, sex tinyint(1) default 0,email varchar(100) default null, regtime timestamp(14) default 0);
注册模块:
reg.php填写注册信息,通过js脚本判断所填写信息是否合法
如果合法,那么提交表单,通过user_add.php进行用户的注册
user_add.php脚本实现的功能如下:
判断输入的信息是否合法,这个js可以实现,但是为了浏览器兼容这里用php再实现一遍js的功能
如果合法并且以前没有注册过,那么可以注册,否则提示错误信息
登录模块:
login.php填写登录信息,js判断输入信息是否合法
如果合法提交表单,通过user_login_check.php登录
user_login_check.php实现功能如下:
......

PHP验证码生成脚本(5位数字png格式)


<?php
header("Content-Type:image/png");
srand((double)microtime()*1000000);
$img_height=20;
$img_width=60;
$im=@imagecreate($img_width,$img_height) or die("不能初始化GD文件流");
$background_color=imagecolorallocate($im,255,255,255);
$text_color=imagecolorallocate($im,233,14,91);
//绘制干扰雪花
for($i=1;$i<=100;$i++)
{
imagestring($im,1,mt_rand(1,$img_width),mt_rand(1,$img_height),"*",imageColorAllocate($im,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255)));
}
while(($num=rand()%100000)<10000);
//将随即产生的验证码保存在session中,方便以后使用
//session_start();
$_SESSION["num"]=null;//验证码刷新
$_SESSION["num"]=$num;
//绘制字符从到图像
imagestring($im,4,15,2,$num,$text_color);
imagepng($im);
imagedestroy($im);
?>
......

[PHP]PDO的使用

1. 安装php5.1以上的版本,有支持pdo!为了使你的环境能提供对pdo的支持!在php.ini文件加入以下:
extension=php_pdo.dll
extension=php_pdo_mysql.dll
extension=php_pdo_mssql.dll(支持mssql数据库)
2. 以下为PH中PDO的具体使用
 <?php
$dsn = 'mysql:dbname=MyDbName;host=localhost';
$user = 'root';
$password = '666666';
try {
$dbCon = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
print 'Connection failed: '.$e->getMessage();
}
//------------pdo query example---------
$strSQL = "select * from Users";
//---------method1---------
try {
$result = $dbCon->query($strSQL);
if( $result ){
$uCol = $result ->columnCount();
$arRS = $result ->fetchAll();
foreach ($arRS as $row){
for( $i=0; $i<$uCol; $i++ )
print $row[$i]." ";
print "<br>";
}
}
}catch (PDOException $e) {
print $e->getMessage();
}

//---------method2---------
try {
$sth = $dbCon->prepare($strSQL);
$sth-& ......

[PHP]PDO调用存储过程

1. 数据库中已创建存储过程user_logon_check, PHP调用示例如下,
<?php
$dsn = 'mssql:dbname=MyDbName;host=localhost';
$user = 'sa';
$password = '666666';
try {
$dbCon = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
print 'Connection failed: '.$e->getMessage();
exit;
}
$username = '123';
$userpsw = '123';
//$xp_userlogon = $dbCon ->query("exec user_logon_check '$username','$userpsw'");
//mysql->call user_logon_check('$username','$userpsw');
//mysql->call user_logon_check(?,?)
$xp_userlogon = $dbCon->prepare('exec user_logon_check ?,?');
$xp_userlogon->bindParam(1,$username);
$xp_userlogon->bindParam(2,$userpsw);
$xp_userlogon->execute();
$uCol = $xp_userlogon->columnCount();
echo $uCol."<br>";
while($row = $xp_userlogon->fetch()){
for( $i=0; $i<$uCol; $i++ )
print $row[$i]." ";
print "<br>";
}
?> ......

[PHP]Pear的使用

1. PEAR的安装, 这里介绍利用PHP5自带的BAT文件安装,需要能上网。
   a. 在PHP5目录下找到go-pear.bat,双击安装(保证能上网, 以便下载),BAT自动从网上下载PEAR所需的东西;
   b. 按照提示输入一些设置信息,主要是要把局域网的网关加上,如http://192.168.0.1:80/ , pear要用这个地址访问Internet,若无代理服务器则直接回车
   c. 然后会提示一些包和PHP绑定,选择Y
2. 安装完PEAR后, 以下示例具体调用: 
<?php
require_once 'DB.php';
//$dsn = 'sqlite:///E:/web2/Web_TY/sqlite/data/tydb.db?mode=0666';
$dsn = array(
'phptype' => 'mysql',
'username' => 'root',
'password' => '666666',
'hostspec' => 'localhost',
'database' => 'MyDbName'
);
$options = array(
'debug' => 2,
'portability' => DB_PORTABILITY_ALL
);
$db =& DB::connect($dsn, $options);
if (DB::isError($db)) {
die($db->getMessage());
}
$db->setFetchMode(DB_FETCHMODE_ASSOC);
$res =& $db->query('select * from counter'); ......

[PHP]Smarty的使用

<?php
define('SMARTY_TMP_DIR','C:/php5/Smarty-2.6.13/');
define('SMARTY_DIR','C:/php5/Smarty-2.6.13/libs/'); //SMARTY_DIR ->smarty keyword,must be defined as libs dectory
require_once(SMARTY_DIR.'Smarty.class.php');
//建立一个smarty对象
$smarty = new Smarty;
$smarty->template_dir = SMARTY_TMP_DIR.'templates/';
$smarty->compile_dir = SMARTY_TMP_DIR.'templates_c/';
$smarty->config_dir = SMARTY_TMP_DIR.'configs/';
$smarty->cache_dir = SMARTY_TMP_DIR.'cache/';
//$smarty->left_delimiter = '{/';
//$smarty->right_delimiter = '/}';
//----------simple show example------------
//$smarty->assign('name','Porky');
//$smarty->display('smarty_test.tpl');
?> ......
总记录数:2174; 总页数:363; 每页6 条; 首页 上一页 [31] [32] [33] [34] 35 [36] [37] [38] [39] [40]  下一页 尾页
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号