这个登录的功能已经做完了 
不过可能存在一定的安全问题 或者 比较雷人的代码 请大家受累帮我看看吧
-----------------------------------------------------------------
function_login.php    登录 登出函数<?php
function login($user,$pwd){
$db=mysql_connect("127.0.0.1","root","" );
if(!$db) {echo "数据库链接失败"; exit();}
mysql_select_db("blog");
mysql_query("set names gb2312");
$user=trim($user);
$pwd=trim($pwd);
$user=htmlspecialchars($user);
$pwd=htmlspecialchars($pwd);
$hel=mysql_query("select id from users where user='$user' and pwd='$pwd'");
if (mysql_num_rows($hel))
return true;
else
return false;
}
function logout(){
session_start();
unset($_SESSION['mp3']); 
echo "<script>alert('登出成功');window.navigate('login.php')</script>";
}
if(@$_GET["act"]=='logout')
logout();
?>
config.php  检查登录状态函数<?php
function logining(){
session_start();
if(!@$_SESSION["mp3"])
echo '<script>window.navigate("login.php");</script>';
}
?>
login.php 登录主文件<?php
include_once("function_login.php");
session_start();
if(@$_POST["code"])
if(strcasecmp($_SESSION["varyz"], @$_POST["code"])==0){
if(login($_POST["user"],$_POST["pwd"])){
$_SESSION["mp3"] = true;  
  
echo '<script>alert("验证成功!");window.navigate("index.php");</script>';
}
else
echo '<script>alert("验证失败!");</script>';
}
else
echo '<script>alert("验证码不正确!");</script>';
?>
....省略HTML代码
<form action="login.php" method="post"  style="margin:25px 0px 0px 20px; float:left">
<p><label>用户名</label><input type="text"    name="user" /></p>
<p><label>密 码</label><input type="password"   name="pwd" /></p>
<p><label>验证码</label><input type="text" style="width:60px;" name="code" /> <img src="image.php" align="absmiddle"  style="cursor:pointer" onclick="this.src=this.src+'?'"/></p>
<p><input type="submit"   value="登录"/></p>
</form>
未来的后台主页<?php 
include_once("config.php");
logining();
?>
<a href="login.php?act=logout">注销</a>