Wildhalf Posted October 22, 2010 Share Posted October 22, 2010 Anyone know how i can remove a querystring from url. Example URL: http://www.mysite.com/?id=1 I am writing a script that needs to read in the ID from the URL. But once have got the information i would like to remove it from the URL and just display http://www.mysite.com but still be able to use the ID to query my database. Any ideas??? Link to comment https://forums.phpfreaks.com/topic/216568-remove-a-querystring-from-url/ Share on other sites More sharing options...
AbraCadaver Posted October 22, 2010 Share Posted October 22, 2010 Anyone know how i can remove a querystring from url. Example URL: http://www.mysite.com/?id=1 I am writing a script that needs to read in the ID from the URL. But once have got the information i would like to remove it from the URL and just display http://www.mysite.com but still be able to use the ID to query my database. Any ideas??? You can rebuild it using the server vars. Have a look at: print_r($_SERVER); Use the appropriate values to rebuild it without the query string. Link to comment https://forums.phpfreaks.com/topic/216568-remove-a-querystring-from-url/#findComment-1125221 Share on other sites More sharing options...
Wildhalf Posted October 22, 2010 Author Share Posted October 22, 2010 Shaun Thanks for you help.... Been reading about it for hours now but still cant figure out how to do it... Link to comment https://forums.phpfreaks.com/topic/216568-remove-a-querystring-from-url/#findComment-1125346 Share on other sites More sharing options...
simshaun Posted October 22, 2010 Share Posted October 22, 2010 If you want to read it then remove it, you need to store the value in a cookie or session var before redirecting. Typically its best to avoid situations like this, because its not good for tabbed browsing. E.g. If I open ?id=1 in one tab, create a new tab and open ?id=2, the first tab would then use id=2 rather than id=1 like it should. So, I think you should ask yourself if its really necessary. (Also, what if users have cookies turned off? You could transfer a session ID through the URL, but that's usually not a good thing to do.) Link to comment https://forums.phpfreaks.com/topic/216568-remove-a-querystring-from-url/#findComment-1125350 Share on other sites More sharing options...
Wildhalf Posted October 22, 2010 Author Share Posted October 22, 2010 I am only going to be using the ID on one page. Say i have 10 different ID's 1 to10. All i am doing is when i send a user to ?ID=1 it displays one thing taken from my database. ?ID=2 displays something else and so on. I suppose i dont now enough about php to do it but i know what i want done works as i have seen it with a few scripts. Link to comment https://forums.phpfreaks.com/topic/216568-remove-a-querystring-from-url/#findComment-1125356 Share on other sites More sharing options...
AbraCadaver Posted October 22, 2010 Share Posted October 22, 2010 Depends on what you mean by "remove it" from the URL. Do you mean in the browser location bar or what? Why do you need to remove it? Normally this is what you do to get the ID: page1.php echo '<a href="page2.php?ID=1">Click for ID 1</a>'; page2.php echo 'The ID is: ' . $_GET['ID']; Link to comment https://forums.phpfreaks.com/topic/216568-remove-a-querystring-from-url/#findComment-1125359 Share on other sites More sharing options...
Wildhalf Posted October 22, 2010 Author Share Posted October 22, 2010 I am trying to remove the ID from the Address bar so rather than having http://www.mysite.com/?id=1 i have http://www.mysite.com displayed in address bar Link to comment https://forums.phpfreaks.com/topic/216568-remove-a-querystring-from-url/#findComment-1125369 Share on other sites More sharing options...
AbraCadaver Posted October 22, 2010 Share Posted October 22, 2010 I am trying to remove the ID from the Address bar so rather than having http://www.mysite.com/?id=1 i have http://www.mysite.com displayed in address bar You can't. Link to comment https://forums.phpfreaks.com/topic/216568-remove-a-querystring-from-url/#findComment-1125382 Share on other sites More sharing options...
Wildhalf Posted October 22, 2010 Author Share Posted October 22, 2010 visit this link and watch it in action...... http://rapidactionprofits.com/?e=test I also have a wordpress plugint designed for thatt script that removes the ?e=whatever. so there is a way to do it.... but how??? Link to comment https://forums.phpfreaks.com/topic/216568-remove-a-querystring-from-url/#findComment-1125389 Share on other sites More sharing options...
BlueSkyIS Posted October 22, 2010 Share Posted October 22, 2010 save the id in a session variable before redirect. based on that session variable, display the proper content. Link to comment https://forums.phpfreaks.com/topic/216568-remove-a-querystring-from-url/#findComment-1125397 Share on other sites More sharing options...
Wildhalf Posted October 22, 2010 Author Share Posted October 22, 2010 Was just about to ask if sessions would work. Was looking on iPhone one last time before I turned out the light and came Accross it... Will try it out thanks Link to comment https://forums.phpfreaks.com/topic/216568-remove-a-querystring-from-url/#findComment-1125398 Share on other sites More sharing options...
simshaun Posted October 22, 2010 Share Posted October 22, 2010 I already told you that in my first post.. If you want to read it then remove it, you need to store the value in a cookie or session var before redirecting. Link to comment https://forums.phpfreaks.com/topic/216568-remove-a-querystring-from-url/#findComment-1125400 Share on other sites More sharing options...
BlueSkyIS Posted October 22, 2010 Share Posted October 22, 2010 ^ yes, you did. Have one file, index.php. Check the GET on each call. if set, set a session variable with the info, then redirect to index.php. If not set, look for the session variable. if set, display proper content, else display default content. Link to comment https://forums.phpfreaks.com/topic/216568-remove-a-querystring-from-url/#findComment-1125402 Share on other sites More sharing options...
Wildhalf Posted October 22, 2010 Author Share Posted October 22, 2010 Shaun sorry I didn't get it from your post thanks for your help. Bluesky thanks also Link to comment https://forums.phpfreaks.com/topic/216568-remove-a-querystring-from-url/#findComment-1125409 Share on other sites More sharing options...
Wildhalf Posted October 25, 2010 Author Share Posted October 25, 2010 Thanks again to everyone.... I got it working. I am using sessions with a javascript redirect. Link to comment https://forums.phpfreaks.com/topic/216568-remove-a-querystring-from-url/#findComment-1126092 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.