I'm trying to display the year a website's domain was created using PHP. Just the year of the webpage it's being displayed on, nothing else.
So far I found this code by Greg Randall that is very close to what I'm looking for.
<?php
$url = "https://example.com/";
echo "Domain Create Date of $url " . date( 'F Y', strtotime( domainCreate($url) ) ) . " (" . domainCreate($url) . ")";
function domainCreate($url){
$parsed = parse_url( $url );
$domain = trim( $parsed[ 'host' ] );
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, "http://rdap.org/domain/$domain" );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$data = curl_exec( $ch );
$data = json_decode( $data, true );
curl_close( $ch );
return( $data[ 'events' ][ 0 ][ 'eventDate' ] );
}
?>
Output: Domain Create Date of https://example.com/ August 1995 (1995-08-14T04:00:00Z)
I need it to reference the website it's being displayed on. Perhaps ($_SERVER['HTTP_HOST'])
? And only output the year.
Add'l notes: I did a Google search and found the example above in a different post. When I posted a reply asking how to get the code to reference the current page, a mod deleted it. So that is why I had to create my own question. I've tried many variations and continue to get parsing errors. I've been reading and researching all day, I'm still learning. I've run out of steam and decided to ask for help.