Code này dùng để thay đổi Ip cho nhiều website 1 lúc trong cloudflare. Code: <?php set_time_limit(999999); $domainurl = array( "xxxxx.net", "bbbbbb.net" ); $token = 'aaaaaa'; //https://www.cloudflare.com/my-account $email = '[email protected]'; $new_ip = '149.202.219.xx; //Gets server's IP Address $old_ip = '149.202.223.yy'; //Gets DNS's IP Address foreach ($domainurl as $domain) { $hostname = $domain; //Gets current hostname if ( $new_ip !== $old_ip ) {// iIf the IP addresses are the same, we don't need to make any changes $api_url = 'https://www.cloudflare.com/api_json.html'; $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $api_url ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); $body = array( 'a' => 'rec_load_all', 'tkn' => $token, 'email' => $email, 'z' => $domain, ); curl_setopt( $ch, CURLOPT_POST, true ); curl_setopt( $ch, CURLOPT_POSTFIELDS, $body ); if ( $output = curl_exec( $ch ) ) { $results = json_decode( $output ); if ( 'success' === $results->result ) { foreach( $results->response->recs->objs as $dns_entry ) { if ( $dns_entry->name === $hostname ) { $record_id = $dns_entry->rec_id; $new_entry = false; break; } else { $new_entry = true; } } if ( $new_entry ) { $body = array( 'a' => 'rec_new', 'tkn' => $token, 'email' => $email, 'z' => $domain, 'type' => 'A', 'name' => $hostname, 'content' => $new_ip, 'ttl' => '1', ); curl_setopt( $ch, CURLOPT_POSTFIELDS, $body ); if ( $output = curl_exec( $ch ) ) { $results = json_decode( $output ); if ( 'success' === $results->result ) { echo "IP Address added for hostname.\n"; } else { printf( "Error adding ip address for hostname: %s\n", $results->msg ); } } else { echo "Error adding IP Address for hostname.\n"; } } else { $body = array( 'a' => 'rec_edit', 'tkn' => $token, 'email' => $email, 'z' => $domain, 'id' => $record_id, 'type' => 'A', 'name' => $hostname, 'content' => $new_ip, 'ttl' => '1', ); curl_setopt( $ch, CURLOPT_POSTFIELDS, $body ); if ( $output = curl_exec( $ch ) ) { $results = json_decode( $output ); if ( 'success' === $results->result ) { echo "IP Address updated for hostname.\n"; } else { printf( "Error adding ip address for hostname: %s\n", $results->msg ); } } else { echo "Error changing IP Address for hostname.\n"; } } } else { printf( "Error adding ip address for hostname: %s\n", $results->msg ); } } curl_close( $ch ); } else { echo "No changes required\n"; } }