通过cookie、PHP、localstorage实现登录注册功能

1.cookie实现简单的登录注册

注册功能:


	用户名:
密 码:

登录功能:


		用户名 : 
密 码 :

PHP文件

alert('邮箱已被注册');location.href = 'register.html'";
	}else{
		$sql = "insert into users (`email`,`upwd`) values( '$email','$upwd' )";	
		$row = mysql_query( $sql );
		if( $row ){
			echo "";
		}else{
			echo "";
		}
	}
	
	/*include "public.php";
	//1、接收数据
	$email = $_POST["email"];
	$upwd = $_POST["upwd"];
	 
	//先查询邮箱email在数据库中是否存在  
	$sqlSel = "select * from users where email = '$email'";
	//mysql_query() 函数执行一条 MySQL 查询。
	$res = mysql_query( $sqlSel );
	//mysql_fetch_array() 函数从结果集中取得一行作为关联数组,或数字数组,或二者兼有
	//返回根据从结果集取得的行生成的数组,如果没有更多行则返回 false
	$arr = mysql_fetch_array( $res );
	if( $arr ){ //数组存在 说明邮箱已经被注册
		echo "";
	}else{
		//第四步 : 编写sql语句  注册功能--insert
		$sql = "insert into users(`email`,`upwd`) values('$email','$upwd')";
		
		//第五步 : 执行sql语句
		$row = mysql_query( $sql ); //返回受影响的行数
		//3、返回结果
		if( $row ){
			echo "";
		}else{
			echo "";
		}
	}
	*/
	
?>

登录功能


		
邮 箱:
密 码:

PHP文件

alert('登录成功');location.href = 'index.php?email=$email';";
		}else{
			echo "";
		}
	}else{
		echo "";
	}
	
	/*
	//引入外部的php文件
	include "public.php";
	
	//1、接收数据
	$email = $_POST["email"];
	$upwd = $_POST["upwd"];
	//2、处理数据
	
	//第四步 : 编写sql语句  登陆功能--select
	$sql = "SELECT * FROM `users` WHERE `email`='$email'";
	
	//第五步 : 执行sql语句  mysql_query执行查询操作时,返回一个资源类型, 返回一个结果集合
	$res = mysql_query($sql);  
	
	//取出资源类型中的数据  取出结果集中的数据  mysql_fetch_array()  一次只能取一行数据 并返回一个数组
	$arr = mysql_fetch_array( $res );
	
	//3、返回结果
	if( $arr ){//如果数组存在 说明用户名是存在
		if( $arr["upwd"] == $upwd ){//判断密码是否相等
			//登录成功  跳转到学生成绩的列表上
			echo "";
		}else{
			echo "";
		}
	}else{
		//用户名不存在
		echo "";
	}*/

你可能感兴趣的:(笔记)