I have a bit of an odd question, I'm sure most of you realise that these sorts of questions arise out of certain situations that a developer has no control over!

I would like to work out how to keep a querystring parameter in the URL at all times. If the parameter is not set, I'd like a default to be appended to the URL ?param=something

I asked a previous question relating to this and have been able to use htaccess to add a default query - but this only works fir the initial request whereas I need to ensure it is always present in the address.

I am thinking of using a cookie - set with PHP and then queried with .htaccess.

So, I am asking if this is possible and if there is a better way of doing this?

If you're using defaults when a value is supplied, isn't that enough?
–
Paul Alan TaylorJan 21 '13 at 11:02

You certainly can use a cookie, though I do not see any advantage to other solutions. But note that cookies values are not populated into the $_GET superglobal variable.
–
arkaschaJan 21 '13 at 11:04

@webnoob its to set a user type on a website without having to modify all the existing URLs with a new path. The variable has to be set so that our sales team can copy the URL and direct clients to a specific page and also set their user type. It's a messy solution but I am out of ideas!
–
Alex HolsgroveJan 21 '13 at 11:07

@arkascha if I can't pass the cookie value into my RewriteRule then that's the end of that idea.
–
Alex HolsgroveJan 21 '13 at 11:08

4 Answers
4

Without changing all the URLs I can't see this being possible and as discussed it is a very hacky way to do it.

I would suggest you give them a "special" button that they use for copying a link. Make them use this button to copy the link instead of the URL. You can then control the data properly without hacking the website.

Edit: You "could" add some JQuery in to append ALL links with your param. Have you thought about this?

$_GET and $_POST superglobal variable those are not meant to used like this. And I don't know why is it required but anyway you can get the required functionality using Session or Cookies. What you are trying to do is not practical. Industry standard is to use session and cookie. Try them out I'm sure it will helps you out for sure. If you have any issues let me know.

The session already functions and sets the user type - but only when the ?param=something is set. If the person goes to a different page, their session is still active, but the querystring is gone. If they copy the address and send it to a client, then the client doesn't get the correct content. Does that sort of explain it?
–
Alex HolsgroveJan 21 '13 at 11:15

1

@AlexHolsgrove - I see your problem now. Can't you give them a "special" button that they use for copying a link. Make them use this button to copy the link instead of the URL. You can then control the data properly without hacking the website.
–
webnoobJan 21 '13 at 11:21

That was my initial solution, but was rejected by higher powers... It seems that it is the only viable solution now :)
–
Alex HolsgroveJan 21 '13 at 11:29

@AlexHolsgrove I will move it to an answer in case you decide to go with it.
–
webnoobJan 21 '13 at 11:38

Thanks for the answer. I managed to get what you suggester to work (see my previous question: stackoverflow.com/questions/14339035/…) however it doesn't fully fix my problem. I've implemented a button to copy the URL and append the querystring - it's a quick and clean solution
–
Alex HolsgroveJan 23 '13 at 15:48