Jump to content

Add Get Variable To URL When One Or More Exist


visualazza

Recommended Posts

hi,

 

im having trouble adding a get variable to a url if one already exists.

 

eg

 

current url = http://www.example.com/index.php?var1=something

 

i want to be able to change this to

 

new url = http://www.example.com/index.php?var1=something&var2=another

 

even so i can have a few get variable there.

 

I can add the first var through a form or link, but how would i add more through a link or through the header function?

 

I am positivly stuck.

 

Thanks

If you where going to do it through headers then it would be like:

header("Location: http://www.example.com/index.php?var1=var1&var2=var2&var3=var3");

 

Same would be for a link:

<a href="http://www.example.com/index.php?var1=var1&var2=var2&var3=var3">Click here</a>

 

EDIT: Don't forget to use the $_GET variables on the link page.

$var1 = $_GET['var1']; //etc.

Okay; try this:

$url = (!empty($_SERVER['HTTPS'])) ? "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];

 

That will get the current url, then you can use this:

$url = $url."&var2=another";

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.