Php打开了一大堆窗户

I have a php script that I got from another guy and for some reason the login function does not work unless it opens up in a new window. (??? no idea why but that's just how it is) Anyways when I execute the open up window javascript from my PHP file, it opens up a whole bunch of windows. I figured that it was somehow looping, so I put the javascript function inside of a for loop that should only execute once. When I click my button, it opens up windows continously until I feverishly close them all and it stops.

Here is the code that seems to be the issue:

    if(basename($_SERVER['PHP_SELF'])==USRFILE && (isset($_REQUEST['usr']) || isset($_REQUEST['susr']) || isset($_GET['mp']) || isset($_REQUEST['rc']))) 
  {
      if(ISAJAX === 0) include(USRTEMPL.'head.php');        // if not Ajax request, include head.php (from USRTEMPL)
      include(USRINCLS.'class.UsersReg.php');        // include the class for Register (used also for Recovery data)

      ob_start();           // start storing output in buffer

      // if 'susr'=Register, create objet of UsersReg (for Register)
      // if 'rc' or 'mp' (for Recover-Confirma), uses UsersRecov class
      // if 'usr', create object of UserPage class (for user page data)
      if(isset($_REQUEST['susr']) && $_REQUEST['susr']==$lsite['users_logform']['register']) {
        $objRe = new UsersReg($mysql);
        echo $objRe->result;
        for($x = 0; $x < 1; $x=2) 
        {
        echo "<script type='text/javascript'>window.open('http://www.thelegendmaker.net/users.php?susr=Register');</script>";
        }
      }
      else if(isset($_REQUEST['rc']) || isset($_GET['mp'])) {
        include(USRINCLS.'class.UsersRecov.php'); //account recovery
        $objRe = new UsersRecov($mysql);
            for($x = 0; $x < 1; $x=2) 
            {
        echo "<script type='text/javascript'>window.open('http://www.thelegendmaker.net/users.php?rc=Recover');</script>";
        }
      }

Specifically this section:

  if(isset($_REQUEST['susr']) && $_REQUEST['susr']==$lsite['users_logform']['register']) {
    $objRe = new UsersReg($mysql);
    echo $objRe->result;
    for($x = 0; $x < 1; $x=2) 
    {
    echo "<script type='text/javascript'>window.open('http://www.thelegendmaker.net/users.php?susr=Register');</script>";
    }

I tried looking up javascript opening up many windows but didn't find anything noteworthy. Same goes when I looked up php opening up a whole bunch of windows. It really makes no sense why it is looking, because it was looping before I put the for loop in. I put in the for loop to stop it, and it still loops.

If this code lives on or gets executed from users.php then that is your problem, because you would have an infinite loop.

The first line only runs this code on the users.php page (or it seems that way based on the constant name). The code goes on to say:

if(isset($_REQUEST['susr']) && $_REQUEST['susr']==$lsite['users_logform']['register']) {

I'm assuming that $lsite['users_logform']['register'] == 'Register'. Thus, when you visit users.php, this code runs. If the $_REQUEST['susr'] == 'Register' (because of the first page load that opened a new window to a url that matches users.php?susr=Regsiter), then you are instructing it to open ANOTHER instance of the page again, here:

if(isset($_REQUEST['susr']) && $_REQUEST['susr']==$lsite['users_logform']['register']) {
  $objRe = new UsersReg($mysql);
  echo $objRe->result;
  for($x = 0; $x < 1; $x=2) 
  {
    echo "<script type='text/javascript'>window.open('http://www.thelegendmaker.net/users.php?susr=Register');</script>";
  }
}

IMO, you need to tell the second request to users.php (generated by your javascript bit) that it is from javascript. Then ignore your entire code block if it is from javascript. Something like this should work:

if ( !isset($_GET['from_js']) && basename($_SERVER['PHP_SELF'])==USRFILE && ( isset($_REQUEST['usr']) || isset($_REQUEST['susr']) || isset($_GET['mp']) || isset($_REQUEST['rc']) ) ) 
{
  if(ISAJAX === 0) include(USRTEMPL.'head.php');        // if not Ajax request, include head.php (from USRTEMPL)
  include(USRINCLS.'class.UsersReg.php');        // include the class for Register (used also for Recovery data)

  ob_start();           // start storing output in buffer

  // if 'susr'=Register, create objet of UsersReg (for Register)
  // if 'rc' or 'mp' (for Recover-Confirma), uses UsersRecov class
  // if 'usr', create object of UserPage class (for user page data)
  if(isset($_REQUEST['susr']) && $_REQUEST['susr']==$lsite['users_logform']['register']) {
    $objRe = new UsersReg($mysql);
    echo $objRe->result;
    // there is no reason for the for loop. totally pointless
    echo "<script type='text/javascript'>window.open('http://www.thelegendmaker.net/users.php?susr=Register&from_js=1');</script>";
  }
  else if(isset($_REQUEST['rc']) || isset($_GET['mp'])) {
    include(USRINCLS.'class.UsersRecov.php'); //account recovery
    $objRe = new UsersRecov($mysql);
    // there is no reason for the for loop. totally pointless
    echo "<script type='text/javascript'>window.open('http://www.thelegendmaker.net/users.php?rc=Recover&from_js=1');</script>";
  }
}

Ok. I changed the first line to include a check for the $_GET['from_js'] variable. I removed the for loops, because they are totally pointless, since they only ever run once. To the urls that are opened in the new window, I added &from_js=1. With this, your code does not run on the subsequent new window openings. This will prevent the infinite popups.

Hopefully this helps.

Change

 echo "<script type='text/javascript'>window.open('http://www.thelegendmaker.net/users.php?susr=Register');</script>";

to:

 header('Location: users.php?susr=Register');