Php打开了一大堆窗户

时间:2013-12-21 22:31:07

标签: javascript php

我有一个我从另一个人那里得到的php脚本,由于某种原因登录功能不起作用,除非它在新窗口中打开。 (???不知道为什么,但那就是它是怎么回事)无论如何,当我从我的PHP文件执行打开窗口javascript时,它打开了一大堆窗口。我认为它以某种方式循环,所以我把javascript函数放在一个只应执行一次的for循环中。当我点击我的按钮时,它会持续打开窗户,直到我狂热地关闭它们并停止。

以下是似乎是问题的代码:

    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>";
        }
      }

特别是本节:

  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>";
    }

我尝试查找javascript打开许多窗口,但没有找到任何值得注意的东西。当我查找php打开一大堆窗口时也一样。它实际上没有意义,因为它是在我放入for循环之前循环的。我放入for循环来阻止它,它仍然循环。

2 个答案:

答案 0 :(得分:1)

如果此代码存在或从users.php执行,那么这就是你的问题,因为你会有一个无限循环。

第一行 only 在users.php页面上运行此代码(或者它似乎基于常量名称)。代码继续说:

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

我假设$lsite['users_logform']['register'] == 'Register'。因此,当您访问users.php时,此代码将运行。如果$_REQUEST['susr'] == 'Register'(因为第一页加载打开了一个与users.php?susr=Regsiter匹配的url的新窗口),那么你指示它再次打开另一个页面实例,这里:

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,您需要告诉第二个请求users.php(由您的javascript位生成)它来自javascript。然后忽略整个代码块,如果它来自javascript。这样的事情应该有效:

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>";
  }
}

确定。我更改了第一行以包含对$_GET['from_js']变量的检查。我删除了for循环,因为它们完全没有意义,因为它们只运行一次。对于在新窗口中打开的网址,我添加了&from_js=1。这样,您的代码就不会在随后的新窗口中运行。这将阻止无限弹出窗口。

希望这有帮助。

答案 1 :(得分:0)

更改

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

为:

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