On a multisite environment, get the subdomain value as variable

I’m trying to setup a multisite where everytime a new site is added, a DNS record is also added in Cloudflare. So far, the code is working but I’m having troubles trying to parse the subdomain value onto a variable.

This is the code so far:

function create_cloudflare_dns_record() {  //$  current_site = ''.$  get_blog_details->siteurl.''; //$  current_site = ''.$  substr( $  current_site, -8).''; //$  current_site = ''.explode('.', $  current_site).'';   /* Cloudflare.com | APİv4 | Api Ayarları */ $  apikey     = '778***************************c37'; // Cloudflare Global API $  email      = 'al******@***********.com'; // Cloudflare Email Adress $  domain     = 'mer*****.com';  // zone_name // Cloudflare Domain Name $  zoneid     = 'ecc**********************1e1'; // zone_id // Cloudflare Domain Zone ID //$  current_site   = ''.$  get_sites->path.''; $  current_site = explode('.', $  _SERVER['HTTP_HOST']);   // $  _SERVER['HTTP_HOST']  // A-record oluşturur DNS sistemi için. $  ch = curl_init("https://api.cloudflare.com/client/v4/zones/".$  zoneid."/dns_records"); curl_setopt($  ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($  ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($  ch, CURLOPT_SSL_VERIFYPEER,false); curl_setopt($  ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($  ch, CURLOPT_HTTPHEADER, array( 'X-Auth-Email: '.$  email.'', 'X-Auth-Key: '.$  apikey.'', 'Cache-Control: no-cache', // 'Content-Type: multipart/form-data; charset=utf-8', 'Content-Type:application/json', 'purge_everything: true'  ));  // -d curl parametresi. $  data = array(      'type' => 'CNAME',     'name' => ''.$  current_site.'',     'content' => 'mer***.com',     'zone_name' => ''.$  domain.'',     'zone_id' => ''.$  zoneid.'',     'proxied' => true,     'ttl' => '120' );  $  data_string = json_encode($  data);  curl_setopt($  ch, CURLOPT_POST, true); curl_setopt($  ch, CURLOPT_POSTFIELDS, $  data_string); //curl_setopt($  ch, CURLOPT_POSTFIELDS, http_build_query($  data_string));  $  sonuc = curl_exec($  ch);  /*     //print_r($  sonuc); */  curl_close($  ch);    }   add_action( 'wp_insert_site', 'create_cloudflare_dns_record' ); 

None of the three different attempts for $ current_site at the beggining of the function is giving any result.

If I manually replace the value for $ current_site, the code is working.

Any help is greatly appreciated.