037 PHP登录、注册、留言、个人中心设计

一:结构目录

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

 

二:源码内容

C:\phpStudy\WWW\PHP\xnfhbbs\index.php

<?php
include "./inc/dblink.inc.php";
?>
<html>
<head>
	<meta charset="utf-8">
	<title>首页--刹那芳华</title>
</head>
<body>
	<h1>刹那芳华BBS 论坛</h1>
<?php
if(isset($_COOKIE['name'])){
	echo "欢迎您,<a href='./member/'>".$_COOKIE['name']."</a>";
}else{
	echo "<a href='./member'>会员中心</a>";
}
echo "|&nbsp;<a href='./addCont.php'>欢迎留言</a>";
echo "<hr />";
$sql="select * from messages";
if($results=mysqli_query($link,$sql)){
	if(mysqli_num_rows($results)>0){
		echo "<table border = 2>";
		echo "<tr><td>ID</td><td>TITLE</td><td>AUTHOR</td></tr>";
		while($result=mysqli_fetch_assoc($results)){
			//var_dump($result);
			echo "<tr><td>{$result['id']}</td><td><a href='showmsg.php?id=
			{$result['id']}' target='_blank'>
			{$result['title']}</a></td><td>{$result['uname']}</td></tr>";
		}
		echo "</table>";
	}else{
		echo "暂无留言内容";
	}
}else{
	echo mysqli_error($link);
}
?>
</body>
</html>
<?php
mysqli_close($link);
?>

C:\phpStudy\WWW\PHP\xnfhbbs\showmsg.php

<html>
<head>
	<meta charset="utf-8">
</head>
<body>
	<h1><a href='./index.php'>刹那芳华BBS 论坛</a></h1>
<?php
include "./inc/dblink.inc.php";
if(isset($_GET['id'])){
	$id = $_GET['id'];
	$sql = "select * from messages where id =".$id;
	//echo $sql;
	if($results = mysqli_query($link,$sql)){
		$result=mysqli_fetch_assoc($results);
		echo $result['uname'].":".$result['title']."<hr />";
		echo $result['content'];
		
	}else{
		echo mysqli_error($link);
	}
}else{
	echo "id Error!";
}
mysqli_close($link);
?>
</body>
</html>

C:\phpStudy\WWW\PHP\xnfhbbs\addCont.php

<html>
<head>
	<meta charset="utf-8">
</head>
<body>
	<h1><a href='./index.php'>刹那芳华BBS 论坛</a></h1>
<?php
include "./inc/dblink.inc.php";
?>
<?php
if(isset($_COOKIE['name'])){
	$html =<<<HTML
	<form
	method="post"
	>
	标题:<input type="text" name="userTitle"><br />
	内容:<br />
	<textarea name="userCont"></textarea>
	<input type="submit" name="userSubmit" value="提交">
	</form>
HTML;
	echo $html."<br />";
	if(isset($_POST['userSubmit']) && isset($_POST['userTitle'])){
		$userName=$_COOKIE['name'];
		$title = mysqli_real_escape_string($link,$_POST['userTitle']);
		$cont = mysqli_real_escape_string($link,$_POST['userCont']);
		$sql = "INSERT INTO `messages`(`uname`, `title`, `content`) VALUES ('".$userName."',
		'".$title."','".$cont."')";
		if($results = mysqli_query($link,$sql)){
			echo "留言成功,<a href='./'>返回首页</a>";
		}else{
			mysqli_close($link);
		}
	}else{
		echo "请提交";
	}
}else{
	echo "您还未登录,<a href='./member/'>请返回个人中心</a>";
}
?>
<?php
mysqli_close($link);
?>
</body>
</html>

C:\phpStudy\WWW\PHP\xnfhbbs\inc\dblink.inc.php

<?php
$dbHost = "127.0.0.1";
$dbUser = "root";
$dbPass = "root";
$dbName = "xnfh";

$link = mysqli_connect($dbHost,$dbUser,$dbPass,$dbName);
if(!link){
	die(mysqli_connect_error());
}
mysqli_set_charset($link,"utf-8");
?>

C:\phpStudy\WWW\PHP\xnfhbbs\member\addUser.php

<meta charset="utf-8">
<?php
include "../inc/dblink.inc.php";
?>
<?php
//var_dump($_POST);
//echo "<hr />";
if(isset($_POST['userSubmit'])){
	$userName=$_POST['userName'];
	$userPass1=$_POST['userPass1'];
	$userPass2=$_POST['userPass2'];
	if(
	isset($userName) && 
	isset($userPass1) && 
	isset($userPass2) &&
	$userPass1 === $userPass2
	){
		$sql = "insert into users(name,password)
		values('".$userName."','".md5($userPass1)."')";
		//echo $sql;
		if(!mysqli_query($link,$sql)){
			die("sql语句有误");
		}else{
			echo "注册成功,<a 
			href='./index.php'>返回个人中心";
			setcookie("name",$userName,time()+3600,'/');
		}
	}else{
		echo "注册信息有误,<a
		href='./register.php'>请重新注册</a>";
	}
 
}else{
	header("Location:./register.php");//重定向
}
 
?>
<?php
mysqli_close($link);
?>

C:\phpStudy\WWW\PHP\xnfhbbs\member\index.php

<?php
include "../inc/dblink.inc.php";
?>
<html>
<head>
	<meta charset="utf-8">
	<title>首页--个人中心</title>
</head>
<body>
<h1><a href="../index.php">刹那芳华BBS 论坛</a></h1>
<?php
if(isset($_COOKIE['name'])){
	$userName = $_COOKIE['name'];
	$sql = "select * from users where name='".$userName."'";
	//echo $sql;
	if($results = mysqli_query($link,$sql)){
		//echo mysqli_num_rows($results);
		if(mysqli_num_rows($results)>0){
			$result = mysqli_fetch_assoc($results);
			echo "<hr />";
			echo "欢迎您,".$result['name']."<a href='./logout.php'>注销</a>";
			echo "<hr />";
			echo "您的头像是<img src='".$result['photo']."'>";
			echo "<a href='./update.php'>修改头像</a>";
			echo "<hr />";
			echo "账户余额:".$result['money']."<span style='color:red;'>请联系管理员</span>";
		}else{
			setcookie('name',$_COOKIE['name'],time()-3600,'/PHP/cnfhbbs');
			die("该用户不存在,<a
			href='./register.php'>请注册</a>或者<a
			href='../index.php'>返回首页</a>");
		}
	}else{
		die(mysqli_error($link));
	}
}else{
	echo "<a href='./register.php'>注册</a>";
	echo "<br />";
	echo "<a href='./login.php'>登录</a>";
}
?>
<?php
mysqli_close($link);
?>
</body>
</html>

C:\phpStudy\WWW\PHP\xnfhbbs\member\login.php

<meta charset="utf-8">
<?php
include "../inc/dblink.inc.php";
?>
<?php
if(isset($_POST['userSubmit'])){
	$userName=$_POST['userName'];
	$userPass=$_POST['userPass'];
	$sql = "select * from users where name='".$userName."' 
	and password='".md5($userPass)."'";
	if($results=mysqli_query($link,$sql)){
		if(mysqli_num_rows($results)>0){
			setcookie('name',$userName,time()+3600*24,'/');
			echo "登录成功,<a href='./index.php'>返回个人中心</a>";
		}else{
			echo "用户名或密码错误,<a href='./login.php'>请重新登录</a>";
		}
	}else{
		die(mysqli_error($link));
	}
}else{
	$html=<<<HTML
	<form
	method="POST"
	>
	用户名:<input type="text" name="userName"><br />
	密码:<input type="password" name="userPass"><br />
	<input type="submit" name="userSubmit" value="登录">
	</form>
HTML;
echo $html;
}
?>
<?php
mysqli_close($link);
?>

C:\phpStudy\WWW\PHP\xnfhbbs\member\logout.php

<meta charset="utf-8">
<?php
if(setcookie('name',$_COOKIE['name'],time()-3600,'/')){
	echo "Logout!<a href='./index.php'>返回个人中心</a>";
}else{
	die("Error!");
}
?>

C:\phpStudy\WWW\PHP\xnfhbbs\member\register.php

<html>
<head>
	<meta charset="utf-8">
	<title>注册--刹那芳华</title>
</head>
<body>
	<h1>刹那芳华BBS 论坛</h1>
<form
	action="./addUser.php"
	method="POST"
>
用户名:<input id="user" type="text" name="userName"><br />
密码:<input id="pas1" type="password" name="userPass1"><br />
确认密码:<input id="pas2" type="password" name="userPass2"><br />
<script>
function fm(){
	var ps1=document.getElementById('pas1');
	var ps2=document.getElementById('pas2');
	if(ps1.value != ps2.value){
		alert("两次密码输入不一致,请重新输入");
		ps1.value="";
		ps2.value="";
	}
}
</script>
<input type="submit" onmouseover="fm()" name="userSubmit" value="注册">
 
</form>
	<hr />
</body>
</html>

C:\phpStudy\WWW\PHP\xnfhbbs\member\update.php

<meta charset="utf-8">
<?php
include "../inc/dblink.inc.php";
?>
<?php
if(isset($_POST['userSubmit'])){
	$userName = $_COOKIE['name'];
	$tmp_path = $_FILES['up']['tmp_name'];
	//echo $tmp_path;
	$path = ".\\image\\".$_FILES['up']['name'];
	//echo $path;
	//echo "<hr />";
	if(move_uploaded_file($tmp_path,$path)){
		$path = mysqli_real_escape_string($link,$path);
		$sql = "update users set photo='".$path."' where name='".$userName."'";
		//echo $sql;
		if(mysqli_query($link,$sql)){
			echo "图片上传成功,<a 
			href='./index.php'>返回个人中心</a>";
		}else{
			die(mysqli_error($link));
		}
	}else{
		echo "图片上传失败!";
	}
}else{
$html=<<<HTML
<form
	method="POST";
	enctype="multipart/form-data"
>
<input type="file" name="up"><br />
<input type="submit" name="userSubmit" value="提交">
</form>
HTML;
echo $html;
}
?>
<?php
mysqli_close($link);
?>
  • 1
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值