用户注册和登录操作之后立即执行

时间:2015-07-31 07:35:10

标签: php

我想实现一个php文件,可以在此之后立即执行用户注册和登录操作。

我认为代码结构应该如下:

注册和login.php

<?php
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST['username'];
$password = $_POST['password'];
//Check the fields.If they are correct
//Check if the username exists and password is correct
$_SESSION['login_user']=$username;
//Go to the profile.php.
//But if the username does not exists, insert the username and password in table}

else {mysql_close($connection);}

上面的代码能否正常运行,对我的问题是一个很好的答案吗?

1 个答案:

答案 0 :(得分:0)

这也是一个很好的方法......

首先检查具有该用户名/电子邮件的用户是否已存在

如果存在,则匹配用户名和密码,并为该用户创建会话

如果没有,那么创建用户,然后在那里为该用户创建一个会话(这意味着用户也已登录)