A browser-based gang war game set in Los Santos. Players join a faction, move between districts, commit crimes, run drugs, and fight in real-time turf wars to control the city.
Built with PHP, MySQL, and vanilla JavaScript. No frameworks, no build step — drop it on any shared host and go.
- PHP 7.4+ with PDO and PDO_MySQL extensions enabled
- MySQL 5.7+ or MariaDB 10.3+
- Apache with
mod_rewrite(or equivalent Nginx config) - A web host or local stack (XAMPP, Laragon, etc.)
Create a new MySQL database and import the schema:
CREATE DATABASE turf_wars CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;Then import the schema file:
mysql -u your_user -p turf_wars < sols_turf_wars.sql
sols_turf_wars.sqlcontains all table definitions and seed data (factions, turfs, weapons, turf control) and is included in the root of the repo.
Copy the example env file and fill in your values:
cp .env.example .envEdit .env:
DB_HOST=localhost
DB_NAME=turf_wars
DB_USER=your_db_user
DB_PASS=your_db_password
DB_PORT=3306
The app reads these via getenv(). You can set them as Apache environment variables instead if you prefer — add to your .htaccess or VirtualHost:
SetEnv DB_HOST localhost
SetEnv DB_NAME turf_wars
SetEnv DB_USER your_db_user
SetEnv DB_PASS your_db_passwordNote: The
.envfile is not automatically loaded by PHP. If you use a.envfile you will need to load it via your server config (ApacheSetEnvIf), a PHP autoloader, or a library like vlucas/phpdotenv. The recommended approach for most hosts is to use ApacheSetEnvdirectives.
Upload all project files to your web root (e.g. public_html/). The includes/ directory contains sensitive files — it's protected by .htaccess but make sure your host respects .htaccess rules.
In includes/config.php, the base_url defaults to the APP_BASE_URL environment variable. Set this to your domain:
APP_BASE_URL=https://yourdomain.com
Or edit the fallback directly in config.php.
Register normally through the site. Then manually set is_admin = 1 for your user in the database:
UPDATE users SET is_admin = 1 WHERE username = 'your_username';The admin panel is then accessible at /admin.php.
All config is in includes/config.php. Values are read from environment variables with fallbacks:
| Env Variable | Default | Description |
|---|---|---|
DB_HOST |
127.0.0.1 |
Database host |
DB_NAME |
turf_wars |
Database name |
DB_USER |
db_user |
Database username |
DB_PASS |
(empty) | Database password |
DB_PORT |
3306 |
Database port |
APP_BASE_URL |
http://localhost |
Public URL of the site |
APP_SESSION_NAME |
stw_session |
PHP session cookie name |
To enable maintenance mode (blocks non-admin logins), set maintenance => true in config.php.
/
├── includes/ # Core PHP includes (DB, auth, config, CSRF, etc.)
│ ├── bootstrap.php # Loaded by every page
│ ├── config.php # App + DB configuration
│ ├── db.php # PDO singleton
│ ├── auth.php # Login/logout/session helpers
│ ├── functions.php # Shared utility functions
│ ├── logger.php # Game action logger
│ └── csrf.php # CSRF token generation + validation
├── templates/
│ ├── header.php # Nav, topbar, game shell open
│ └── footer.php # Game shell close
├── assets/
│ ├── css/ # Stylesheet
│ ├── js/ # Client-side game logic
│ └── img/ # Map, faction icons, UI images
├── index.php # Landing page
├── login.php # Login
├── register.php # Registration
├── dashboard.php # Main game screen
├── actions.php # All player actions (crime, drugs, capture, war, etc.)
├── turf.php # Interactive map
├── war.php # Real-time turf war screen
├── dominance.php # City control leaderboard
├── players.php # Player list
├── faction.php # Faction roster
├── admin.php # Admin panel
├── manual.php # In-game manual
└── sols_turf_wars.sql # Database schema + seed data
- All DB queries use PDO prepared statements
- CSRF tokens are validated on every POST and AJAX request
- The
includes/directory is blocked from direct web access via.htaccess - Passwords are hashed with
password_hash()/ verified withpassword_verify() - Never commit your
.envfile or put real credentials inconfig.php - The database user should have only
SELECT,INSERT,UPDATE,DELETE— notDROPorALTER
MIT — do whatever you want with it, just don't claim you made it from scratch.