0

In my Slim 3 Controller I use a function to return images from a non-public folder. I put the route to this Controller in an img tag like so:

<img src="/get_pic/some_filename.jpg" />

Everything works fine as long as I access my webpage via WIFI. But when I switch to mobile internet access, chrome displays only the broken image icon for all images. When I instead put the absolute url path to the controller in my browser bar, the image shows correctly.

Here's my controller class:

<?php
namespace Picserver\Controller;

use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;

class GetPic
{

    public function index(Request $request, Response $response, array $args)
    {
        /* do some stuff */
        $pic = file_get_contents('path/to/file.jpg');
        $response->getBody()->write($pic);

        return $response->withHeader('Content-Type', 'image/jpeg');
    }

}

[EDIT]

Inspection of the generated HTML shows that the <img> src-attribute changes from src="http://subdomain.mydomain..." to src="http://1.1.1.1/bmi/subdomain.mydomain..." when I connect to mobile internet. As result I get a "302 Moved Temporarily" response from Slim3. Maybe it is worth to mention that I am using an absolute <base> tag that points to my domain, and I also tried it with an absolute route in the <img> src-attribute, without success.

[EDIT 2]

OK, I found the cause but not the solution of the problem. I got an authorization middleware attached to the route that points to the script which provides the image. It looks like the middleware cannot identify the session for the incoming request, so it redirects to my login page. I assume this has something to do with the changed src-attribute and cookie domains. Any help would be appreciated.

Benni
  • 1,023
  • 11
  • 15

0 Answers0