API requests return an aes.js security page instead of JSON

Website URL

https://amalukyuhimuna.com

Error Message

PowerShell and Flutter HTTP requests to api_jobs.php and api_test.php return an HTML page containing /aes.js and a JavaScript redirect that sets a __test cookie, instead of returning JSON. The HTTP status is 200 OK, but the Content-Type is text/html. The issue also occurs with a simple PHP test file that only outputs JSON.

Other Information

Hosting provider: InfinityFree Free Hosting.

API endpoint: https://amalukyuhimuna.com/api_jobs.php

Test endpoint: https://amalukyuhimuna.com/api_test.php

Both PHP files are located in the htdocs directory. The API is intended to provide publicly published job listings to a Flutter application.

The endpoints return the same JavaScript security challenge even when requested with an Accept: application/json header and a Mozilla/5.0 User-Agent.

I do not want to disable security for the entire website. I would appreciate guidance on a supported solution for serving JSON API responses to my app.

Welcome to the InfinityFree community forum! Good to have you here.

  • Most people answering here are volunteers. They’re often the fastest source of help. Admin (the only staff member) checks in about once a day for issues on our end.
  • Volunteers can’t see your account or website. Share what you actually see, like error messages and what happens when you try something. That’s more useful than your theory of what’s wrong.
  • AI tools often get InfinityFree wrong. If a volunteer’s advice differs from what an AI told you, please try the volunteer’s suggestion first.
  • Solving an issue is a joint effort. Try the suggestions you get and report back what happened.

Beep boop, I’m a bot! I dug through the forum to get you started. I sometimes get things wrong though, so do with this what you will until a human has a look.

There isn’t a supported way to do this on free hosting. What you’re seeing is InfinityFree’s browser security system, not a bug in your PHP.

The knowledge base article says the check covers every URL on a free hosting site, including JSON files. A client that can’t run JavaScript and keep cookies gets the short HTML page that loads /aes.js and sets a __test cookie. That matches what you describe, and the request never reaches your PHP code. The article names mobile apps and REST APIs as things that won’t work. It also says the check can’t be turned off for one path, file type, user agent or IP address. Sending an Accept: application/json header or a browser User-Agent doesn’t get around it, because the check needs JavaScript to run.

Your plan to leave security on for the rest of the site and exempt only the API isn’t possible. The article says the system is mandatory on all free hosting accounts.

The article’s only suggestion for sites that need API or app access is premium hosting, which it says protects sites with less restrictive methods that let apps and APIs work normally.

Here is the article:

InfinityFree is designed for hosting websites (to be accessed with a browser) not API’s to be accessed by programs or other websites. This is part of the T&C’s that you agreed to when signing up.

As such, your remote access to the API is being blocked correctly by the security system