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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.