Jump to content

passing & variable in browser?


darkfreaks

Recommended Posts

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;
}

?>

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

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.