purencool Posted February 23, 2011 Share Posted February 23, 2011 hi phpfreaks I am trying to remove the get variables from my url. the code below works if I echo it out but to try to modify the $_server variable it will not work. Any ideas? $current_url = explode('?',$_SERVER["REQUEST_URI"]); $_SERVER["REQUEST_URI"]= $current_url[0]; echo $current_url[0]."<br>"; Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 23, 2011 Share Posted February 23, 2011 Why are you trying to do this? Ken Quote Link to comment Share on other sites More sharing options...
nobodyk Posted February 23, 2011 Share Posted February 23, 2011 Try this: $current_url = $_SERVER['REQUEST_URI']; $pos = strpos($current_url, '?', 0); $current_url = substr($current_url, 0, $pos+1); The code might need some adjustments. If you know the length of the url, you can actually shorten the code. Quote Link to comment Share on other sites More sharing options...
codefossa Posted February 23, 2011 Share Posted February 23, 2011 preg_replace('/\?.*/', '', $url); Quote Link to comment Share on other sites More sharing options...
nobodyk Posted February 23, 2011 Share Posted February 23, 2011 Sorry I just read your full post lol. Try this with the code I posted above: if (isset($pos)) { header("Location: ".$current_url.""); die(); } Quote Link to comment Share on other sites More sharing options...
purencool Posted February 24, 2011 Author Share Posted February 24, 2011 Sorry for the late rely. To answer kenrbnsn question. The reason for doing this is I have a multiple forms on one page if I update the page with one of the forms then displays the get vars. So what I have been doing is putting the get vars into normal vars and then trying to remove the get vars so that they don't display in the url. Thanks for your replys so far. I hope that this answer your questions. Quote Link to comment Share on other sites More sharing options...
nobodyk Posted February 24, 2011 Share Posted February 24, 2011 if you're doing it for security reasons, then it's useless. _GET and _POST can always be manipulated by the user. If you're trying to hide it from the user it's also useless. I say let the user see the url, it makes no difference. If you're code if properly validated, then you have nothing to worry about. The only thing I must say is always use POST to get a password because using GET will sometimes leave the password in the url history. It would make more sense to ask for help on improving your forms and validation. Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted February 24, 2011 Share Posted February 24, 2011 Sorry for the late rely. To answer kenrbnsn question. The reason for doing this is I have a multiple forms on one page if I update the page with one of the forms then displays the get vars. So what I have been doing is putting the get vars into normal vars and then trying to remove the get vars so that they don't display in the url. Thanks for your replys so far. I hope that this answer your questions. The method you should use depends on what you're trying to do. If you're passing data in to simply retrieve related info (e.g., using an id number to retrieve a product from the db), use get, a.k.a., query string appended to the end of a URL. If you're passing data in to insert/update/edit something, use post. This will keep your site semantically correct. Quote Link to comment Share on other sites More sharing options...
purencool Posted February 24, 2011 Author Share Posted February 24, 2011 wow I just want to keep it clean but why don't just use post vars Quote Link to comment Share on other sites More sharing options...
codefossa Posted February 24, 2011 Share Posted February 24, 2011 wow I just want to keep it clean but why don't just use post vars If you want to keep it clean and not change the URL, I would suggest using Javascript. Set the page that you post to on a whole 'nother page, and use JQuery/AJAX to post to it and return false to the function to keep it from refreshing your page. You can then use JQuery to change the value of a div to "Successfully Updated", or whatever you wish upon success, or if failed have it display that there as well. Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted February 24, 2011 Share Posted February 24, 2011 wow I just want to keep it clean but why don't just use post vars I guess I'm just not entirely clear as to why you need to keep the address clean. I'm getting the feeling that your design may be flawed. Also, if you're scrubbing the address, why wouldn't you want to use post instead? Quote Link to comment Share on other sites More sharing options...
purencool Posted February 24, 2011 Author Share Posted February 24, 2011 After thinking about it I will use ajax that will achieve two things speed an a clean url thanks for all your input. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.