CREATE A DOMAIN AGECHECKER IN PHP
- User
CREATE A DOMAIN AGECHECKER IN PHP
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
CREATE A DOMAIN AGECHECKER IN PHP
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Here's a simple PHP script to check a domain's age:
<?php
function getDomainAge($domain) {
// Remove http://, https://, www. if present
$domain = preg_replace('/^(https?:\/\/)?(www\.)?/', '', $domain);
// Get domain information using whois
$whoisData = shell_exec("whois $domain");
// Try to find creation date in different formats
$patterns = [
'/Creation Date: ([^\n]+)/',
'/created: ([^\n]+)/',
'/Domain Registration Date: ([^\n]+)/',
'/Registered on: ([^\n]+)/',
'/Created: ([^\n]+)/'
];
foreach ($patterns as $pattern) {
if (preg_match($pattern, $whoisData, $matches)) {
$creationDate = strtotime(trim($matches[1]));
if ($creationDate) {
$age = time() - $creationDate;
$years = floor($age / (365 * 24 * 60 * 60));
$months = floor(($age % (365 * 24 * 60 * 60)) / (30 * 24 * 60 * 60));
return [
'domain' => $domain,
'creation_date' => date('Y-m-d', $creationDate),
'age_years' => $years,
'age_months' => $months,
'age_days' => floor(($age % (30 * 24 * 60 * 60)) / (24 * 60 * 60))
];
}
}
}
return [
'domain' => $domain,
'error' => 'Creation date not found'
];
}
// Example usage
if (isset($_POST['domain'])) {
$domain = $_POST['domain'];
$result = getDomainAge($domain);
header('Content-Type: application/json');
echo json_encode($result);
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Domain Age Checker</title>
<style>
body { font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 20px; }
.result { margin-top: 20px; padding: 15px; border: 1px solid #ddd; border-radius: 5px; }
input[type="text"] { width: 70%; padding: 8px; }
button { padding: 8px 15px; background: #4CAF50; color: white; border: none; cursor: pointer; }
</style>
</head>
<body>
<h1>Domain Age Checker</h1>
<form id="domainForm">
<input type="text" id="domainInput" placeholder="Enter domain (e.g., example.com)" required>
<button type="submit">Check Age</button>
</form>
<div id="result" class="result" style="display: none;"></div>
<script>
document.getElementById('domainForm').addEventListener('submit', function(e) {
e.preventDefault();
const domain = document.getElementById('domainInput').value;
fetch('', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: 'domain=' + encodeURIComponent(domain)
})
.then(response => response.json())
.then(data => {
const resultDiv = document.getElementById('result');
resultDiv.style.display = 'block';
if (data.error) {
resultDiv.innerHTML = `<p>Error: ${data.error}</p>`;
} else {
resultDiv.innerHTML = `
<h3>Results for ${data.domain}</h3>
<p>Creation Date: ${data.creation_date}</p>
<p>Age: ${data.age_years} years, ${data.age_months} months, ${data.age_days} days</p>
`;
}
})
.catch(error => {
document.getElementById('result').innerHTML = `<p>Error: ${error.message}</p>`;
document.getElementById('result').style.display = 'block';
});
});
</script>
</body>
</html>
Would you like me to explain or break down this code?