cheechm Posted October 11, 2008 Share Posted October 11, 2008 Hi, So for instance I am on this page: http://mydomain.com/?id=1 it could also be: http://mydomain.com/?id=4&do=search So I was wondering, when I use my get_url() function: function get_url() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") { $pageURL .= "s"; } $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"]; } else { $_SERVER['REQUEST_URI'] = str_replace(array('&', '&'), array('&', '&'), $_SERVER['REQUEST_URI']); $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; } return $pageURL; } why does it form a link, for instance like: http://mydomain.com/?id=2&do=2&id=3 I don't want 2 places where id is set. It would eventually make the url clogged up. Also, I have to use that function because of the different variables that could be in the URL. Many thanks. Link to comment https://forums.phpfreaks.com/topic/127961-url-variables/ Share on other sites More sharing options...
Guest Posted October 11, 2008 Share Posted October 11, 2008 Hmm, it wouldnt' seem the problem is in that code. I somehow suspect the REQUEST_URI variable though. Not that it's incorrect, I just prefer to break it up into easier-to-dissect steps. The request_uri joins the querystring and php_self into one, so perhaps you have a piece of code somewhere where you append the additional id=3 to the url? Essentially it's just easier to picture. You'd replace REQUEST_URI with PHP_SELF and QUERY_STRING like so (also simplified the process a little): function get_url() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") { $pageURL .= "s"; } $pageURL .= "://" . $_SERVER["SERVER_NAME"]; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= ":" . $_SERVER["SERVER_PORT"]; } $pageURL .= $_SERVER['PHP_SELF']; if(! empty($_SERVER['QUERY_STRING']) ){ $pageURL .= '?' . str_replace(array('&', '&'), array('&', '&'), $_SERVER['QUERY_STRING']); } return $pageURL; } Otherwise, it really should work. Can you show me in what context you use the function? Or more details on the problem? Link to comment https://forums.phpfreaks.com/topic/127961-url-variables/#findComment-662605 Share on other sites More sharing options...
cheechm Posted October 11, 2008 Author Share Posted October 11, 2008 Doesn't make a difference. Thanks anyway though. Link to comment https://forums.phpfreaks.com/topic/127961-url-variables/#findComment-662682 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.