douluan8828 2017-07-14 02:52
浏览 142
已采纳

如何使用php登录/注册页面

I am using a bootstrap and I want to use the login/ register page with php. I changed index.html to index.php same with register.php and login.php

So this is the section from my login.php file that used to be login.html.

I have a base.php file that has the information for my database. I can use the database just fine, I have done it with simpler code.

My question is : Do I add the php code in this page, and how do I do it?

<div class="sign-in-form-top">
    <h1>Inicio de Sesión</h1>
</div>
<div class="signin">
    <div class="signin-rit">
        <span class="checkbox1">
            <label class="checkbox"><input type="checkbox" name="checkbox" checked="">¿Olvidaste tu contraseña?</label>
        </span>
        <p><a href="#">Haz clic aquí</a> </p>
        <div class="clearfix"> </div>
    </div>
    <form>
        <div class="log-input">
            <div class="log-input-left">
                <input type="text" class="user" value="Tu Correo Electrónico" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Tu Correo Electrónico';}"/>
            </div>
            <span class="checkbox2">
                <label class="checkbox"><input type="checkbox" name="checkbox" checked=""><i> </i></label>
            </span>
            <div class="clearfix"> </div>
        </div>
        <div class="log-input">
            <div class="log-input-left">
                <input type="password" class="lock" value="password" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Email address:';}"/>
            </div>
            <span class="checkbox2">
                <label class="checkbox"><input type="checkbox" name="checkbox" checked=""><i> </i></label>
            </span>
            <div class="clearfix"> </div>
        </div>
        <input type="submit" value="Inicia Sesión">
    </form>    
</div>
<div class="new_people">
    <h2>¿Todavía no sos miembro?</h2>
    <p>Crea tu cuenta, es fácil y rápido.</p>
    <a href="register.php">¡Registrate Ahora!</a>

</div>
  • 写回答

2条回答 默认 最新

  • douzhong3887 2017-07-14 04:50
    关注

    First of all, you should search on the internet there are a number of tutorials are available for login and register demo.

    Quick solution.

    <?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
        }
    }
    ?>
    

    Please change the code for textbox and submit button

    <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 ">
    

    Also, change the <form> tag to below code. Read more about form here

    <form action="" method="post">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解
  • ¥15 有偿请教计算电磁学的问题涉及到空间中时域UTD和FDTD算法结合的
  • ¥15 three.js添加后处理以后模型锯齿化严重