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. Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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.