How to let the Opencart APIs work for all IP addresses?

Opencart checks the IP address to allow the API calls, but sometimes you need to let all IP addresses do the API calls, for example, while testing the API. To allow all IP addresses to comment following the line of code at catalog/controller/api/account/login.php

//$json[‘error’] = sprintf($this->language->get(‘error_ip’), $this->request->server[‘REMOTE_ADDR’]);

if ($api_info) {
	// Check if IP is allowed
	$ip_data = [];

	$results = $this->model_account_api->getIps($api_info['api_id']);

	foreach ($results as $result) {
		$ip_data[] = trim($result['ip']);
	}

	if (!in_array($this->request->server['REMOTE_ADDR'], $ip_data)) {
		//$json['error'] = sprintf($this->language->get('error_ip'), $this->request->server['REMOTE_ADDR']);
	}
} else {
	$json['error'] = $this->language->get('error_key');
}

To learn more about Opencart API following posts help more:

Previous articleDocker set up for Opencart for local development
Next articleChrome console built-in AI helps with code understanding for the Developer
Author of three Opencart book. The recent Opencart 4 book is at https://amzn.to/4dOlbOR

LEAVE A REPLY

Please enter your comment!
Please enter your name here