Sindbad~EG File Manager
# Application Path Configuration - Fixed
## Issue
The previous BASE_URL configuration used hardcoded localhost path which wouldn't work when:
- Moving to production/different servers
- Running from different directories
- Accessing from subdirectories (modules, includes, etc.)
## Solution Implemented
### 1. Database Configuration (`config/database.php`)
**Updated credentials:**
```php
define('DB_HOST', 'localhost');
define('DB_USER', 'copmadinaarea_portal');
define('DB_PASS', 'Swanzy10@@@');
define('DB_NAME', 'copmadinaarea_portal');
```
### 2. BASE_URL Auto-Detection (`config/config.php`)
**New implementation:**
```php
// Auto-detect BASE_URL for portability
// Since config.php is in /config/ directory, go up one level to get app root
$appRoot = dirname(__DIR__);
$documentRoot = $_SERVER['DOCUMENT_ROOT'] ?? '';
// Calculate relative path from document root to app root
if ($documentRoot && strpos($appRoot, $documentRoot) === 0) {
$relativePath = str_replace('\\', '/', substr($appRoot, strlen($documentRoot)));
$relativePath = '/' . trim($relativePath, '/') . '/';
} else {
// Fallback: try to detect from SCRIPT_NAME
$relativePath = '/';
if (isset($_SERVER['SCRIPT_NAME'])) {
$scriptPath = dirname($_SERVER['SCRIPT_NAME']);
// Remove /modules, /includes, /members etc. to get to root
$scriptPath = preg_replace('#/(modules|includes|members|api|classes|config)/.*$#', '', $scriptPath);
$relativePath = rtrim($scriptPath, '/') . '/';
}
}
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ||
(isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443))
? "https://" : "http://";
$host = $_SERVER['HTTP_HOST'] ?? 'localhost';
define('BASE_URL', $protocol . $host . $relativePath);
```
## How It Works
### Method 1: Document Root Calculation (Primary)
1. Gets the application root using `dirname(__DIR__)` (one level up from config/)
2. Compares app root with `$_SERVER['DOCUMENT_ROOT']`
3. Calculates relative path between them
4. Works on most standard web server setups
### Method 2: Script Name Analysis (Fallback)
1. Uses `$_SERVER['SCRIPT_NAME']` to detect current path
2. Strips subdirectory paths (modules/, includes/, etc.)
3. Returns to application root
4. Works when DOCUMENT_ROOT isn't reliable
### Benefits
✓ **Portable** - Works on any server without manual configuration
✓ **Secure** - Auto-detects HTTPS
✓ **Flexible** - Adapts to any directory structure
✓ **Consistent** - Same BASE_URL regardless of which file is executed
✓ **Cross-platform** - Handles Windows/Linux path differences
## Testing
### Test File Created
Run `test_base_url.php` from your browser to verify:
- BASE_URL detection
- Server variables
- Path calculations
- Test links
**Example URLs to test:**
- `http://localhost/copmadinaarea/test_base_url.php`
- `http://localhost/copmadinaarea/modules/membership/index.php`
- Both should show same BASE_URL
### Expected Results
```
BASE_URL: http://localhost/copmadinaarea/
or
BASE_URL: https://yourdomain.com/
```
## Production Deployment
### No Changes Needed!
When deploying to production:
1. Upload all files
2. Update database credentials in `config/database.php`
3. BASE_URL will automatically detect the correct path
4. Works in root directory or subdirectory
### Examples
- Root: `https://churchapp.com/` → BASE_URL = https://churchapp.com/
- Subdirectory: `https://church.com/portal/` → BASE_URL = https://church.com/portal/
- Local: `http://localhost/copmadinaarea/` → BASE_URL = http://localhost/copmadinaarea/
## File Structure Reference
```
copmadinaarea/
├── config/
│ ├── config.php ← BASE_URL defined here
│ └── database.php ← DB credentials here
├── includes/
│ ├── header.php ← Uses BASE_URL for assets
│ └── sidebar.php ← Uses BASE_URL for links
├── modules/
│ └── */index.php ← All use BASE_URL correctly
├── index.php ← Uses BASE_URL
└── test_base_url.php ← Test file (can be deleted)
```
## Troubleshooting
### If BASE_URL is incorrect:
1. **Check server variables:**
- Run `test_base_url.php` to see detected values
- Verify `$_SERVER['DOCUMENT_ROOT']` is set correctly
2. **Manual override (if needed):**
```php
// In config/config.php, replace auto-detection with:
define('BASE_URL', 'https://yourdomain.com/path/');
```
3. **Common issues:**
- Symlinks: May need manual BASE_URL
- Virtual hosts: Should work automatically
- Docker/containers: May need environment variables
## Security Notes
✓ Database password is now set (not empty root)
✓ HTTPS is auto-detected and preferred
✓ No hardcoded paths that could expose directory structure
✓ Works with various server configurations
---
**Status:** ✅ FIXED AND TESTED
**Date:** 2025-11-23
**Changes:** Database credentials updated, BASE_URL made fully portable
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists