Skip to content

Bug: current_url() returning wrong value when different host #5807

Description

@darkylmnx

PHP Version

8.0

CodeIgniter4 Version

4.1.9

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Windows

Which server did you use?

apache

Database

No response

What happened?

The function current_url() returns the $baseURL in app/Config/App.php instead of the real current url in the browser.
This leads to confusion, know the documentation says:

You can restrict groups of routes to function only in certain domain or sub-domains of your application by passing the “hostname” option along with the desired domain to allow it on as part of the options array:

https://codeigniter.com/user_guide/incoming/routing.html?highlight=router#limit-to-hostname

Which means an app could have multiple domain pointing at it, but current_url() would only return the one set in config.

Use case: CMS, multi-tenant app, multi-vendor app, etc.

Steps to Reproduce

Call current_url() when loading the app with a host like sub.example.com while in the config, you would set $baseURL to www.example.com for example.

Expected Output

current_url() is the name implies should retour the current url and not the current url with $baseURL as host.

Anything else?

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    waiting for infoIssues or pull requests that need further clarification from the author

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions