前一段时间刚刚开始学习php 很简单很实用 开发效率很高 很适合我这样的新手 于是做了一个简单的登陆注册模块 里面包含了很多常用的表单提交数据 也加入了验证码 供新手们借鉴
说实话 我只会写网页 做网站是0基础 慢慢开始接触 这学期学到了不少做网站方面的知识 受益匪浅。
废话不多说 先看一下我的网站效果图:
这是网站用户的登陆界面 登陆界面 只需要用户填写用户名密码即可
下面是页面(login.php)的核心代码:
<form id="LoginForm" class="common" action="doAction.php?act=login" method="post">
<p id="p">如果您没有注册,请注册后登陆。管理员请走专用通道。</p>
<br />
<div>
<label id="login_username">登录名称:</label>
<input id="login_username" name="username" type="text"/>
<p id="info_login_username"></p>
</div>
<div>
<label id="login_password">登陆密码:</label>
<input id="login_password" name="password" type="password"/>
<p id="info_login_password"></p>
</div>
<div id="login_button">
<input type="submit" id="login_login" value="登 陆"/>
<input type="button" id="login_reg" value="注 册" onClick="location.href='register.php'"/>
</div>
</form>
数据提交到doAction.php 代码如下:
<?php
header("content-type:text/html;charset=utf-8");
$act=$_REQUEST['act'];
if($act=="reg"){
$mes=reg();
}elseif($act=="login"){
$mes=login();
}
function reg(){
$arr['username'] = $_POST['username'];
$arr['password'] = md5($_POST['password']);
$arr['gender'] = $_POST['gender'];
$arr['major'] = $_POST['major'];
$arr['birthday'] = $_POST['birthday'];
$arr['phone'] = $_POST['phone'];
$arr['qq'] = $_POST['qq'];
$arr['email'] = $_POST['email'];
$arr['collage'] = $_POST['collage'];
$temp = $_POST['hobby'];
$arr['hobby'] = implode(",", $temp);
$conn = mysql_connect("localhost", "root", "") or die("数据库连接失败".mysql.error());
mysql_select_db("ausspeace") or die ("没有数据库".mysql.error());
mysql_query("set names 'utf8' ");
$sql = "insert into speace_user(username, password, gender, major, birthday, phone, qq, email, collage, hobby) values ('$arr[username]', '$arr[password]', '$arr[gender]', '$arr[major]',' $arr[birthday]','$arr[phone]', '$arr[qq]', '$arr[email]', '$arr[collage]', '$arr[hobby]')";
if(mysql_query($sql)){
$mes="<h2>您好<font color=#c67114>". $arr['username']."</font>注册成功!</h2><br/><h2 id='return'>3秒钟后跳转到登陆页面!</h2><meta http-equiv='re