View Full Version : Adding To Url Parameters
Bloodshot
03-26-2009, 05:39 AM
Hi Everyone,
I am back with a new problem I am stuck on.
I am trying to add to a url's paramters but cant get anything working.
if I have url: http://www.test.com/Search?Cat=1
and i would like to add on to the url when someone clicks on the link how would I?
For example I want it to now be: http://www.test.com/Search?Cat=1&User=1
Any help would be helpful.
Thanks.
Sukh
JasonDFR
03-26-2009, 07:44 AM
I'm not super clear about what you are trying to do. If this doesn't answer your question, let me know.
You will first have to somehow get a value for the User variable. Once you have that you can make your link like this:
<?php
$user = 1;
?>
<a href="http://www.test.com/Search?Cat=1&User=<?php echo $user; ?>">Search</a>
codeexploiter
03-26-2009, 07:47 AM
You can do this through JS rather than using PHP as the click is going to happen on the browser. Try the following code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<p><a href="http://www.test.com/Search?Cat=1" id="one">Click to add Parameters</a></p>
<script type="text/javascript">
document.getElementById("one").onclick = function(){
this.href += "&User=1";
alert(this.href); //Just to get a notification you can remove this.
}
</script>
</body>
</html>
Bloodshot
03-26-2009, 03:00 PM
Thanks codeexploiter, i will give that a try.
Well JasonDFR, what I am trying to is take the current url, in the path for example: http://www.test.com/?ID=1&User=1
and when someone clicks on the link, that I need a $_GET for, i would like to add it on the url with ease and not lot of extra statements.
So if someone clicked the link, and I want the page reloaded I just want to add on extra details to the url path so now I want it to look like
example: http://www.test.com/?ID=1&User=1&Search=2
I need to solve this issue because I am working on the searching of my website, but I also have a place where you can change the currency, if someone searches something, then tries to change the currency they don't get and error, the search page will reloaded but the search is lost.
I would like to still keep the research data in the url and add the currency change variables as well to the url path.
Bloodshot
03-26-2009, 03:14 PM
codeexploiter, its helpful what you provided me with, but what if in the situtation is there no ? in the url path it would throw and error.
I need it to check to see if there is a ?ID=Something then just add &Currency=CDN, if there is not ?ID=Something then I need it to add ?Currency=CDN.
Any suggestion to that ?
CrazyChop
03-28-2009, 07:12 AM
use strpos() to find if the current url has a question mark
If there is, the path is likely to be valid.
OTH, there is a http_build_query() (http://sg.php.net/manual/en/function.http-build-query.php) command which you may want to look into.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.