我想php重定向到我刷新页面时设置的目录

I have two files named index.php and index2.php. My problem is that; I don't want to have POST when I refresh the page in index2.php and I want to redirect to index.php again. How do I do that?

I think if I'm reading your question correctly, you want to send a post request to index.php without leaving your current page, which would be index2.php?

More context would help, but if running JavaScript on your page is possible, you could perform a post request via Ajax, and then redirect the user to index.php by changing the window location.

This is quite contradictory, as posting a form in standard html would achieve the same result.

Are you performing some other logic after the post which you want to happen on index2.php?

More info required please!

use sessions to store the number of tries of your condition on page2.

Do a check when loading page2 if it exists number tries redirect to page1. once you hit page 1 reset the number of tries if you need to

I'll let you write the PHP code yourself, but the logic goes like this

Page 1

// RESETS by: 
// if ($session[retries] > 2) {$session[retries] = 0}

Page 2

// load $session[retries], if not defined, than set default 0

// Increase number of retries
// if (someCondition) { $session[retires] += 1; }

// check the retries and redirect
// if ($isession[retries] > 2 ) { redirectToPage1; }

however the "refresh" behaviour you are describing is a little strange, it's best to use ajax.