Welcome Guest, Not a member yet? Register   Sign In
Get Current URL
#11

[eluser]mihu[/eluser]
will current_url() works?

I got similar issue.
I need to use javascript to direct request to a processing step and redirect back to original place.
Could someone guide me how I can get this done?
#12

[eluser]Pascal Kriete[/eluser]
You could put the current_url into a cookie, redirect, and read the cookie to get back again.

The url helper's current_url() will work fine - the function didn't exist when this thread was started.
#13

[eluser]Unknown[/eluser]
site_url(uri_string()) will do the job.
#14

[eluser]danmontgomery[/eluser]
[quote author="ortolano" date="1308012899"]site_url(uri_string()) will do the job.[/quote]

This thread is 3 years old, but current_url() is more to the point.
#15

[eluser]wovenlander[/eluser]
[quote author="mihu" date="1228518626"]will current_url() works?

I got similar issue.
I need to use javascript to direct request to a processing step and redirect back to original place.
Could someone guide me how I can get this done?[/quote]

Javascript already knows the current URL, it's at [removed].href

Assign that to a hidden field in your form, or append it to your query string, so it'll go to the server when the form is submitted; and then your controller can redirect back to it.

Try writing a little Javascript that outputs the location.href into the current page once it's loaded. That way you can see if you're getting the value you need to send them back.

One thing: you generally want to HTMLencode the current URL for transmission in a GET or POST, and then decode it when you want to use it in a redirect.
#16

[eluser]Unknown[/eluser]
You can use these functions.

Code:
public function str_left($s1, $s2){
return substr($s1, 0, strpos($s1, $s2));
}


public function get_self_url(){

$s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
$protocol = $this->str_left(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
}
#17

[eluser]InsiteFX[/eluser]
Code:
$url = current_url();
Returns the full URL (including segments) of the page being currently viewed.




Theme © iAndrew 2016 - Forum software by © MyBB