Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How can I pass the current URL as a URI segment?
  • Hi there,

    I am changing the languange of my system via link:
    http://fueladmin.local/base/lang/de

    Now I need to store the current URL from the side on which this link was calles to make a redirect after changing the language.

    How can I do that?
    I know how to call the current URI, but when I pass it as a segment in URL the "/" makes some trouble.

    Thanks
    Kay
  • HarroHarro
    Accepted Answer
    If the goal is to redirect back to the page you were coming from in base::action_lang(), you can use something like this:
    $url = '/';
    if (isset(\Input::server('HTTP_REFERER')) and strpos(\Input::server('HTTP_REFERER'), Uri::base())=== 0)
    {
        $url = \Input::server('HTTP_REFERER');
    }

    \Response::redirect($url);

    It will check if the previous page was one of your app, to avoid redirecting away from it.
  • Thanks Harro,

    with the change that
    if (isset(\Input::server('HTTP_REFERER')) and strpos(\Input::server('HTTP_REFERER'), Uri::base())=== 0)
    is
    if (\Input::server('HTTP_REFERER', false) and strpos(\Input::server('HTTP_REFERER'), Uri::base())=== 0)
  • Correct. I should not try to write code before my morning coffee... :-)

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion