I have a Laravel 11 web app where I implemented an IDN converter to handle domains written in Cyrillic script, such as монгол.мон, converting them into Punycode (xn--c1aqbeec.xn--l1acc). Locally, it works perfectly. However, after deploying it on cPanel, Cyrillic domains aren’t being processed correctly.
Here’s the controller:
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
use Algo26IdnaConvertToIdn;
class IDNController extends Controller
{
public function convert(Request $request)
{
$domain = $request->input('domain');
$idn = new ToIdn();
$output = $idn->convert($domain);
return response()->json(['output' => $output]);
}
}
And this is the Javascript:
document.getElementById('idn-form').addEventListener('submit', function(event) {
event.preventDefault();
const domain = document.querySelector('#idn-form input[name="domain"]').value;
const submitButton = document.getElementById('idn-submit');
submitButton.disabled = true;
fetch(`/idn?domain=${domain}`)
.then(response => response.json())
.then(data => {
const resultDiv = document.getElementById('idn-result');
resultDiv.innerHTML = `<p class="text-[#312E81] text-md font-semibold px-4 py-2 rounded-lg">${data.output}</p>`;
document.getElementById('copy-button').classList.remove('hidden');
submitButton.disabled = false;
})
.catch(error => {
console.error('Error:', error);
document.getElementById('idn-result').innerHTML = `<p class="text-red-500">An error occurred. Please try again later.</p>`;
submitButton.disabled = false;
});
});
Locally, this setup works fine, returning JSON as expected. However, after deploying on cPanel, I face the following issue: when I input Cyrillic domains, nothing is returned. Upon logging the $domain in the controller, it shows as empty:
[2024-10-03 02:14:03] local.INFO: Domain:
And here’s the log in the error:
[2024-10-03 02:14:03] local.ERROR: Algo26IdnaConvertToIdn::convert(): Argument #1 ($host) must be of type string, null given, called in /home/cctldmn/cctldmn/app/Http/Controllers/IDNController.php on line 16
When I use English letters, it works perfectly. But with Cyrillic domains, the input is not passed correctly. Could it be an encoding issue or some cPanel setting? Any ideas on why Cyrillic domains aren’t being processed?