简体   繁体   中英

After redirecting to a php page with request parameters and processing them, how to I return to the same page without the parameters?

I have one PHP page that tests $_REQUEST['delete'] to see if it exists.

If it does, then I delete the item number that it references from a list and redirect to a different tab. The tab switch is done by hiding and exposing different divs.

However, the URL displayed in the browser URL field still has the URL ?delete=nn in it. This can lead to a second delete if I inadvertently submit again without changing the shown URL.

How can I remove the parameters when I shift tabs? Or equivalently, can I switch to the new tab via my URL, eg URL ?tab=2 .

It's a lot of code to show, so I am looking for some suggestions about how to structure. Right now, I create a 'page' with three divs, one for each 'tab' with one being the default.

After handling the delete, the page is reconstructed and the default tab is presented.

The URL isn't modified, of course, since I used it to create the page. Here is the 'pseudo-code':

<?php
    ... head stuff
    ... definition of tabs with onClicks for switching to named tab
    ... create content of div for 1st tab
    ... start creating content of div for 2nd tab
    ... examine $_REQUEST for 'delete'
    ... if it exists then
    ...    alter contents of data to eliminate item nn from list
    ... then
    ... continue content of div for 2nd tab using altered data
    ... then create content of div for 3rd tab
    ... add content for javascript that manages tab switching, login, etc.
    ... echo the entire contents of the page for presentation.
    ... the javascript switches to the default tab on load.

I would like to have the url in the browsers url field NOT have the parameters when the page gets loaded.

I believe I stated the question poorly. I did look at the 'Funk Doc' suggestion, and it does work by putting a new entry on the History stack, but as I examined it, I realized that what I actually wanted was the refresh button of the browser to refresh the screen without using any of the Post or Get variables that might have been present when the screen was drawn originally. I realized this, when I changed to be sure that I was Posting the form variables, and upon hitting refresh, it asked about re-sending the form. The 'pushState' seemed to still retain the Post variables. I tried setting them to different values, but it didn't seem to affect anything.

The issue was that I delete a value in a list by line number, which deletes it from a file. If I use the refresh button, then the line number in the request is again deleted in the altered file. I want the user to have to click on the link to cause the delete, not have a delete happen if they refresh the page.

Suggestions or comments still invited, but I will consider withdrawing the question since it was stated poorly.

Thanks,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM