PHP登录界面实例

<!-- HTML 页面 -->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <div class="login">
        <h1>登录</h1>
        <?php
            // 获取表单提交的数据
            $username = $_POST['username'];
            $password = $_POST['password'];

            // 如果表单已提交
            if ($_SERVER['REQUEST_METHOD'] == 'POST') {
                // 验证用户输入
                if ($username == 'admin' && $password == 'admin123') {
                    // 登录成功,跳转到欢迎页面
                    header('Location: welcome.php');
                    exit();
                } else {
                    // 登录失败,显示错误提示
                    echo '<p class="error">用户名或密码不正确</p>';
                }
            }
        ?>
        <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
            <input type="text" name="username" placeholder="用户名" required>
            <input type="password" name="password" placeholder="密码" required>
            <button type="submit">登录</button>
        </form>
    </div>
</body>
</html>

上述代码使用了 HTML 和 PHP 混合编程的方式,通过 HTML 表单提交用户输入的用户名和密码,PHP 代码接收并验证数据,如果登录成功则跳转到欢迎页面,否则显示错误提示。以下是代码的注释:

<!-- HTML 页面 -->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <link rel="stylesheet" href="styles.css"> <!-- 引入 CSS 样式表 -->
</head>
<body>
    <div class="login"> <!-- 开始登录界面的 DIV 容器 -->
        <h1>登录</h1> <!-- 显示登录标题 -->
        <?php
            // 获取表单提交的数据
            $username = $_POST['username'];
            $password = $_POST['password'];

            // 如果表单已提交
            if ($_SERVER['REQUEST_METHOD'] == 'POST') {
                // 验证用户输入
                if ($username == 'admin' && $password == 'admin123') {
                    // 登录成功,跳转到欢迎页面
                    header('Location: welcome.php');
                    exit(); // 退出程序
                } else {
                    // 登录失败,显示错误提示
                    echo '<p class="error">用户名或密码不正确</p>';
                }
            }
        ?>
        <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
            <!-- 显示登录表单 -->
            <input type="text" name="username" placeholder="用户名" required>
            <input type="password" name="password" placeholder="密码" required>
            <button type="submit">登录</button>
        </form>
    </div> <!-- 结束登录界面的 DIV 容器 -->
</body>
</html>

此外,我们还可以添加 CSS 样式表来美化登录页面。例如,以下是一个简单的 CSS 样式表,可为登录界面添加一些基本样式:

.login {
    width: 400px;
    margin: 50px auto;
    text-align: center;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0px 0px 10px #666;
    background-color: #fff;
}
h1 {
    margin-top: 0;
    color: #333;
    font-weight: normal;
}
input[type="text"],
input[type="password"],
button {
    width: 100%;
    padding: 10px;
    margin-bottom: 20px;
    border-radius: 5px;
    border: none;
}
input[type="text"]:focus,
input[type="password"]:focus {
    outline: none;
    box-shadow: 0px 0px 5px #ccc;
}
button[type="submit"] {
    background-color: #39f;
    color: #fff;
    cursor: pointer;
    transition: background-color 0.2s ease;
}
button[type="submit"]:hover {
    background-color: #66a6e1;
}
.error {
    color: #f00;
}

最终,经过以上步骤,我们可以获得一个简单美观的登录界面。

 

  • 1
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,下面是一个简单的 Android 闪屏动态界面设置和跳转到登录界面实例演示: 1. 首先,在 res/layout 目录下创建一个名为 activity_splash.xml 的布局文件,用于设置闪屏动态界面,如下所示: ```xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/splash_image" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" android:src="@drawable/splash_image" /> <TextView android:id="@+id/splash_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="Welcome to my app!" android:textColor="@android:color/white" android:textSize="24sp" /> </RelativeLayout> ``` 2. 在 res/drawable 目录下添加一张名为 splash_image 的启动图片。 3. 在 res/values/styles.xml 文件中添加一个名为 SplashTheme 的主题样式,用于设置闪屏动态界面的背景颜色、字体颜色等属性,如下所示: ```xml <style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:windowBackground">@color/colorSplash</item> <item name="android:textColor">@android:color/white</item> <item name="android:textSize">24sp</item> </style> ``` 4. 在 AndroidManifest.xml 文件中将应用的启动 Activity 设置为 SplashActivity,并将 SplashActivity 的主题设置为 SplashTheme,如下所示: ```xml <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".SplashActivity" android:theme="@style/SplashTheme"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".LoginActivity" /> </application> ``` 5. 在 SplashActivity 中设置延迟跳转到 LoginActivity,如下所示: ```java public class SplashActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); new Handler().postDelayed(new Runnable() { @Override public void run() { Intent intent = new Intent(SplashActivity.this, LoginActivity.class); startActivity(intent); finish(); } }, 3000); //延迟 3 秒跳转到 LoginActivity } } ``` 以上就是一个简单的 Android 闪屏动态界面设置和跳转到登录界面实例演示。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

需要什么私信我

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值