如何在php中使用登录/注册页面
我使用的是引导程序,我想用php使用登录/注册页面。我将index.html改为index.php,与如何在php中使用登录/注册页面,php,twitter-bootstrap-3,Php,Twitter Bootstrap 3,我使用的是引导程序,我想用php使用登录/注册页面。我将index.html改为index.php,与register.php和login.php 这是我的login.php文件中的一部分,它以前是login.html 我有一个base.php文件,其中包含数据库的信息。我可以很好地使用数据库,我使用了更简单的代码 我的问题是:我是否要在这个页面中添加php代码,以及如何添加? 伊尼西奥·德塞西翁 奥维达斯特·图康瑟斯·尼娜? 托达维亚没有sos miembro? 这是一个很好的例子 您可
register.php
和login.php
这是我的login.php
文件中的一部分,它以前是login.html
我有一个base.php
文件,其中包含数据库的信息。我可以很好地使用数据库,我使用了更简单的代码
我的问题是:我是否要在这个页面中添加php代码,以及如何添加?
伊尼西奥·德塞西翁
奥维达斯特·图康瑟斯·尼娜?
托达维亚没有sos miembro?
这是一个很好的例子
您可以使用php self方法将表单发送到login.php本身。确保您的表单具有操作和方法
<?php
if(isset($_POST['login-form'])) {
// Your Code Here
}
?>
<html>
<body>
<form action=<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?> method="post" enctype="multipart/form-data" >
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<button type="submit" name="login-form"> Submit </button>
</form>
首先,你应该在互联网上搜索有许多教程可供登录和注册演示
快速解决方案
<?php
include('base.php');
session_start(); // Starting Session
$error=''; // Variable To Store Error Message
if (isset($_POST['submit'])) {
if (empty($_POST['username']) || empty($_POST['password'])) {
$error = "Username or Password is invalid";
}
else
{
// Define $username and $password
$username=$_POST['username'];
$password=$_POST['password'];
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
// Selecting Database
$db = mysql_select_db("company", $connection); //$connection -> Connection of the database from base.php
// Assuming you have table LOGIN or Change the table name with your along with the database columns
// SQL query to fetch information of registerd users and finds user match.
$query = mysql_query("select * from login where password='$password' AND username='$username'", $connection);
$rows = mysql_num_rows($query);
if ($rows == 1) {
// Session to check whether the user is logged in or not in another pages
$_SESSION['login_user'] = $username; // Initializing Session
header("location: PageYouWantAfterLogin.php"); // Redirecting To Other Page
} else {
$error = "Username or Password is invalid";
}
mysql_close($connection); // Closing Connection
}
}
?>
<input type="text" name="username" class="user" value="Tu Correo Electrónico" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Tu Correo Electrónico';}"/>
<input type="password" name="password" class="lock" value="password" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Email address:';}"/>
<input name="submit" type="submit" value=" Login ">
<form action="" method="post">