visualazza Posted August 13, 2010 Share Posted August 13, 2010 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 Quote Link to comment Share on other sites More sharing options...
hcdarkmage Posted August 13, 2010 Share Posted August 13, 2010 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. Quote Link to comment Share on other sites More sharing options...
visualazza Posted August 13, 2010 Author Share Posted August 13, 2010 sorry, you misunderstand. If my url already has a get var in it but i want to add another later how would i do this? If one isnt there already then it just uses the standard ?var=string Quote Link to comment Share on other sites More sharing options...
hcdarkmage Posted August 13, 2010 Share Posted August 13, 2010 I hate to ask, but what do you mean by add some later? You mean after you process the first link? Or are you talking about adding things while it is being redirected? Quote Link to comment Share on other sites More sharing options...
hcdarkmage Posted August 13, 2010 Share Posted August 13, 2010 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"; 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.