Jump to content

Remove A querystring from url


Wildhalf

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.