XeroXer Posted February 1, 2007 Share Posted February 1, 2007 Hi there! I am making my whole menusystem with ?m=1&p=2&f=folder I am doing this with linking to $_SERVER['REQUEST_URI']. The problem is that if m=1 is in the URL and I click a link with m=2 it is also entered into the URL. So I have both 1 and 2 and the site doesn't work. Or the problem that if m=2 and I press a link that goes to p=3 it has to add the & between them. Can I check if the URL contains a m=, p= or f= and depending on what link is pressed replace the number/text or append it with a & at the end of the URL. Hope that someone understands my problem... Link to comment https://forums.phpfreaks.com/topic/36690-p2-with-_serverrequest_uri/ Share on other sites More sharing options...
ShogunWarrior Posted February 1, 2007 Share Posted February 1, 2007 Why are you using REQUEST_URI and not the query string $_GET? Link to comment https://forums.phpfreaks.com/topic/36690-p2-with-_serverrequest_uri/#findComment-174953 Share on other sites More sharing options...
XeroXer Posted February 2, 2007 Author Share Posted February 2, 2007 Well the problem is that I want to replace the number in the URL if it's already there. And if it's not I want to add a & and then enter the new. If none of them exists I want to add a ? and then the code. If a user goes to http://www.test.com/mysite/ and they click a link to my gallery. The URL then goes to http://www.test.com/mysite/?m=2 that is my gallery. They then select a subcategory in my gallery to my vacation pictures. The URL then goes to http://www.test.com/mysite/?m=2&p=1 that is my gallery with the subcategory vacation. In that gallery they select the folder Ibiza2006 and the URL goes to http://www.test.com/mysite/?m=2&p=1&f=Ibiza2006 If they now select a different gallery say London2003 the URL becomes http://www.test.com/mysite/?m=2&p=1&f=Ibiza2006&f=London2003 And it doesn't work. I can also select main section such as my guestbook and the URL goes to this: http://www.test.com/mysite/?m=2&p=1&f=Ibiza2006&f=London2003?m=3 * note the ? and not & * All this is because I use REQUEST_URI and just add the ?m=1, &p=2 or &f=folder. Can I somehow search the REQUEST_URI for m=, p= and f= ? And if the one I am trying to enter exists it replaces that number and if none of them exists it adds a ? in the start. And if another one exists but not the one I am trying to enter it adds a &. ( I know that this can be hard to understand but I so need your help. ) Link to comment https://forums.phpfreaks.com/topic/36690-p2-with-_serverrequest_uri/#findComment-175249 Share on other sites More sharing options...
ShogunWarrior Posted February 2, 2007 Share Posted February 2, 2007 I understand now, and what you're trying to do is standard enough but you're doing it in a rather roundabout way. Now, what you would do is: $m = (( isset($_GET['m']) )?( trim($_GET['m']) ) '' )); $p = (( isset($_GET['p']) )?( trim($_GET['p']) ) '' )); $f = (( isset($_GET['f']) )?( trim($_GET['f']) ) '' )); And now you can work with, and check the different variables. if( $m != '' ) { $newp = '2'; echo '<a href="?m='.$m.'&p='.$newp.'"> ... </a>'; } I hope you get what I mean which is that you should re-construct the URL from the data you already have, not keep adding parts to the URL. Link to comment https://forums.phpfreaks.com/topic/36690-p2-with-_serverrequest_uri/#findComment-175503 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.