I am developing a website and now I need to append get parameters to all the url's of the website.The website is developed using php and all the tasks have been completed.So is there any way now or any function with the help of which I can automatically append get parameters to all the url's requested by the user automatically?
Asked
Active
Viewed 3,593 times
1
-
actually I am developing a recommendation system engine.So for its evaluation I am bound to track the number of recommendations given to the user for that page which I am thinking to track using the get parameter of the url. – log N May 26 '13 at 11:51
-
You mean, if the URL was initially like `index.php?id=foo` you want to append another value, so it can be `index.php?id=foo&id2=bar`? – samayo May 26 '13 at 11:52
-
yeah and this need to be done for all the url's and doing it manually for all is very troublesome.So is there any way to minimize this work. – log N May 26 '13 at 11:54
-
1cant' you just pretend that the $_GET is set on every request, by adding something like `$_GET['yourvar']='yourvalue';` to some always-loading page? – Nanne May 26 '13 at 12:02
-
yeah but how do I get the value of some parameter from the previous page. – log N May 26 '13 at 12:05
-
Thankx Nanne.I got my answer...I can just pass that information through a session variable. – log N May 26 '13 at 12:06
3 Answers
1
<?php
$current_url = $_SERVER['REQUEST_URI'];
$add = '?id=car'; // could be from a GET['type'] post
$add_2 = '&car_type=BMW'; //could be from a GET['car_type'] post
$add_3 = '&pc_type=Apple'; //could be from a GET['pc_type'] post
$final = $current_url.$add.$add_2.$add_3;
echo $final;
Output will be
/test.php?id=car&car_type=BMW&pc_type=Apple
So, if you had just a page index.php
the, whatever you get, from the URL with the GET
global can be appended, to your URL

samayo
- 16,163
- 12
- 91
- 106
-
But will it work in my case.I have normal urls and whenever user hits that there should be some processing that automatically these parameters should get appended to the urls and the user is shown with the page. – log N May 26 '13 at 12:03
-
I don't clearly understand, whenever user hits what? and what should be processed? I thought, you wanted only yo get append the id, anyway, just give me a little bit more explanation, and I will try to make it – samayo May 26 '13 at 12:06
-
yeah my situation is that user hits index.php there should be something that user goes to index.php but the url on the browser should be index.php?foo=bar..So will this solution work for my query? – log N May 26 '13 at 12:08
-
But, how do you want the URL to recognize `foo=bar` does user submit bar in the form? I am just trying to help you more. – samayo May 26 '13 at 12:09
-
yeah i have a recommendation array.I know its size but i just want to send the count of recommendation array through the url.Using session is a way and get request is another.Which one is better? – log N May 26 '13 at 12:11
-
-
1
I try to reply, but i don't know if someone reply when i typing :)
First get all variables
<?php
$variables = "?f=0";
foreach (getallheaders() as $name => $value) {
$variables .= "&$name=$value";
}
?>
Then you must find all link in the page and append the $variables, you must load the html page
<?php
$dom = new DOMDocument;
$dom->loadHTML($html);
$links = $dom->getElementsByTagName('a');
foreach ($links as $link){
$tmpLink = $link->getAttribute('href') . $variables;
$link->setAttribute('href',$tmpLink);
}
?>

Valerio Cicero
- 347
- 4
- 13
1
You have to modify all links and forms that append a collection of the tracked urls. For that you can catch the last url in php by $_SERVER ['HTTP_REFERER'] and append it to the collection. But this could be very dirty. You should use sessions for tracking instead of an GET collection in urls.