c_pattle Posted October 15, 2010 Share Posted October 15, 2010 I have a link that sets a get variable that then performs a search based on that get variable. How after I the page has reloaded with the new search results how can I removed the $GET from the end of the url? Thanks for any help. Quote Link to comment https://forums.phpfreaks.com/topic/215953-unset-get/ Share on other sites More sharing options...
Pawn Posted October 15, 2010 Share Posted October 15, 2010 What? Quote Link to comment https://forums.phpfreaks.com/topic/215953-unset-get/#findComment-1122535 Share on other sites More sharing options...
c_pattle Posted October 15, 2010 Author Share Posted October 15, 2010 Sorry. For example say I click on a link such as this <a href="index.php?author=fred">Click</a> Then next time I reload the page how do I remove "author=fred" from the url so that the variable author isn't set? Quote Link to comment https://forums.phpfreaks.com/topic/215953-unset-get/#findComment-1122539 Share on other sites More sharing options...
Pawn Posted October 15, 2010 Share Posted October 15, 2010 By refreshing the page, do you mean by pressing refresh, or following a link on the page to itself? Do you need the value of the $_GET variable to still be accessible? Why do you actually want to do this? Quote Link to comment https://forums.phpfreaks.com/topic/215953-unset-get/#findComment-1122540 Share on other sites More sharing options...
c_pattle Posted October 15, 2010 Author Share Posted October 15, 2010 I want to do this because I have some code at the top of my document that says (this is an example) if(isset($_GET['author'])) { echo ("hello") } This is fine but then if I submit a form on that page "$_GET['author']" will still be set and it will still say hello at the top of the screen. It's hard to explain but I hope this makes sense. Quote Link to comment https://forums.phpfreaks.com/topic/215953-unset-get/#findComment-1122545 Share on other sites More sharing options...
the182guy Posted October 15, 2010 Share Posted October 15, 2010 You could post the data to the page instead of passing it in the $_GET, use $_POST with a form. That way it won't be visable. The other thing you could do is store something in a session variable to say that the hello echo has already happend so don't show it again. Quote Link to comment https://forums.phpfreaks.com/topic/215953-unset-get/#findComment-1122552 Share on other sites More sharing options...
.josh Posted October 16, 2010 Share Posted October 16, 2010 you could mod-rewrite your url in your htaccess file, or if you can't do that, you can do something like session_start(); if ($_GET['x']) { $_SESSION['x'] = $_GET['x']; header("Location: {$_SERVER['PHP_SELF']}"); exit(); } // perform check and query with session var Quote Link to comment https://forums.phpfreaks.com/topic/215953-unset-get/#findComment-1122635 Share on other sites More sharing options...
Pawn Posted October 16, 2010 Share Posted October 16, 2010 I want to do this because I have some code at the top of my document that says (this is an example) if(isset($_GET['author'])) { echo ("hello") } This is fine but then if I submit a form on that page "$_GET['author']" will still be set and it will still say hello at the top of the screen. It's hard to explain but I hope this makes sense. Then your form action is setting the querystring. Use <form action="<?=$_SERVER['REQUEST_URL']?>"> or similar. The querystring won't persist unless it's actually embedded in links. Quote Link to comment https://forums.phpfreaks.com/topic/215953-unset-get/#findComment-1122713 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.