Here's a simple PHP script for user registration and login using a MySQL database:

<?php
// www.websitefunctions.com

// Database connection settings

$servername = "localhost";

$username = "your_username";

$password = "your_password";

$dbname = "your_database_name";

 

// Create connection

$conn = new mysqli($servername, $username, $password, $dbname);

 

// Check connection

if ($conn->connect_error) {

    die("Connection failed: " . $conn->connect_error);

}

 

// User registration

if(isset($_POST['register'])) {

    $username = $_POST['username'];

    $password = $_POST['password'];

    

    // Hash the password

    $hashed_password = password_hash($password, PASSWORD_DEFAULT);

    

    $sql = "INSERT INTO users (username, password) VALUES ('$username', '$hashed_password')";

    

    if ($conn->query($sql) === TRUE) {

        echo "Registration successful!";

    } else {

        echo "Error: " . $sql . "<br>" . $conn->error;

    }

}

 

// User login

if(isset($_POST['login'])) {

    $username = $_POST['username'];

    $password = $_POST['password'];

    

    $sql = "SELECT password FROM users WHERE username = '$username'";

    $result = $conn->query($sql);

    

    if ($result->num_rows == 1) {

        $row = $result->fetch_assoc();

        $stored_password = $row['password'];

        

        if (password_verify($password, $stored_password)) {

            echo "Login successful!";

        } else {

            echo "Invalid username or password.";

        }

    } else {

        echo "Invalid username or password.";

    }

}

 

// Close the database connection

$conn->close();

?>

 

<!DOCTYPE html>

<html>

<head>

    <title>User Registration and Login</title>

</head>

<body>

    <h2>User Registration</h2>

    <form method="post" action="">

        <label for="username">Username:</label>

        <input type="text" name="username" required><br><br>

        

        <label for="password">Password:</label>

        <input type="password" name="password" required><br><br>

        

        <input type="submit" name="register" value="Register">

    </form>

    

    <h2>User Login</h2>

    <form method="post" action="">

        <label for="username">Username:</label>

        <input type="text" name="username" required><br><br>

        

        <label for="password">Password:</label>

        <input type="password" name="password" required><br><br>

        

        <input type="submit" name="login" value="Login">

    </form>

</body>

</html>

Make sure to replace 'your_username', 'your_password', and 'your_database_name' with your actual database credentials. Also, ensure that the table named users exists in your MySQL database with columns username (VARCHAR) and password (VARCHAR) to store user information.

This script includes two sections: user registration and user login. When the user fills in the registration form and submits it, their username and hashed password will be stored in the database. For user login, the script checks if the entered username exists in the database and verifies the entered password against the stored hashed password.

Remember to validate and sanitize user input to prevent SQL injection and other security vulnerabilities. Additionally, it's recommended to use prepared statements or an ORM (Object-Relational Mapping) library for secure database interactions.