Skip to content

anikchand461/AnyoneHere

Repository files navigation

💬 AnyoneHere

A minimal, real-time-feeling chat app built with plain PHP, MySQL, and vanilla JS.

No frameworks. No build step. Just clean code and live conversations.

Live Demo PHP MySQL JavaScript

🚀 Try the Live Demo →


AnyoneHere login screen

✨ Overview

AnyoneHere is a lightweight one-to-one messaging app. Sign up, see who's online right now, and jump into a conversation — all wrapped in a clean, dark-and-white interface inspired by modern messaging apps.

It's built without any frameworks on purpose: just mysqli prepared statements, a sprinkle of fetch(), and old-fashioned short-polling to simulate real-time updates. A great reference project if you want to understand how chat apps work under the hood before reaching for sockets.

🧩 Features

🔐 Secure Auth Passwords hashed with password_hash(), verified with password_verify()
🟢 Live Presence Heartbeat pings every 5s mark users "online" for a 10-second window
👥 Active Users List Dashboard shows everyone currently online, refreshed automatically
💬 1-on-1 Conversations Clean chat bubbles with sender/receiver styling
🔄 Auto-Refreshing Chat Messages poll every second — no page reloads needed
🧹 Self-Cleaning Messages older than 24 hours are purged automatically
📱 Responsive UI Mobile-friendly layout with safe-area support for notched devices
🛡️ SQL Injection Safe Every query uses parameterized statements

🛠️ Tech Stack

  • Backend: PHP (mysqli, prepared statements)
  • Database: MySQL
  • Frontend: Vanilla HTML, CSS, JavaScript (no frameworks, no dependencies)
  • Realtime simulation: Client-side polling (fetch + setInterval)

📁 Project Structure

anyonehere/
├── index.php              # Login page
├── register.php           # Account creation
├── dashboard.php          # List of currently active users
├── conversation.php       # 1-on-1 chat view
├── send-message.php       # Handles new message submission
├── fetch-messages.php     # Polled endpoint that renders message history
├── heartbeat.php          # Updates last_seen timestamp for presence
├── user-status.php        # Returns online/offline status for a user
├── style.css              # Global styles (auth, dashboard, chat)
├── script.js              # Polling, heartbeat, send/receive logic
├── config.example.php     # Template for DB credentials
├── config.php             # Your local DB credentials (gitignored)
└── database.sql           # Database schema

⚙️ Getting Started

Prerequisites

  • PHP 7.4+ with the mysqli extension
  • MySQL / MariaDB
  • Any local server stack (XAMPP, MAMP, php -S, etc.)

Installation

1. Clone the repository

git clone https://github.com/your-username/anyonehere.git
cd anyonehere

2. Create the database

mysql -u root -p < database.sql

This creates the chat database along with the users and messages tables.

3. Configure your environment

Copy the example config and fill in your own credentials:

cp config.example.php config.php
$server   = "localhost";
$username = "YOUR_DB_USERNAME";
$password = "YOUR_DB_PASSWORD";
$database = "YOUR_DB_NAME";

⚠️ Never commit config.php with real credentials. It's meant to stay local — keep it out of version control.

4. Run it

php -S localhost:8000

Then visit http://localhost:8000 in your browser 🎉

🗄️ Database Schema

Click to expand

users

Column Type Notes
id INT Primary key, auto-increment
username VARCHAR(50) Unique
password VARCHAR(255) Hashed with password_hash()
last_seen DATETIME Used to determine online status

messages

Column Type Notes
id INT Primary key, auto-increment
sender_id INT FK → users.id
receiver_id INT FK → users.id
message TEXT Message content
created_at TIMESTAMP Auto-purged after 24h

🧠 How Presence & Polling Work

  • Every open session pings heartbeat.php every 5 seconds, updating last_seen.
  • A user is considered online if their last_seen is within the last 10 seconds.
  • The active chat polls fetch-messages.php every 1 second to pull new messages, comparing the response against the last render to avoid unnecessary DOM updates.
  • user-status.php polls every 3 seconds to reflect the other person going online/offline in real time.

🌐 Live Demo

Give it a spin here → anyonehere.freehosting.dev

Create an account, open a second browser (or incognito tab), sign in as someone else, and chat with yourself in real time. 👻

🤝 Contributing

Pull requests are welcome! For major changes, please open an issue first to discuss what you'd like to change.

📄 License

This project is open source and available under the MIT License.


Made with 🖤 and plain old PHP

About

A minimal, real-time-feeling chat app built with plain PHP, MySQL, and vanilla JS.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors