Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slash is appers in the begining of Uri/path on one server, and not appears in another #1794

Closed
xorik opened this issue Mar 3, 2016 · 9 comments

Comments

@xorik
Copy link

xorik commented Mar 3, 2016

Hi! I found some issue in the Uri parser.

I have different results on different servers test2 and /test2 for this code:

$app->get('/test2', function()
{
    var_dump($this->request->getUri()->getPath());
});

On the first server (dev) index.php is not in the HTTP root (in subdirectory), and on the second (prod) index.php is in the HTTP root.

I have slim-3.2.1 on both servers.

Dev server:

  'PATH_INFO' => string '' (length=0)
  'SCRIPT_FILENAME' => string '/var/www/hot/index.php' (length=22)
  'QUERY_STRING' => string 't=test2' (length=7)
  'REQUEST_METHOD' => string 'GET' (length=3)
  'CONTENT_TYPE' => string '' (length=0)
  'CONTENT_LENGTH' => string '' (length=0)
  'SCRIPT_NAME' => string '/hot/index.php' (length=14)
  'REQUEST_URI' => string '/hot/test2' (length=10)
  'DOCUMENT_URI' => string '/hot/index.php' (length=14)
  'DOCUMENT_ROOT' => string '/var/www' (length=8)
  'SERVER_PROTOCOL' => string 'HTTP/1.1' (length=8)
 .....
  'PHP_SELF' => string '/hot/index.php' (length=14)

Prod server:

  ["DOCUMENT_ROOT"]=>
  string(29) "/var/www/0/71917/varmtarbeid/"
  ["REQUEST_SCHEME"]=>
  string(4) "http"
  ["CONTEXT_PREFIX"]=>
  string(0) ""
  ["CONTEXT_DOCUMENT_ROOT"]=>
  string(29) "/var/www/0/71917/varmtarbeid/"
  ["SCRIPT_FILENAME"]=>
  string(38) "/var/www/0/71917/varmtarbeid/index.php"
  ["REDIRECT_URL"]=>
  string(6) "/test2"
  ["REQUEST_METHOD"]=>
  string(3) "GET"
  ["QUERY_STRING"]=>
  string(0) ""
  ["REQUEST_URI"]=>
  string(6) "/test2"
  ["SCRIPT_NAME"]=>
  string(10) "/index.php"
  ["PHP_SELF"]=>
  string(10) "/index.php"
@akrabat
Copy link
Member

akrabat commented Mar 3, 2016

This is related to getBasePath()

Does this code give the same output on both servers?

$uri = $this->request->getUri();
var_dump($uri->getBasePath() . $uri->getPath());

@xorik
Copy link
Author

xorik commented Mar 3, 2016

@akrabat nope, on the dev result is '/hottest2', on prod "/test2"

@xorik
Copy link
Author

xorik commented Mar 3, 2016

I think that path must be same, not depending on script location, isn't it?

@akrabat
Copy link
Member

akrabat commented Mar 3, 2016

ah yes - basePath doesn't end with a '/'

@akrabat
Copy link
Member

akrabat commented Mar 3, 2016

@akrabat nope, on the dev result is '/hottest2', on prod "/test2"

The URIs you are using are different, so the path will be different. Slim tries to remove this difference by putting the path to index.php into basePath, leaving the rest of the path in path.

This definitely causes confusion, so more work is required here.

@tuupola
Copy link
Contributor

tuupola commented Mar 3, 2016

Duplicate of #1554. Personally I still think behaviour of getPath() should be the same when installed in document root and subfoler.

@geggleto
Copy link
Member

geggleto commented Mar 3, 2016

Can confirm on 3.2.1

$app->get('/test2', function()
{
    var_dump($this->request->getUri()->getPath());
});

string(5) "test2" when installed in a subdirectory

@xorik xorik changed the title Slash is appers in the begining of Uri/path on one server, and not in another Slash is appers in the begining of Uri/path on one server, and not appears in another Mar 3, 2016
@akrabat
Copy link
Member

akrabat commented Jan 8, 2017

I suspect we can't change this in Slim 3 as we'll break existing applications.

@akrabat akrabat closed this as completed Jan 8, 2017
@misha354
Copy link

Pull request #2115 fixes this in Slim 4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants