提供一款可以保存用户登陆的信息来做了,这里就是一个简单的php 登陆并设置cookie代码哦,很简单的。
if(!$c_log){
$title.='登陆';
if($_SERVER['REQUEST_METHOD']=='POST'){
if(isset($_POST['username']) && trim($_POST['username'])!='' && isset($_POST['password']) && trim($_POST['password'])!=''){
$username=trim($_POST['username']);
$password=enc_p(trim($_POST['password']));
$q_author=sprintf('select * from %s where username=%s and password=%s', $dbprefix.'member', SQLString($username, 'text'), SQLString($password, 'text'));
$author=mysql_query($q_author) or die('');
$r_author=mysql_fetch_assoc($author);
if(mysql_num_rows($author)>0){
if($r_author['status']==0 || $r_main['veri']>0){
$uSQL=sprintf('update %s set visit=visit+1, visitdate=%s where id=%s', $dbprefix.'member', time(), $r_author['id']);
$result=mysql_query($uSQL) or die('');
session_unset();
session_start();
$_SESSION['palu_id']=$r_author['id'];
if(isset($_POST['remember']) && $_POST['remember']=='1'){
setcookie('palu_u', $username, time()+86400*30);
setcookie('palu_p', $password, time()+86400*30);
}else{
setcookie('palu_u','',time());
setcookie('palu_p','',time());
}
}else{
$e=1;
}
}else{
$e=2;
}
mysql_free_result($author);
}
if(isset($_GET['m']))$u[]='m='.$_GET['m'];
if(isset($_GET['t']))$u[]='t='.$_GET['t'];
if(isset($_GET['page']))$u[]='page='.$_GET['page'];
if(isset($e))$u[]='e='.$e;
$topinfo.='<script type="text/JavaScript">location.href=''.(isset($u)?'?'.join('&', $u):'./').'';</script>';
}else{
if(isset($_GET['e'])){
if($_GET['e']==2){
$msg='用户名/密码错误!';
}elseif($_GET['e']==3){
$msg='注册成功!请'.($r_main['veri']>0?'登陆':'等待管理员审核').'。';
}else{
$msg='您的帐号还没有通过审核,请稍候再试。';
}
}
$content.='<div class="tcontent">'.(isset($msg)?'<div class="msg_v">'.$msg.'</div>':'').'<div class="title">登陆</div><div class="lcontent"><form method="post" action="" onsubmit="return chklog();"><div class="formline"><label for="formname">用户名:</label><input name="username" id="formname" size="32" maxlength="20" /></div><div class="formline"><label for="formpw">密 码:</label><input name="password" id="formpw" size="32" maxlength="20" type="password" /></div><div class="formline"><label></label><input name="remember" value="1" type="checkbox" title="为了确保信息安全,请不要在网吧或者公共机房选择此项!如果今后要取消此选项,只需点击“退出登陆”即可。" />记住我</div><div class="formline"><input type="submit" value="登陆" id="formsubmit" class="button" /> <input type="reset" value="取消" class="button" /><br/>'.($r_main['openreg']==0?'<a href="?m=reg">加入本班</a> | ':'').'<a href="?m=lostpw">忘记密码</a></div></form></div></div>';
}
}else{
$topinfo.='<script type="text/JavaScript">location.href='./';</script>';
}
?>
function makeHtml($msgContent,$filePath,$fileName){//生成html文件
if(!is_dir($filePath)){@mkdir($filePath);}
$handle = fopen(str_replace('\','../',$filePath.$fileName),'w+') or die("can't create file!$fileName");
fwrite($handle,$msgContent);
fclose($handle);
}
function md5_filename($fileid,$fileztype,$fileuid){//文件加密方法
return md5($fileid.$fileztype.$fileuid).'.htm';
}
function getSql(){//一次多少生成htm文件
global $limit,$start,$id;
$sysType = '';
if( !empty( $id ) ){
$sysType = "And systype = $id";
}
$sql = "select * from filecontent where siteindex=1 $sysType limit $start,$limit";
$result = mysql_query($sql) or die('Query error');
while( $rs = mysql_fetch_array($result) ){
$fileName =md5_filename($rs[0],$rs['z_type'],$rs['filesendid']);
$path = get_path($rs['systype']).$rs['z_type'].'/';
$parent = substr(getcwd(),0,strrpos(getcwd(),'\'));
$filePath =$parent.'\'.$path;
makeHtml($rs['content'],$filePath,$fileName);
}
mysql_free_result($result);
}
$info = "<script language="javascript">
var pgo =0;
function JumpUrl(){
document.write('己生成文件<a href=make_html.php?id=$id&start=$start&limit=$limit&end=$end>如果浏览器无反应请点击这里</a>');
location='make_html.php?id=$id&start=$start&limit=$limit&end=$end';
}
setTimeout('JumpUrl()',100);
</script>";
if($start>$end){
die('完成所有生成任务!');
} else {
getSql();
echo $info;
}
function SQLString($c, $t){
$c=(!get_magic_quotes_gpc())?addslashes($c):$c;
switch($t){
case 'text':
$c=($c!='')?"'".$c."'":'NULL';
break;
case 'search':
$c="'%%".$c."%%'";
break;
case 'int':
$c=($c!='')?intval($c):'0';
break;
}
return $c;
}
function getftime($t=''){
global $r_main;
if($t=='')$t=time();
return $t+$r_main['timefix'];
}
function getldate($t){
$a=time()-$t;
if($a<60){
$c=$a.'秒前';
}elseif($a<3600){
$c=floor($a/60).'分钟前';
}elseif($a<86400){
$c=floor($a/3600).'小时前';
}elseif($a<86400*2){
$c='1天前';
}
return (isset($c)?$c.' ':'').date('Y-n-j H:i', getftime($t));
}
function substrs($c, $l=16){
if(strlen($c)>$l){
$n=0;
for($i=0;$i<$l;$i++){
if(ord(substr($c,$i,1))>127){
$n++;
if($i<($l-1)){
$i++;
$n++;
}
}
}
if($n%2>0)$l+=1;
$c=substr($c, 0, $l).'…';
}
return $c;
}