Updated PHP Windows builds for Brotli security fix

Özgün MySQL API

Giriş

Bu eklentinin kullanımı PHP 5.5.0 itibariyle önerilmemekte olup PHP 7.0.0'da kaldırılmıştır. Bu eklentinin yerine ya mysqli ya da PDO_MySQL eklentisi kullanılmalıdır. MySQL API seçerken MySQL API'ye Bakış belgesi yardımcı olabilir.

Bu işlevler MySQL veritabanı sunucularına erişmenizi sağlar. MySQL hakkında daha fazla bilgi » https://www.mysql.com/ adresinde bulunabilir.

MySQL belgeleri » https://dev.mysql.com/doc/ adresinde bulunabilir.

MySQL veritabanı ürünleri ve bağlanabilirlik kuralları hakkında Overview bölümünde bilgi bulabilirsiniz.

+add a note

User Contributed Notes 1 note

up
0
taegmyial at gmail dot com
5 months ago
<?php
// 1. Session start must always be at the very top
session_start();

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "my_db";

// Database connection (MySQLi)
$conn = new mysqli($servername, $username, $password, $dbname);

// If the form was submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {

    $user = $_POST['username'];
    $pass = $_POST['password'];

    // 2. Find the user in the database by username
    // (Prepared Statements should be used here for security, see Topic 24)
    $sql = "SELECT id, password_hash FROM users WHERE username = '$user'";
    $result = $conn->query($sql);

    if ($result->num_rows > 0) {
        $row = $result->fetch_assoc();

        // 3. Verify the password using password_verify
        if (password_verify($pass, $row['password_hash'])) {

            // Password is correct -> Save user data into Session
            $_SESSION["loggedin"] = true;
            $_SESSION["userid"] = $row["id"];
            $_SESSION["username"] = $user;

            echo "Welcome, you are logged in!";
        } else {
            echo "Incorrect password.";
        }
    } else {
        echo "User does not exist.";
    }
}
?>
To Top