webref.eu Posted December 12, 2008 Share Posted December 12, 2008 If I have a url like: http://www.mysite.com/review-add-form.php?ProductId=1 and want to put this into a variable called $redirect, how do I do it? I've tried: $redirect = $_SERVER['PHP_SELF']; but that only sets $redirect as: http://www.mysite.com Missing out the rest of the URL. Thanks for any help. Rgds Quote Link to comment https://forums.phpfreaks.com/topic/136716-solved-how-do-i-get-full-current-url-into-a-variable/ Share on other sites More sharing options...
gevans Posted December 12, 2008 Share Posted December 12, 2008 $_SERVER['PHP_SELF'] should hold 'review-add-form.php'; your going to need $_SERVER['REQUEST_URI'] Quote Link to comment https://forums.phpfreaks.com/topic/136716-solved-how-do-i-get-full-current-url-into-a-variable/#findComment-713924 Share on other sites More sharing options...
mmarif4u Posted December 12, 2008 Share Posted December 12, 2008 Perhaps this function will also work. <?php function full_url() { $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; $protocol = substr(strtolower($_SERVER["SERVER_PROTOCOL"]), 0, strpos(strtolower($_SERVER["SERVER_PROTOCOL"]), "/")) . $s; $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); return $protocol . "://" . $_SERVER['SERVER_NAME'] . $port . $_SERVER['REQUEST_URI']; } echo full_url(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/136716-solved-how-do-i-get-full-current-url-into-a-variable/#findComment-713929 Share on other sites More sharing options...
Maq Posted December 12, 2008 Share Posted December 12, 2008 If you're going to use a function you probably want to return the url not just echo it. Quote Link to comment https://forums.phpfreaks.com/topic/136716-solved-how-do-i-get-full-current-url-into-a-variable/#findComment-713937 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.