dongmi1941 2013-12-21 22:31
浏览 51
已采纳

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.

  • 写回答

2条回答 默认 最新

  • doujuyang1764 2013-12-21 22:50
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
  • ¥50 invest生境质量模块
  • ¥15 nhanes加权logistic回归,svyglm函数