$hosts = gethostbynamel('home.example.com');
$myip= file_get_contents('https://server.example.com/ip.txt');
if($hosts[0]!=$myip){
//if(TRUE){
	$params = array(
		'username' => 'xsvxXXXXXXX',
		'password' => 'password',
		'sv'  => 'sv000',
		'service'  => 'xserver',
		'action_user_login'=>'true'
	); 
	$ch = curl_init();
 
	$fp = fopen("tmp", "w");
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
	curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie");
//	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_WRITEHEADER, $fp);
	curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
	curl_setopt($ch, CURLOPT_POST, TRUE);
	curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
	curl_setopt($ch, CURLOPT_URL, 'https://secure.xserver.ne.jp/xserver/sv000/');
	// ログイン
	$output = curl_exec($ch);
//	print "CURL OUTPUT:\n{$output}\n"; 
 
	$params = array(
		'dns_id' => '00000000',
		'dns_host' => 'home',
		'dns_type'  => 'A',
		'dns_content'  => $myip,
		'dns_prio'=>'0',
		'action_user_dns_edit_index'=>mb_convert_encoding('変更', 'eucjp-win','UTF-8'),
		'did'=>'example.com'
	); 
	curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
	curl_setopt($ch, CURLOPT_URL, 'https://secure.xserver.ne.jp/xserver/sv000/?action_user_dns_list=on&did=example.com');
	// DNSレコード設定
	$output = curl_exec($ch);
//	print "CURL OUTPUT:\n{$output}\n"; 
 
	if(preg_match('/.*name="id" value="(.*)"/', $output, $matches)){
		unset($params['action_user_dns_edit_index']);
		$params['action_user_dns_edit_conf'] = mb_convert_encoding('DNSレコードの編集(確認)', 'eucjp-win','UTF-8');
		$params['id'] = $matches[1];
		curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
		curl_setopt($ch, CURLOPT_URL, 'https://secure.xserver.ne.jp/xserver/sv000/?action_user_dns_list=on&did=example.com');
		// 変更確認
		$output = curl_exec($ch);
//		print "CURL OUTPUT:\n{$output}\n"; 
	}
	if(preg_match('/.*name="uniqid" value="(.*)"/', $output, $matches)){
		unset($params['id']);
		unset($params['action_user_dns_edit_conf']);
		$params['uniqid'] = $matches[1];
		$params['action_user_dns_edit_do'] = mb_convert_encoding('DNSレコードの変更(確定)', 'eucjp-win','UTF-8');
		curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
		curl_setopt($ch, CURLOPT_URL, 'https://secure.xserver.ne.jp/xserver/sv000/?action_user_dns_list=on&did=example.com');
		// 変更確定
		$output = curl_exec($ch);
		print "CURL OUTPUT:\n{$output}\n"; 
	}
	 
	fclose($fp);
	curl_close($ch);
}