CBaZ Posted January 18, 2013 Share Posted January 18, 2013 here's my code thus far I am stuck <?php $protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https') === FALSE ? 'http' : 'https'; $host = $_SERVER['HTTP_HOST']; $script = $_SERVER['SCRIPT_NAME']; $query = explode('&', $_SERVER['QUERY_STRING']); $params = array(); foreach( $query as $param ) { list($name, $value) = explode('=', $param); $params[urldecode($name)][] = urldecode($value); } $currentUrl = $protocol . '://' . $host . $script . '?' . $query . '&' . $name . $value; ?> Quote Link to comment https://forums.phpfreaks.com/topic/273344-get-multiple-parameters-from-url-and-echo-them-out/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 18, 2013 Share Posted January 18, 2013 See the $_GET array. It already contains the parsed key/value pairs, unless you are doing something unusual, which you didn't show. You also didn't state what incorrect result you are getting vs. what you expect that leads you to believe that you are stuck. Quote Link to comment https://forums.phpfreaks.com/topic/273344-get-multiple-parameters-from-url-and-echo-them-out/#findComment-1406855 Share on other sites More sharing options...
requinix Posted January 18, 2013 Share Posted January 18, 2013 $protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https')Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â === FALSE ? 'http' : 'https'; The SERVER_PROTOCOL will never contain "https". It is always in the form "HTTP/1.x". Check $_SERVER["HTTPS"] ("on" or "off") or, if that's not available, the less reliable $_SERVER["SERVER_PORT"] (80=http, 443=https). Â Speaking of, you don't take into account the port number. Â As for $currentUrl, $name and $value do not have what you want them to have. They're only useable inside the foreach loop. Quote Link to comment https://forums.phpfreaks.com/topic/273344-get-multiple-parameters-from-url-and-echo-them-out/#findComment-1406857 Share on other sites More sharing options...
CBaZ Posted January 18, 2013 Author Share Posted January 18, 2013 ok I am trying to just get a name and value into the url string like index.php?Brand&Device .. then I echo it out as <?php echo $params; ?>.gif" to put a picture in the section of the page which i pull from the url string currently it displays $array in all the fields Quote Link to comment https://forums.phpfreaks.com/topic/273344-get-multiple-parameters-from-url-and-echo-them-out/#findComment-1406858 Share on other sites More sharing options...
BagoZonde Posted January 18, 2013 Share Posted January 18, 2013 (edited) foreach($query as $param){ list($name, $value) = explode('=', $param); $params[urldecode($name)] = urldecode($value); //for array purposes $params_pairs[]=$param; //for string purposes } //Here we go with nice key=>value array print'<pre>'; print_r($params); print '</pre>'; $currentUrl = $protocol . '://' . $host . $script . '?' . implode('&', $params_pairs); Â However I put implode for learning purposes as I think you doing all that stuff for this reason. To get only names, just iterate through keys with foreach. Â However please be more precise when asking. Â P.S. Also I'm not sure as I haven't any SSL server, but maybe isset($_SERVER['HTTPS']) is a good way to check https. Â Edit: ok, requinix was more detailed with HTTPS, quite interesting . Thanks. Edited January 18, 2013 by BagoZonde Quote Link to comment https://forums.phpfreaks.com/topic/273344-get-multiple-parameters-from-url-and-echo-them-out/#findComment-1406859 Share on other sites More sharing options...
CBaZ Posted January 18, 2013 Author Share Posted January 18, 2013 ok let me be more specific. I have one section on my site where the brand logo is displayed. and another section where the device image would be displayed. the brand images are in .png format and the device are in .gif format. So i figured i could achieve it with this script. Quote Link to comment https://forums.phpfreaks.com/topic/273344-get-multiple-parameters-from-url-and-echo-them-out/#findComment-1406863 Share on other sites More sharing options...
requinix Posted January 19, 2013 Share Posted January 19, 2013 And how would this script help with that? Quote Link to comment https://forums.phpfreaks.com/topic/273344-get-multiple-parameters-from-url-and-echo-them-out/#findComment-1406865 Share on other sites More sharing options...
CBaZ Posted January 19, 2013 Author Share Posted January 19, 2013 this so far works for index.php?brand it will let me echo out the $params in my text i just need one extra like this index,php?brand&device but I am not sure I can do it with the multiple parameters script i posted in here earlier or if it can be done period. hope that clears up why i am trying to do this it has its purpose. <?php $protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https') === FALSE ? 'http' : 'https'; $host = $_SERVER['HTTP_HOST']; $script = $_SERVER['SCRIPT_NAME']; $params = $_SERVER['QUERY_STRING']; $currentUrl = $protocol . '://' . $host . $script . '?' . $params; ?> Quote Link to comment https://forums.phpfreaks.com/topic/273344-get-multiple-parameters-from-url-and-echo-them-out/#findComment-1406866 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.