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 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'] 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(); ?> 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. 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
Archived
This topic is now archived and is closed to further replies.