darkfreaks Posted September 24, 2009 Share Posted September 24, 2009 ok so how would i use the $_GET method to fetch a variable like so http://mysite.com/?pg=portfolio&design=design Link to comment https://forums.phpfreaks.com/topic/175389-passing-variable-in-browser/ Share on other sites More sharing options...
mattal999 Posted September 24, 2009 Share Posted September 24, 2009 <?php $pg = $_GET['pg']; $design = $_GET['design']; ?> The $_GET['xxx'] is what you need to use. Link to comment https://forums.phpfreaks.com/topic/175389-passing-variable-in-browser/#findComment-924236 Share on other sites More sharing options...
darkfreaks Posted September 24, 2009 Author Share Posted September 24, 2009 ok i found the following code how would i modify it it to work with my code? it takes a php page and adds what i need to the end of it. &design=design. however i need to just add &design to the end of pg=portfolio <?php function makeUrl($path, $qs = false, $qsAdd = false) { $var_array = array(); $varAdd_array = array(); $url = $path; if($qsAdd) { $varAdd = explode('&', $qsAdd); foreach($varAdd as $varOne) { $name_value = explode('=', $varOne); $varAdd_array[$name_value[0]] = $name_value[1]; } } if($qs) { $var = explode('&', $qs); foreach($var as $varOne) { $name_value = explode('=', $varOne); //remove duplicated vars if($qsAdd) { if(!array_key_exists($name_value[0], $varAdd_array)) { $var_array[$name_value[0]] = $name_value[1]; } } else { $var_array[$name_value[0]] = $name_value[1]; } } } //make url with querystring $delimiter = "?"; foreach($var_array as $key => $value) { $url .= $delimiter.$key."=".$value; $delimiter = "&"; } foreach($varAdd_array as $key => $value) { $url .= $delimiter.$key."=".$value; $delimiter = "&"; } return $url; } ?> Link to comment https://forums.phpfreaks.com/topic/175389-passing-variable-in-browser/#findComment-924239 Share on other sites More sharing options...
SystemOverload Posted September 24, 2009 Share Posted September 24, 2009 What exactly are you trying to achieve? Link to comment https://forums.phpfreaks.com/topic/175389-passing-variable-in-browser/#findComment-924242 Share on other sites More sharing options...
darkfreaks Posted September 24, 2009 Author Share Posted September 24, 2009 this is how they call the function. <?php makeUrl('index.php', $_SERVER['QUERY_STRING'], 'name=value&name2=value2') ?> which outputs: http://mysite.com/index.php?name=value&namename2=value2 i want to modify that to output http://mysite.com/?pg=portfolio&design=design Link to comment https://forums.phpfreaks.com/topic/175389-passing-variable-in-browser/#findComment-924243 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.