Template Customization Guide
Learn how to integrate and display affiliate data in your templates with our simple PHP code snippets.
Quick Start Integration
Add this code at the beginning of your template to fetch affiliate data. The system automatically detects the current domain and loads the corresponding affiliate information.
<?php
// =============================================
// AFFILIATE DATA INTEGRATION
// Place this code at the very top of your template
// =============================================
// Detect current domain
$currentDomain = str_replace('www.', '', $_SERVER['HTTP_HOST']);
// API endpoint
$apiUrl = "https://api.licenselabs.site/api.php?action=affiliate_info&domain=" . urlencode($currentDomain);
// Fetch affiliate data
$response = @file_get_contents($apiUrl);
$affiliate = [];
if ($response) {
$data = json_decode($response, true);
if ($data['status'] === 'success' && isset($data['affiliate'])) {
$affiliate = $data['affiliate'];
}
}
// Helper function for logo URL
function getAffiliateLogoUrl($logoPath) {
if (empty($logoPath)) return '';
return 'https://licenselabs.site/user/' . $logoPath;
}
?>
Important Note
After adding the setup code, the $affiliate array will contain all your affiliate data. You can then use the following snippets anywhere in your template.
Available Affiliate Fields
These are all the fields you can access from the $affiliate array:
| Field Name | Type | Description | Usage Example |
|---|---|---|---|
| affiliate_id | String | Unique affiliate identifier | $affiliate['affiliate_id'] |
| name | String | Affiliate full name | $affiliate['name'] |
| String | Email address | $affiliate['email'] |
|
| custom_title | String | Custom page title | $affiliate['custom_title'] |
| custom_logo | String | Logo file path | getAffiliateLogoUrl($affiliate['custom_logo']) |
| custom_description | String | Meta description | $affiliate['custom_description'] |
| custom_keywords | String | Meta keywords | $affiliate['custom_keywords'] |
| domain | String | Affiliate domain | $affiliate['domain'] |
| template | String | Template name | $affiliate['template'] |
| status | String | Account status | $affiliate['status'] |
| facebook_pixel | Text | Facebook Pixel code | htmlspecialchars_decode($affiliate['facebook_pixel']) |
| google_analytics | Text | Google Analytics code | htmlspecialchars_decode($affiliate['google_analytics']) |
| custom_css | Text | Custom CSS styles | htmlspecialchars_decode($affiliate['custom_css']) |
| custom_js | Text | Custom JavaScript | htmlspecialchars_decode($affiliate['custom_js']) |
Individual Field Display Codes
Use these code snippets to display specific fields anywhere in your template. Each snippet is independent and can be placed in different sections of your page.
Display Affiliate Name
<?php if (!empty($affiliate['name'])): ?>
<h1 class="affiliate-name">
<?php echo htmlspecialchars($affiliate['name']); ?>
</h1>
<?php endif; ?>
Display Affiliate ID
<?php if (!empty($affiliate['affiliate_id'])): ?>
<p class="affiliate-id">
<strong>Affiliate ID:</strong>
<?php echo htmlspecialchars($affiliate['affiliate_id']); ?>
</p>
<?php endif; ?>
Display Email
<?php if (!empty($affiliate['email'])): ?>
<p class="affiliate-email">
<strong>Email:</strong>
<a href="mailto:<?php echo htmlspecialchars($affiliate['email']); ?>">
<?php echo htmlspecialchars($affiliate['email']); ?>
</a>
</p>
<?php endif; ?>
Display Custom Title
<title>
<?php
if (!empty($affiliate['custom_title'])) {
echo htmlspecialchars($affiliate['custom_title']);
} else {
echo htmlspecialchars($affiliate['name'] ?? 'Default Title');
}
?>
</title>
Display Logo
<?php if (!empty($affiliate['custom_logo'])):
$logoUrl = 'https://licenselabs.site/user/' . $affiliate['custom_logo'];
?>
<div class="logo-container">
<img src="<?php echo htmlspecialchars($logoUrl); ?>"
alt="<?php echo htmlspecialchars($affiliate['name']); ?> Logo"
class="affiliate-logo">
</div>
<?php endif; ?>
Meta Description
<?php if (!empty($affiliate['custom_description'])): ?>
<meta name="description"
content="<?php echo htmlspecialchars($affiliate['custom_description']); ?>">
<?php endif; ?>
Meta Keywords
<?php if (!empty($affiliate['custom_keywords'])): ?>
<meta name="keywords"
content="<?php echo htmlspecialchars($affiliate['custom_keywords']); ?>">
<?php endif; ?>
Display Domain
<?php if (!empty($affiliate['domain'])): ?>
<p class="affiliate-domain">
<strong>Domain:</strong>
<?php echo htmlspecialchars($affiliate['domain']); ?>
</p>
<?php endif; ?>
Display Template
<?php if (!empty($affiliate['template'])): ?>
<p class="template-name">
<strong>Template:</strong>
<?php echo htmlspecialchars($affiliate['template']); ?>
</p>
<?php endif; ?>
Display Status
<?php if (!empty($affiliate['status'])): ?>
<span class="status-badge status-<?php echo $affiliate['status']; ?>">
<?php echo ucfirst($affiliate['status']); ?>
</span>
<?php endif; ?>
Tracking Codes Integration
Facebook Pixel
<?php if (!empty($affiliate['facebook_pixel'])): ?>
<!-- Facebook Pixel Code -->
<?php echo htmlspecialchars_decode($affiliate['facebook_pixel']); ?>
<?php endif; ?>
Google Analytics
<?php if (!empty($affiliate['google_analytics'])): ?>
<!-- Google Analytics Code -->
<?php echo htmlspecialchars_decode($affiliate['google_analytics']); ?>
<?php endif; ?>
Important
Always use htmlspecialchars_decode() when outputting tracking codes to ensure proper JavaScript execution.
Custom CSS & JavaScript
Custom CSS
<?php if (!empty($affiliate['custom_css'])): ?>
<style>
<?php echo htmlspecialchars_decode($affiliate['custom_css']); ?>
</style>
<?php endif; ?>
Custom JavaScript
<?php if (!empty($affiliate['custom_js'])): ?>
<script>
<?php echo htmlspecialchars_decode($affiliate['custom_js']); ?>
</script>
<?php endif; ?>
Complete Template Example
Here's a complete HTML template with all affiliate fields integrated:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<?php
// Setup code (place at the top)
$currentDomain = str_replace('www.', '', $_SERVER['HTTP_HOST']);
$apiUrl = "https://api.licenselabs.site/api.php?action=affiliate_info&domain=" . urlencode($currentDomain);
$response = @file_get_contents($apiUrl);
$affiliate = [];
if ($response) {
$data = json_decode($response, true);
if ($data['status'] === 'success' && isset($data['affiliate'])) {
$affiliate = $data['affiliate'];
}
}
function getAffiliateLogoUrl($logoPath) {
if (empty($logoPath)) return '';
return 'https://licenselabs.site/user/' . $logoPath;
}
?>
<!-- Dynamic Title -->
<title><?php echo htmlspecialchars($affiliate['custom_title'] ?? $affiliate['name'] ?? 'Affiliate Site'); ?></title>
<!-- Meta Tags -->
<?php if (!empty($affiliate['custom_description'])): ?>
<meta name="description" content="<?php echo htmlspecialchars($affiliate['custom_description']); ?>">
<?php endif; ?>
<?php if (!empty($affiliate['custom_keywords'])): ?>
<meta name="keywords" content="<?php echo htmlspecialchars($affiliate['custom_keywords']); ?>">
<?php endif; ?>
<!-- Tracking Codes -->
<?php if (!empty($affiliate['facebook_pixel'])) echo htmlspecialchars_decode($affiliate['facebook_pixel']); ?>
<?php if (!empty($affiliate['google_analytics'])) echo htmlspecialchars_decode($affiliate['google_analytics']); ?>
<!-- Custom CSS -->
<?php if (!empty($affiliate['custom_css'])): ?>
<style><?php echo htmlspecialchars_decode($affiliate['custom_css']); ?></style>
<?php endif; ?>
<style>
/* Default styles */
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: Arial, sans-serif; line-height: 1.6; }
.header { background: #f4f4f4; padding: 20px; text-align: center; }
.logo { max-width: 200px; margin: 0 auto; }
.logo img { max-width: 100%; height: auto; }
.content { max-width: 1200px; margin: 20px auto; padding: 0 20px; }
.info-box { background: #fff; border: 1px solid #ddd; padding: 20px; margin: 10px 0; }
.status-active { color: green; }
.status-inactive { color: red; }
</style>
</head>
<body>
<header class="header">
<!-- Logo Display -->
<?php if (!empty($affiliate['custom_logo'])): ?>
<div class="logo">
<img src="<?php echo htmlspecialchars(getAffiliateLogoUrl($affiliate['custom_logo'])); ?>"
alt="<?php echo htmlspecialchars($affiliate['name']); ?>">
</div>
<?php endif; ?>
<!-- Affiliate Name -->
<h1><?php echo htmlspecialchars($affiliate['name'] ?? 'Welcome'); ?></h1>
</header>
<main class="content">
<div class="info-box">
<h2>Affiliate Information</h2>
<!-- Affiliate ID -->
<p><strong>Affiliate ID:</strong>
<?php echo htmlspecialchars($affiliate['affiliate_id'] ?? 'N/A'); ?>
</p>
<!-- Email -->
<p><strong>Email:</strong>
<a href="mailto:<?php echo htmlspecialchars($affiliate['email'] ?? ''); ?>">
<?php echo htmlspecialchars($affiliate['email'] ?? 'N/A'); ?>
</a>
</p>
<!-- Domain -->
<p><strong>Domain:</strong>
<?php echo htmlspecialchars($affiliate['domain'] ?? $currentDomain); ?>
</p>
<!-- Status -->
<p><strong>Status:</strong>
<span class="status-<?php echo $affiliate['status'] ?? 'inactive'; ?>">
<?php echo ucfirst($affiliate['status'] ?? 'inactive'); ?>
</span>
</p>
</div>
</main>
<!-- Custom JavaScript -->
<?php if (!empty($affiliate['custom_js'])): ?>
<script><?php echo htmlspecialchars_decode($affiliate['custom_js']); ?></script>
<?php endif; ?>
</body>
</html>
Best Practices & Tips
Always Escape Output
Use htmlspecialchars() when outputting text data to prevent XSS attacks.
Decode Tracking Codes
Use htmlspecialchars_decode() for Facebook Pixel and Google Analytics codes.
Logo URL Format
Always use the helper function getAffiliateLogoUrl() to ensure correct logo paths.
Check Empty Values
Always check if a field exists with !empty() before displaying it.
Error Handling
Provide default values when API data is not available.
Responsive Design
Ensure your template is mobile-friendly for better user experience.
Pro Tip
Test your template with different affiliate accounts to ensure all fields display correctly. Use the API test endpoint: https://api.licenselabs.site/api.php?action=test